feat(stdlib): add datetime module bindings#267
Merged
Conversation
Adds F# bindings for the Python datetime module, covering: - timedelta (duration with days/seconds/microseconds, total_seconds()) - date (year/month/day, isoformat, strftime, weekday, fromisoformat, replace) - time (hour/minute/second/microsecond, isoformat, strftime, fromisoformat) - datetime (full date+time, now, utcnow, fromisoformat, strptime, combine, timestamp, astimezone) - timezone (fixed-offset tzinfo, utc singleton) Each class has a separate static factory type (timedeltaStatic, dateStatic, timeStatic, datetimeStatic, timezoneStatic) for constructors and class methods. Int arguments use int($1) Emit wrappers to handle Fable's Int32 boxing. Adds 30 tests covering all bound classes and their main operations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Datetime:
- Switch from paired static-factory types to Queue.fs-style primary-ctor
classes. The original factory pattern combined [<Emit("$0($1...)")>] with
[<NamedParams>], which silently dropped all kwargs (generated timedelta()
instead of timedelta(days=3.0)).
- timedelta: empty primary ctor plus static ofDays/ofHours/ofMinutes/
ofSeconds/ofWeeks/ofMilliseconds/ofMicroseconds factories with float()
emit wrappers so Fable's Float64 doesn't reach Python's datetime. Added
add/sub/neg arithmetic.
- timezone: moved above datetime so datetime.astimezone/now(tz)/
fromtimestamp(tz) can take timezone instead of obj.
- date/time/datetime: collapsed replaceDate/replaceTime into a single
[<NamedParams>] replace that supports partial replacement (any subset of
fields). Added time.replace.
- datetime: arithmetic via sub(datetime)->timedelta, sub(timedelta)->
datetime, add(timedelta)->datetime. utcnow marked [<Obsolete>] pointing
at now(tz = timezone.utc).
- Module-level doc note about the `time` identifier collision with
Fable.Python.Time.
- Tests expanded from 30 to 37 covering partial replace, arithmetic,
datetime.now(tz), and the ofX factories.
justfile:
- Drop -r from `dotnet fantomas` invocations in `format` and `format-check`;
fantomas has no -r flag and it caused both recipes to fail.
Other files: fantomas reformatting applied by `just format` to pre-existing
files touched by the formatter.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.
Summary
Adds F# bindings for Python's
datetimemodule — one of the most-used modules in the stdlib and previously absent from Fable.Python.Changes
New file:
src/stdlib/Datetime.fsCovers the five main classes:
timedeltadays,seconds,microseconds,total_seconds()+ keyword-argument factorydateyear/month/day,isoformat(),strftime(),fromisoformat(),today(),fromtimestamp(),weekday(),replace()timehour/minute/second/microsecond,isoformat(),strftime(),fromisoformat()datetimenow(),utcnow(),fromisoformat(),strptime(),combine(),timestamp(),isoformat(),astimezone(),replaceDate(),replaceTime()timezoneutcsingletonNew file:
test/TestDatetime.fs— 30 tests covering all bound classes.Design Decisions
datetimeStatic) alongside the instance type (datetime). This mirrors the pattern inFunctools.fsandItertools.fsand keeps class methods separate from instance methods.Emittemplates wrap integer args withint(...)to handle Fable'sInt32boxing correctly.timedelta.Createandtime.Createuse[<NamedParams>]+[<Emit("$0($1...)")>]so callers can writetimedelta.Create(days = 2.0, hours = 3.0)idiomatically.datetime.isoformathas two overloads: no-arg (defaultTseparator) and asep: stringoverload via[<Emit>].replaceDateandreplaceTimeuse named-keyword Emits to avoid the complex optional-parameter combinatorial explosion of Python'sdatetime.replace(...).Trade-offs
tzinfo(abstract base class) is not bound since it is rarely used directly by consumers;timezonecovers the common use-case.datetime.replace()is split intoreplaceDateandreplaceTimehelpers rather than a single method with many optional args; this avoids a complex overload matrix while covering the most common use-cases.astimezoneacceptsobjfor thetzparameter to avoid a circular dependency withtimezone.CI will validate the build and all 30 new tests.
Note
🔒 Integrity filter blocked 10 items
The following items were blocked because they don't meet the GitHub integrity level.
list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".To allow these resources, lower
min-integrityin your GitHub frontmatter: