You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB
Python

"""Unit tests for time_utils module."""
import datetime as dt
from zoneinfo import ZoneInfo
import pytest
_UTC = ZoneInfo("UTC")
_ET = ZoneInfo("America/New_York")
def test_utc_now():
from libs.common.time_utils import utc_now
now = utc_now()
assert now.tzinfo is not None
def test_to_eastern():
from libs.common.time_utils import to_eastern
d = dt.datetime(2026, 1, 29, 21, 5, tzinfo=_UTC)
e = to_eastern(d)
assert e.tzinfo is not None
assert e.hour == 16 # 21:05 UTC = 16:05 ET (EST, UTC-5)
def test_to_utc():
from libs.common.time_utils import to_utc
d = dt.datetime(2026, 1, 29, 16, 5, tzinfo=_ET)
u = to_utc(d)
assert u.tzinfo is not None
def test_naive_datetime_rejected():
from libs.common.time_utils import to_eastern
with pytest.raises(ValueError):
to_eastern(dt.datetime(2026, 1, 1))
def test_filing_time_bucket_post_market():
from libs.common.time_utils import filing_time_bucket
d = dt.datetime(2026, 1, 29, 21, 5, tzinfo=_UTC)
assert filing_time_bucket(d) == "post_market"
def test_filing_time_bucket_pre_market():
from libs.common.time_utils import filing_time_bucket
d = dt.datetime(2026, 1, 29, 12, 0, tzinfo=_UTC) # 7:00 AM ET
assert filing_time_bucket(d) == "pre_market"
def test_filing_time_bucket_regular():
from libs.common.time_utils import filing_time_bucket
d = dt.datetime(2026, 1, 29, 15, 0, tzinfo=_UTC) # 10:00 AM ET
assert filing_time_bucket(d) == "regular_hours"
def test_filing_time_bucket_naive():
from libs.common.time_utils import filing_time_bucket
d = dt.datetime(2026, 1, 29, 21, 5)
assert filing_time_bucket(d) == "unknown"