Skip to content

Commit

Permalink
tz calculations
Browse files Browse the repository at this point in the history
don't start the sub_time window earlier than start time!
  • Loading branch information
Rohit Chatterjee committed Dec 4, 2023
1 parent 39170a0 commit e35a651
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ def mk_query(self):
else:
start_sub_time = datetime.fromisoformat(self.state[self.cursor_field])
start_sub_time -= timedelta(days=self.max_days_to_close)
from datetime import timezone

tzaware_start_time = datetime.fromisoformat(self.start_time)
if tzaware_start_time.tzinfo is None:
# interpret as utc
tzaware_start_time = tzaware_start_time.replace(tzinfo=timezone.utc)
else:
# convert to utc if necessary
tzaware_start_time = tzaware_start_time.astimezone(timezone.utc)
start_sub_time = max(start_sub_time, tzaware_start_time)
return {"_submission_time": {"$gte": start_sub_time.isoformat()}, self.cursor_field: {"$gte": self.state[self.cursor_field]}}

def request_params(
Expand Down Expand Up @@ -157,6 +167,12 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
retval = {"_id": record["_id"], "data": record}
retval["_submission_time"] = record["_submission_time"]
retval["endtime"] = record.get("endtime")
if retval["endtime"]:
from datetime import timezone

# endtime is in utc
endtime = datetime.fromisoformat(retval["endtime"]).astimezone(timezone.utc)
retval["endtime"] = endtime.isoformat()
yield retval

def read_records(self, *args, **kwargs) -> Iterable[Mapping[str, Any]]:
Expand Down

0 comments on commit e35a651

Please sign in to comment.