Skip to content

Commit e5683e5

Browse files
committed
Add timezones to all dates
1 parent 2144554 commit e5683e5

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

packages/flare/bin/cron_job_ingest_events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def main(
3535
# To avoid cron jobs from doing the same work at the same time, exit new cron jobs if a cron job is already doing work
3636
last_fetched_timestamp = data_store.get_last_fetch()
3737
if last_fetched_timestamp and last_fetched_timestamp > (
38-
datetime.now() - CRON_JOB_THRESHOLD_SINCE_LAST_FETCH
38+
datetime.now(timezone.utc) - CRON_JOB_THRESHOLD_SINCE_LAST_FETCH
3939
):
4040
logger.info(
4141
f"Fetched events less than {int(CRON_JOB_THRESHOLD_SINCE_LAST_FETCH.seconds / 60)} minutes ago, exiting"
@@ -50,7 +50,7 @@ def main(
5050
severities_filter = get_severities_filter(storage_passwords=storage_passwords)
5151
source_types_filter = get_source_types_filter(storage_passwords=storage_passwords)
5252

53-
data_store.set_last_fetch(datetime.now())
53+
data_store.set_last_fetch(datetime.now(timezone.utc))
5454

5555
# If the tenant has changed, update the start date so that future requests will be based off today
5656
# If you switch tenants, this will avoid the old tenant from ingesting all the events before today and the day
@@ -71,7 +71,7 @@ def main(
7171
flare_api_cls=flare_api_cls,
7272
data_store=data_store,
7373
):
74-
data_store.set_last_fetch(datetime.now())
74+
data_store.set_last_fetch(datetime.now(timezone.utc))
7575

7676
data_store.set_next_by_tenant(tenant_id, next_token)
7777

packages/flare/tests/bin/test_data_store.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from data_store import ConfigDataStore
22
from datetime import datetime
3+
from datetime import timezone
34

45

56
def test_get_and_set_last_tenant_id(data_store: ConfigDataStore) -> None:
@@ -8,13 +9,13 @@ def test_get_and_set_last_tenant_id(data_store: ConfigDataStore) -> None:
89

910

1011
def test_get_and_set_start_date(data_store: ConfigDataStore) -> None:
11-
date = datetime(2024, 3, 6, 12, 0, 0)
12+
date = datetime(2024, 3, 6, 12, 0, 0, tzinfo=timezone.utc)
1213
data_store.set_start_date(date)
1314
assert data_store.get_start_date() == date
1415

1516

1617
def test_get_and_set_last_fetch(data_store: ConfigDataStore) -> None:
17-
date = datetime(2024, 3, 6, 14, 0, 0)
18+
date = datetime(2024, 3, 6, 14, 0, 0, tzinfo=timezone.utc)
1819
data_store.set_last_fetch(date)
1920
assert data_store.get_last_fetch() == date
2021

packages/flare/tests/bin/test_ingest_events.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ def test_main_expect_early_return(
102102
storage_passwords: FakeStoragePasswords,
103103
data_store: ConfigDataStore,
104104
) -> None:
105-
data_store.set_last_fetch(datetime.datetime.fromisoformat("2000-01-01T12:00:00"))
105+
data_store.set_last_fetch(
106+
datetime.datetime.fromisoformat("2000-01-01T12:00:00+00:00")
107+
)
106108

107109
main(
108110
logger=logger,

0 commit comments

Comments
 (0)