Skip to content

Commit adb3f62

Browse files
authored
Merge pull request #207 from Sage-Bionetworks/xindiguo-synutils-tz-fix
[GEN-2043] Refactor timezone conversion in update_cbio_mapping.py
2 parents 93b23d3 + a0e7b6c commit adb3f62

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

scripts/references/update_cbio_mapping.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import argparse
22
from datetime import datetime
3-
43
import pandas as pd
4+
import pytz
5+
56
import synapseclient
67
from synapseclient import Table
78

8-
99
def now(time_only=False, tz="US/Pacific"):
1010
if time_only:
1111
return datetime.now().strftime("%H:%M:%S")
@@ -48,7 +48,10 @@ def main(save_to_synapse, comment, verbose):
4848
# Mapping
4949
if comment is None:
5050
utc_mod = entity.modifiedOn
51-
pt_mod = utc_mod.replace(tzinfo=synapseclient.utils.from_tz_string("America/Los_Angeles"))
51+
# Remove trailing 'Z' from ISO 8601 UTC timestamp (e.g., '2024-06-10T12:34:56Z')
52+
utc_datetime = datetime.fromisoformat(utc_mod.rstrip('Z')).replace(tzinfo=pytz.utc)
53+
pt_timezone = pytz.timezone('US/Pacific')
54+
pt_mod = utc_datetime.astimezone(pt_timezone)
5255
comment = f"mapping file update from {pt_mod.strftime('%Y-%m-%d')} PT ({file_id}.{entity.versionNumber})"
5356

5457
if verbose:

0 commit comments

Comments
 (0)