From 42daea2dd6caf4c15e9d52cfe6a7220e2865e25c Mon Sep 17 00:00:00 2001 From: dejay Date: Sat, 13 Jul 2013 11:57:34 -0600 Subject: [PATCH] Better Day One Timestamps --- jrnl/Journal.py | 12 ++++++++++-- requirements.txt | 3 +++ setup.py | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 193d89a6..6141b5d6 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -10,6 +10,8 @@ except ImportError: import parsedatetime.parsedatetime as pdt import re from datetime import datetime import time +import pytz +from tzlocal import get_localzone try: import simplejson as json except ImportError: import json import sys @@ -308,7 +310,10 @@ class DayOne(Journal): for filename in filenames: with open(filename) as plist_entry: dict_entry = plistlib.readPlist(plist_entry) - entry = self.new_entry(raw=dict_entry['Entry Text'], date=dict_entry['Creation Date'], sort=False) + timezone = pytz.timezone(dict_entry['Time Zone']) + date = dict_entry['Creation Date'] + date = date + timezone.utcoffset(date) + entry = self.new_entry(raw=dict_entry['Entry Text'], date=date, sort=False) entry.starred = dict_entry["Starred"] entry.uuid = dict_entry["UUID"] # We're using new_entry to create the Entry object, which adds the entry @@ -324,12 +329,15 @@ class DayOne(Journal): # that have a uuid will be old ones, and only the one that doesn't will # have a new one! if not hasattr(entry, "uuid"): + timezone = str(get_localzone()) + utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple())) new_uuid = uuid.uuid1().hex filename = os.path.join(self.config['journal'], "entries", new_uuid+".doentry") entry_plist = { - 'Creation Date': entry.date, + 'Creation Date': utc_time, 'Starred': entry.starred if hasattr(entry, 'starred') else False, 'Entry Text': entry.title+"\n"+entry.body, + 'Time Zone': timezone, 'UUID': new_uuid } plistlib.writePlist(entry_plist, filename) diff --git a/requirements.txt b/requirements.txt index a4a16eb3..0871fab2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,7 @@ parsedatetime >= 1.1.2 +pytz >= 2013b colorama >= 0.2.5 pycrypto >= 2.6 argparse==1.2.1 +tzlocal == 1.0 + diff --git a/setup.py b/setup.py index 2b0bbd11..0bb14c25 100644 --- a/setup.py +++ b/setup.py @@ -70,6 +70,8 @@ setup( packages = ['jrnl'], install_requires = [ "parsedatetime>=1.1.2", + "pytz>=2013b", + "tzlocal==1.0", "colorama>=0.2.5" ] + [p for p, cond in conditional_dependencies.items() if cond], extras_require = {