From 2a981d51e29e6f495a83d39d2b7d5d58d0ea12e5 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Sat, 17 Aug 2013 13:19:54 -0700 Subject: [PATCH] Tests for parsing DayOne entries without Timezone --- .../4BB1F46946AD439996C9B59DE7C4DDC1.doentry | 4 ++-- features/dayone.feature | 10 +++++++--- features/steps/core.py | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/features/data/journals/dayone.dayone/entries/4BB1F46946AD439996C9B59DE7C4DDC1.doentry b/features/data/journals/dayone.dayone/entries/4BB1F46946AD439996C9B59DE7C4DDC1.doentry index 977026d7..9ebaf538 100644 --- a/features/data/journals/dayone.dayone/entries/4BB1F46946AD439996C9B59DE7C4DDC1.doentry +++ b/features/data/journals/dayone.dayone/entries/4BB1F46946AD439996C9B59DE7C4DDC1.doentry @@ -3,7 +3,7 @@ Creation Date - 2013-08-17T18:37:50Z + 2013-01-17T18:37:50Z Creator Device Agent @@ -18,7 +18,7 @@ Day One (Mac)/1.8 Entry Text - This is a DayOne entry. + This is a DayOne entry without Timezone. Starred Tags diff --git a/features/dayone.feature b/features/dayone.feature index 27f795f5..c8e987e1 100644 --- a/features/dayone.feature +++ b/features/dayone.feature @@ -2,7 +2,7 @@ Feature: DayOne Ingetration Scenario: Loading a DayOne Journal Given we use the config "dayone.json" - When we run "jrnl -until now" + When we run "jrnl -from 'feb 2013'" Then we should get no error and the output should be """ @@ -11,10 +11,14 @@ Feature: DayOne Ingetration 2013-06-17 20:38 This entry has a location. 2013-07-17 11:38 This entry is starred! - - 2013-08-17 11:37 This is a DayOne entry. """ + Scenario: Entries without timezone information will be intepreted in the current timezone + Given we use the config "dayone.json" + When we run "jrnl -until 'feb 2013'" + Then we should get no error + and the output should contain "2013-01-17T18:37Z" in the local time + Scenario: Writing into Dayone Given we use the config "dayone.json" When we run "jrnl 01 may 1979: Being born hurts." diff --git a/features/steps/core.py b/features/steps/core.py index 1b476a2a..66e6a07f 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -1,8 +1,10 @@ from behave import * -from jrnl import jrnl, Journal +from jrnl import jrnl, Journal, util +from dateutil import parser as date_parser import os import sys import json +import pytz try: from io import StringIO except ImportError: @@ -73,7 +75,7 @@ def check_output_json(context): def check_output_field(context, field, number=1): out = context.stdout_capture.getvalue() out_json = json.loads(out) - assert field in out_json [field, out_json] + assert field in out_json, [field, out_json] assert len(out_json[field]) == number, len(out_json[field]) @then('"{field}" in the json output should not contain "{key}"') @@ -97,6 +99,15 @@ def check_output(context): for line_text, line_out in zip(text, out): assert line_text.strip() == line_out.strip(), [line_text.strip(), line_out.strip()] +@then('the output should contain "{text}" in the local time') +def check_output_time_inline(context, text): + out = context.stdout_capture.getvalue() + local_tz = pytz.timezone(util.get_local_timezone()) + utc_time = date_parser.parse(text) + date = utc_time + local_tz._utcoffset + local_date = date.strftime("%Y-%m-%d %H:%M") + assert local_date in out, local_date + @then('the output should contain "{text}"') def check_output_inline(context, text): out = context.stdout_capture.getvalue()