Skip to content

Commit

Permalink
Fix error in days to microseconds calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrattli committed Nov 30, 2023
1 parent 2734920 commit ee7ade0
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions src/fable-library-py/fable_library/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def subtract(x: datetime, y: datetime | TimeSpan) -> datetime | TimeSpan:
delta = x - y
# ts.microseconds only contains the microseconds provided to the constructor
# so we need to calculate the total microseconds ourselves
delta_microseconds = delta.days * (24 * 3600) + delta.seconds * 10**6 + delta.microseconds
delta_microseconds = delta.days * (24 * 3600 * 10**6) + delta.seconds * 10**6 + delta.microseconds
return create_time_span(0, 0, 0, 0, 0, delta_microseconds)

return x - timedelta(microseconds=total_microseconds(y))
Expand Down Expand Up @@ -237,17 +237,6 @@ def try_parse(string: str, style: int, unsigned: bool, bitsize: int, defValue: F
return False


def add(d: datetime, ts: int) -> datetime:
new_date = d + timedelta(milliseconds=ts)
if d.tzinfo:
old_tz_offset = d.utcoffset()
new_tz_offset = new_date.utcoffset()
if old_tz_offset is not None and new_tz_offset is not None and old_tz_offset != new_tz_offset:
return new_date + (new_tz_offset - old_tz_offset)

return new_date


def add_milliseconds(d: datetime, v: int) -> datetime:
return d + timedelta(milliseconds=v)

Expand Down

0 comments on commit ee7ade0

Please sign in to comment.