Skip to content

Commit

Permalink
v2.2.5 Ensure 4-digit years
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed Aug 23, 2020
1 parent 3c2d3ed commit 154f0f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion datapackage_pipelines/VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
2.2.4
2.2.5

21 changes: 14 additions & 7 deletions datapackage_pipelines/utilities/extended_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@

from .lazy_dict import LazyDict


DATE_FORMAT = '%Y-%m-%d'
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
if datetime.date(1, 1, 1).strftime('%04Y') == '4Y':
DATE_F_FORMAT = '%Y-%m-%d'
DATETIME_F_FORMAT = '%Y-%m-%d %H:%M:%S'
else:
DATE_F_FORMAT = '%04Y-%m-%d'
DATETIME_F_FORMAT = '%04Y-%m-%d %H:%M:%S'
DATE_FORMAT = DATE_F_FORMAT
DATETIME_FORMAT = DATETIME_F_FORMAT
DATE_P_FORMAT = '%Y-%m-%d'
DATETIME_P_FORMAT = '%Y-%m-%d %H:%M:%S'
TIME_FORMAT = '%H:%M:%S'


Expand Down Expand Up @@ -57,13 +64,13 @@ def object_hook(cls, obj):
if 'type{datetime}' in obj:
try:
return datetime.datetime \
.strptime(obj["type{datetime}"], DATETIME_FORMAT)
.strptime(obj["type{datetime}"], DATETIME_P_FORMAT)
except ValueError:
pass
if 'type{date}' in obj:
try:
return datetime.datetime \
.strptime(obj["type{date}"], DATE_FORMAT) \
.strptime(obj["type{date}"], DATE_P_FORMAT) \
.date()
except ValueError:
pass
Expand Down Expand Up @@ -98,9 +105,9 @@ def default(self, obj):
elif isinstance(obj, datetime.time):
return {'type{time}': obj.strftime(TIME_FORMAT)}
elif isinstance(obj, datetime.datetime):
return {'type{datetime}': obj.strftime(DATETIME_FORMAT)}
return {'type{datetime}': obj.strftime(DATETIME_F_FORMAT)}
elif isinstance(obj, datetime.date):
return {'type{date}': obj.strftime(DATE_FORMAT)}
return {'type{date}': obj.strftime(DATE_F_FORMAT)}
elif isinstance(obj, (isodate.Duration, datetime.timedelta)):
return {'type{duration}': isodate.duration_isoformat(obj)}
elif isinstance(obj, set):
Expand Down

0 comments on commit 154f0f1

Please sign in to comment.