Skip to content

[Repo Assist] feat: add calendar module bindings and tests#82

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/bindings-calendar-2026-04-db790420b92595ef
Draft

[Repo Assist] feat: add calendar module bindings and tests#82
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/bindings-calendar-2026-04-db790420b92595ef

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated contribution from Repo Assist, an AI assistant.

What

Adds Fable.Beam.Calendar — F# bindings for Erlang's calendar module (stdlib), covering date/time introspection and Gregorian calendar arithmetic.

Changes

src/otp/Calendar.fs (new)

Type aliases (for readability):

  • type Date = int * int * int — (Year, Month, Day)
  • type Time = int * int * int — (Hour, Min, Sec)
  • type DateTime = Date * Time — ((Year,Month,Day),(Hour,Min,Sec))

[<ImportAll>] bindings (multi-arg variants where available):

Function Description
calendar.date() Current local date
calendar.time() Current local time
calendar.local_time() Current local datetime
calendar.universal_time() Current UTC datetime
calendar.day_of_the_week(year, month, day) Day number (1=Mon, 7=Sun)
calendar.is_leap_year(year) Leap year check
calendar.last_day_of_the_month(year, month) Last day of month
calendar.date_to_gregorian_days(year, month, day) Date → Gregorian day count
calendar.gregorian_days_to_date(days) Gregorian day count → Date
calendar.gregorian_seconds_to_datetime(seconds) Gregorian seconds → DateTime

[<Emit>] bindings (functions that take single tuple args on the Erlang side):

Function Description
datetimeToGregorianSeconds(datetime) DateTime → Gregorian second count (int64)
timeToSeconds(time) Time → seconds since midnight
secondsToTime(seconds) Seconds since midnight → Time
localTimeToUniversalTime(datetime) Local → UTC
universalTimeToLocalTime(datetime) UTC → Local

test/TestCalendar.fs (new) — 24 tests

  • is_leap_year: 2000 ✓, 2024 ✓, 1900 ✗ (century rule), 2023 ✗
  • last_day_of_the_month: Jan=31, Feb leap=29, Feb non-leap=28, Apr=30
  • day_of_the_week: Mon/Fri/Sun for known 2024 dates
  • date_to_gregorian_days / gregorian_days_to_date: roundtrip + known value (2000-01-01 = day 730485)
  • timeToSeconds / secondsToTime: midnight, noon, 01:30:30 roundtrips
  • datetimeToGregorianSeconds / gregorian_seconds_to_datetime: roundtrip + known value (2000-01-01 00:00:00 = 63113904000)
  • date, time, local_time, universal_time: sanity-range checks on live values

Other

  • src/Fable.Beam.fsproj: added Calendar.fs after Re.fs
  • test/Fable.Beam.Test.fsproj: added TestCalendar.fs after TestRe.fs
  • README.md: added Fable.Beam.Calendar and Fable.Beam.Re to module table

Notes

  • datetimeToGregorianSeconds returns int64 because Gregorian seconds for modern dates exceed 231 (e.g. 2000-01-01 = 63,113,904,000).
  • localTimeToUniversalTime / universalTimeToLocalTime results are timezone-dependent; no test asserts specific UTC offset.
  • F# compilation verified locally with dotnet build test/. Full BEAM validation by CI.

Generated by Repo Assist · ● 2.9M ·

Adds Fable.Beam.Calendar with bindings for the Erlang calendar
module (date, time, datetime, Gregorian conversions):

- ImportAll bindings: date, time, local_time, universal_time,
  day_of_the_week, is_leap_year, last_day_of_the_month,
  date_to_gregorian_days, gregorian_days_to_date,
  gregorian_seconds_to_datetime
- Emit bindings: datetimeToGregorianSeconds, timeToSeconds,
  secondsToTime, localTimeToUniversalTime, universalTimeToLocalTime
- Type aliases: Date, Time, DateTime for clarity
- 24 tests covering deterministic functions (leap year, day-of-week,
  Gregorian day/second roundtrips, time/seconds conversions) plus
  sanity checks on live-clock functions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants