Skip to content

Commit

Permalink
Merge pull request #5 from reichlab/fix_date_handling
Browse files Browse the repository at this point in the history
fix date handling
  • Loading branch information
elray1 authored Oct 10, 2024
2 parents 5947abe + b12d0b9 commit 98f8c22
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions get_covid_clade_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import click
from pathlib import Path
import logging
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

from cladetime import CladeTime # type: ignore
from cladetime.util.sequence import filter_covid_genome_metadata, get_clade_counts # type: ignore
Expand Down Expand Up @@ -52,11 +52,21 @@
)
def main(as_of: str | None = None):
"""Get clade counts and save to S3 bucket."""
utc_now = datetime.now(tz=timezone.utc)
utc_now_date = utc_now.date()
if as_of is None or as_of == str(utc_now_date):
# as_of not provided or is today
as_of_datetime = utc_now
as_of = str(utc_now_date)
elif as_of > str(utc_now_date):
raise ValueError('as_of is in the future!')
else:
# as_of is not today
as_of_datetime = datetime.strptime(as_of, "%Y-%m-%d") \
+ timedelta(hours = 23, minutes = 59, seconds = 59)

# Instantiate CladeTime object
# Pending CladeTime update, we tell CladeTime to use the specified as_of date + 1 day
# This ensures that any updates made on the specified as_of date are captured
ct = CladeTime(sequence_as_of=datetime.strptime(as_of, "%Y-%m-%d") + timedelta(1))
ct = CladeTime(sequence_as_of=as_of_datetime)
logger.info({
"msg": f"CladeTime object created with sequence as_of date = {ct.sequence_as_of}",
"nextstrain_metadata_url": ct.url_sequence_metadata,
Expand Down

0 comments on commit 98f8c22

Please sign in to comment.