Skip to content

Commit

Permalink
Issue #147 - Activity Time stored in UTC
Browse files Browse the repository at this point in the history
bcgov/ckanext-bcgov#147 #2882 #2970

The Activity model now stores its timestamp in utc

In Formatters, localized_nice_date, removed the datetime replace method
calls with actually ensuring the comparing timestamps have a timezone
specified

fixing typo
  • Loading branch information
jrods committed Sep 12, 2016
1 parent 45b8e4f commit b9b1bd6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions ckan/lib/formatters.py
Expand Up @@ -99,12 +99,10 @@ def months_between(date1, date2):
return months

if not show_date:
now = datetime.datetime.utcnow()
if datetime_.tzinfo is not None:
now = now.replace(tzinfo=datetime_.tzinfo)
else:
now = now.replace(tzinfo=pytz.utc)
datetime_ = datetime_.replace(tzinfo=pytz.utc)
now = datetime.datetime.now(pytz.utc)
if datetime_.tzinfo is None:
datetime_ = datetime_.astimezone(pytz.utc)

date_diff = now - datetime_
days = date_diff.days
if days < 1 and now > datetime_:
Expand Down
2 changes: 1 addition & 1 deletion ckan/model/activity.py
Expand Up @@ -40,7 +40,7 @@ class Activity(domain_object.DomainObject):
def __init__(self, user_id, object_id, revision_id, activity_type,
data=None):
self.id = _types.make_uuid()
self.timestamp = datetime.datetime.now()
self.timestamp = datetime.datetime.utcnow()
self.user_id = user_id
self.object_id = object_id
self.revision_id = revision_id
Expand Down

0 comments on commit b9b1bd6

Please sign in to comment.