Work if timezone is UTC

This commit is contained in:
MinchinWeb 2018-04-08 22:03:42 -06:00
parent bee2bac2b4
commit ea19458e7c
2 changed files with 7 additions and 3 deletions

View file

@ -43,4 +43,4 @@ Feature: Multiple journals
Scenario: Gracefully handle a config without a default journal Scenario: Gracefully handle a config without a default journal
Given we use the config "multiple_without_default.yaml" Given we use the config "multiple_without_default.yaml"
When we run "jrnl fork this repo and fix something" When we run "jrnl fork this repo and fix something"
Then we should see the message "You have not specified a journal. Either provide a default journal in your config file, or specify one of your journals on the command line." Then the output should contain "You have not specified a journal. Either provide a default journal in your config file, or specify one of your journals on the command line."

View file

@ -7,7 +7,7 @@ from . import Journal
from . import time as jrnl_time from . import time as jrnl_time
import os import os
import re import re
from datetime import datetime from datetime import datetime, timedelta
import time import time
import fnmatch import fnmatch
import plistlib import plistlib
@ -49,7 +49,11 @@ class DayOne(Journal.Journal):
except (KeyError, pytz.exceptions.UnknownTimeZoneError): except (KeyError, pytz.exceptions.UnknownTimeZoneError):
timezone = tzlocal.get_localzone() timezone = tzlocal.get_localzone()
date = dict_entry['Creation Date'] date = dict_entry['Creation Date']
date = date + timezone.utcoffset(date, is_dst=False) if timezone != pytz.timezone('UTC'):
time_offset = timezone.utcoffset(date)
else:
time_offset = timedelta(0)
date = date + time_offset
entry = Entry.Entry(self, date, text=dict_entry['Entry Text'], starred=dict_entry["Starred"]) entry = Entry.Entry(self, date, text=dict_entry['Entry Text'], starred=dict_entry["Starred"])
entry.uuid = dict_entry["UUID"] entry.uuid = dict_entry["UUID"]
entry._tags = [self.config['tagsymbols'][0] + tag.lower() for tag in dict_entry.get("Tags", [])] entry._tags = [self.config['tagsymbols'][0] + tag.lower() for tag in dict_entry.get("Tags", [])]