Commit db5f0b3
feat(stdlib): add datetime module bindings (#267)
* feat(stdlib): add datetime module bindings
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>
* refactor(stdlib): rework datetime bindings, fix justfile, apply fantomas
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>
---------
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Dag Brattli <dag@brattli.net>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 28194c3 commit db5f0b3
19 files changed
Lines changed: 738 additions & 158 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
| 86 | + | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
| 91 | + | |
| 92 | + | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
356 | | - | |
| 356 | + | |
| 357 | + | |
357 | 358 | | |
358 | 359 | | |
359 | 360 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| 92 | + | |
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
| 79 | + | |
77 | 80 | | |
78 | 81 | | |
79 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
0 commit comments