Skip to content

Commit cbc79ed

Browse files
authored
Merge pull request singer-io#41 from singer-io/feature/strptime_with_tz-enforces-tz
strptime_with_tz will always return a tz aware datetime object
2 parents ccc1be1 + a296e0b commit cbc79ed

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

singer/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
import json
66
import time
77
import dateutil
8+
import pytz
89

910
from singer.catalog import Catalog
1011

1112
DATETIME_PARSE = "%Y-%m-%dT%H:%M:%SZ"
1213
DATETIME_FMT = "%Y-%m-%dT%H:%M:%S.%fZ"
1314

15+
def now():
16+
return datetime.datetime.utcnow().replace(tzinfo=pytz.UTC)
1417

1518
def strptime_with_tz(dtime):
16-
return dateutil.parser.parse(dtime)
19+
d_object = dateutil.parser.parse(dtime)
20+
if d_object.tzinfo is None:
21+
return d_object.replace(tzinfo=pytz.UTC)
22+
23+
return d_object
1724

1825
def strptime(dtime):
1926
try:

0 commit comments

Comments
 (0)