mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-11 00:58:31 +02:00
Better Day One Timestamps
This commit is contained in:
parent
20fb701a1a
commit
ed20660815
3 changed files with 15 additions and 2 deletions
|
@ -10,6 +10,8 @@ except ImportError: import parsedatetime.parsedatetime as pdt
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import time
|
import time
|
||||||
|
import pytz
|
||||||
|
from tzlocal import get_localzone
|
||||||
try: import simplejson as json
|
try: import simplejson as json
|
||||||
except ImportError: import json
|
except ImportError: import json
|
||||||
import sys
|
import sys
|
||||||
|
@ -308,7 +310,10 @@ class DayOne(Journal):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
with open(filename) as plist_entry:
|
with open(filename) as plist_entry:
|
||||||
dict_entry = plistlib.readPlist(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.starred = dict_entry["Starred"]
|
||||||
entry.uuid = dict_entry["UUID"]
|
entry.uuid = dict_entry["UUID"]
|
||||||
# We're using new_entry to create the Entry object, which adds the entry
|
# 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
|
# that have a uuid will be old ones, and only the one that doesn't will
|
||||||
# have a new one!
|
# have a new one!
|
||||||
if not hasattr(entry, "uuid"):
|
if not hasattr(entry, "uuid"):
|
||||||
|
timezone = str(get_localzone())
|
||||||
|
utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple()))
|
||||||
new_uuid = uuid.uuid1().hex
|
new_uuid = uuid.uuid1().hex
|
||||||
filename = os.path.join(self.config['journal'], "entries", new_uuid+".doentry")
|
filename = os.path.join(self.config['journal'], "entries", new_uuid+".doentry")
|
||||||
entry_plist = {
|
entry_plist = {
|
||||||
'Creation Date': entry.date,
|
'Creation Date': utc_time,
|
||||||
'Starred': entry.starred if hasattr(entry, 'starred') else False,
|
'Starred': entry.starred if hasattr(entry, 'starred') else False,
|
||||||
'Entry Text': entry.title+"\n"+entry.body,
|
'Entry Text': entry.title+"\n"+entry.body,
|
||||||
|
'Time Zone': timezone,
|
||||||
'UUID': new_uuid
|
'UUID': new_uuid
|
||||||
}
|
}
|
||||||
plistlib.writePlist(entry_plist, filename)
|
plistlib.writePlist(entry_plist, filename)
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
parsedatetime >= 1.1.2
|
parsedatetime >= 1.1.2
|
||||||
|
pytz >= 2013b
|
||||||
colorama >= 0.2.5
|
colorama >= 0.2.5
|
||||||
pycrypto >= 2.6
|
pycrypto >= 2.6
|
||||||
argparse==1.2.1
|
argparse==1.2.1
|
||||||
|
tzlocal == 1.0
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -70,6 +70,8 @@ setup(
|
||||||
packages = ['jrnl'],
|
packages = ['jrnl'],
|
||||||
install_requires = [
|
install_requires = [
|
||||||
"parsedatetime>=1.1.2",
|
"parsedatetime>=1.1.2",
|
||||||
|
"pytz>=2013b",
|
||||||
|
"tzlocal==1.0",
|
||||||
"colorama>=0.2.5"
|
"colorama>=0.2.5"
|
||||||
] + [p for p, cond in conditional_dependencies.items() if cond],
|
] + [p for p, cond in conditional_dependencies.items() if cond],
|
||||||
extras_require = {
|
extras_require = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue