Skip to content

[Repo Assist] feat(stdlib): add datetime module bindings#267

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/bindings-datetime-2026-04-21-9acec82cb3409615
Draft

[Repo Assist] feat(stdlib): add datetime module bindings#267
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/bindings-datetime-2026-04-21-9acec82cb3409615

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.

Summary

Adds F# bindings for Python's datetime module — one of the most-used modules in the stdlib and previously absent from Fable.Python.

Changes

New file: src/stdlib/Datetime.fs

Covers the five main classes:

Class Key features bound
timedelta days, seconds, microseconds, total_seconds() + keyword-argument factory
date year/month/day, isoformat(), strftime(), fromisoformat(), today(), fromtimestamp(), weekday(), replace()
time hour/minute/second/microsecond, isoformat(), strftime(), fromisoformat()
datetime Full date+time properties, now(), utcnow(), fromisoformat(), strptime(), combine(), timestamp(), isoformat(), astimezone(), replaceDate(), replaceTime()
timezone Fixed-offset factory, utc singleton

New file: test/TestDatetime.fs — 30 tests covering all bound classes.

Design Decisions

  • Each class has a separate static factory type (e.g. datetimeStatic) alongside the instance type (datetime). This mirrors the pattern in Functools.fs and Itertools.fs and keeps class methods separate from instance methods.
  • Constructor Emit templates wrap integer args with int(...) to handle Fable's Int32 boxing correctly.
  • timedelta.Create and time.Create use [<NamedParams>] + [<Emit("$0($1...)")>] so callers can write timedelta.Create(days = 2.0, hours = 3.0) idiomatically.
  • datetime.isoformat has two overloads: no-arg (default T separator) and a sep: string overload via [<Emit>].
  • replaceDate and replaceTime use named-keyword Emits to avoid the complex optional-parameter combinatorial explosion of Python's datetime.replace(...).
  • No breaking changes — this is a purely additive module.

Trade-offs

  • tzinfo (abstract base class) is not bound since it is rarely used directly by consumers; timezone covers the common use-case.
  • datetime.replace() is split into replaceDate and replaceTime helpers rather than a single method with many optional args; this avoids a complex overload matrix while covering the most common use-cases.
  • astimezone accepts obj for the tz parameter to avoid a circular dependency with timezone.

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.

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by Repo Assist · ● 2.3M ·

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>
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