Repository navigation
Closed
Description
[Python] Implement missing DateTimeOffset members
Summary
The Python target's DateTimeOffset implementation in fable_library/date_offset.py is incomplete. Many members from System.DateTimeOffset either throw at runtime (referenced in Replacements.fs but not implemented in the library) or are silently missing.
Currently working
- Constructor:
DateTimeOffset(year, month, day, hour, minute, second, millisecond, offset)viacreate - Properties:
Year,Month,Day,Hour,Minute,Second,Offset,DateTime,Now,UtcNow - Static fields:
MinValue - Methods:
ToString,TryParse,FromUnixTimeMilliseconds,FromUnixTimeSeconds,ToUnixTimeMilliseconds,ToUnixTimeSeconds - Operator:
op_subtraction(DateTimeOffset - DateTimeOffset → TimeSpan, DateTimeOffset - TimeSpan → DateTimeOffset) - Equality/comparison: delegated to
date.equals/date.compare
Missing / broken
Constructors
-
DateTimeOffset(DateTime)—fromDatereferenced inReplacements.fsbut missing indate_offset.py -
DateTimeOffset(Int64 ticks, TimeSpan offset)—fromTicksreferenced but missing -
DateTimeOffset(DateOnly, TimeOnly, TimeSpan)— not handled
Fields
-
MaxValue—date_offset.maxValuereferenced inReplacements.fsbut missing indate_offset.py -
UnixEpoch
Properties
-
UtcDateTime—to_universal_timereferenced but missing -
LocalDateTime—to_local_timereferenced but missing -
UtcTicks—getUtcTicksreferenced but missing -
Date(date-only component asDateTime) -
DayOfWeek -
DayOfYear -
Millisecond -
Microsecond -
Nanosecond -
Ticks(clock time ticks) -
TimeOfDay(asTimeSpan) -
TotalOffsetMinutes
Methods
-
Add(TimeSpan)— would go via catch-all todate_offset.add, which is missing -
AddDays(float)— catch-all, not implemented -
AddHours(float)— catch-all, not implemented -
AddMicroseconds(float)— catch-all, not implemented -
AddMilliseconds(float)— referenced asaddMilliseconds(used forAddTicks), missing -
AddMinutes(float)— catch-all, not implemented -
AddMonths(int)— catch-all, not implemented -
AddSeconds(float)— catch-all, not implemented -
AddYears(int)— catch-all, not implemented -
AddTicks(int64)— dispatches toaddMilliseconds, which is missing -
Compare(DateTimeOffset, DateTimeOffset)— static method, not handled -
EqualsExact(DateTimeOffset)— not handled -
FromFileTime(int64)— not handled -
ToFileTime()— not handled -
ToLocalTime()—to_local_timereferenced but missing -
ToOffset(TimeSpan)— not handled -
ToUniversalTime()—to_universal_timereferenced but missing -
ParseExact— not handled -
TryParseExact— not handled
Operators
-
op_addition(DateTimeOffset + TimeSpan) — commented out in Rust extension, missing indate_offset.py
Other
-
GetHashCode/ hash support —Replacements.fsroutes todate.dateHash, which does not exist indate.py;DateTimeOffsetvalues cannot be used as map/set keys reliably
Implementation notes
- The catch-all branch in
Replacements.fs(line ~3022) forwards unknown instance methods todate_offset.<lowerFirst(methodName)>, so manyAdd*methods will silently try to call missing functions at runtime. to_local_timeandto_universal_timeshould returnDateTimeOffset(notDateTime), consistent with the .NET API.AddTicksis currently mapped toaddMilliseconds(ticks / 10000)— this function needs to be added, and the mapping should be verified for precision.- Equality semantics: .NET compares
DateTimeOffsetby UTC-normalized instant (not by local time + offset pair). The current delegation todate.equalsneeds to apply the offset before comparing. - The Rust extension (
src/fable-library-py/src/datetime_offset.rs) has stubs for most functions commented out — these should be completed when the Python implementation is stabilized.
Files to change
src/fable-library-py/fable_library/date_offset.py— main implementationsrc/Fable.Transforms/Python/Replacements.fs— wire up new functionstests/Python/TestDateTimeOffset.fs— add test coverage for each implemented member
Metadata
Metadata
Assignees
Labels
No labels
Activity
ncave commentedon Apr 2, 2026
/repo-assist
[Python] Implement missing DateTimeOffset members (#4475)
dbrattli commentedon Apr 2, 2026
Added a PR #4477. The 3 remaining are: