Skip to content

Commit

Permalink
try fix neg windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Apr 21, 2024
1 parent cda9e12 commit cf3d8f8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/nd2/_util.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

import math
import os
import re
from contextlib import suppress
from datetime import datetime, timezone
from datetime import datetime, timedelta, timezone
from itertools import product
from typing import TYPE_CHECKING, BinaryIO, NamedTuple, cast

Expand Down Expand Up @@ -82,7 +83,12 @@ def is_new_format(path: str) -> bool:

def jdn_to_datetime(jdn: float, tz: timezone = timezone.utc) -> datetime:
# astimezone() without arguments will use the system's local timezone
dt = datetime.fromtimestamp((jdn - 2440587.5) * 86400.0, tz)
t = (jdn - 2440587.5) * 86400.0
if os.name == "nt" and t < 0:
# Windows does not always support negative timestamps
dt = datetime.fromtimestamp(0, tz) + timedelta(seconds=t)

Check warning on line 89 in src/nd2/_util.py

View check run for this annotation

Codecov / codecov/patch

src/nd2/_util.py#L89

Added line #L89 was not covered by tests
else:
dt = datetime.fromtimestamp(t, tz)
with suppress(ValueError, OSError):
return dt.astimezone()
return dt

Check warning on line 94 in src/nd2/_util.py

View check run for this annotation

Codecov / codecov/patch

src/nd2/_util.py#L94

Added line #L94 was not covered by tests
Expand Down

0 comments on commit cf3d8f8

Please sign in to comment.