Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Commit

Permalink
util: If no date or datetime, assume 1970. Update tests to reflect this.
Browse files Browse the repository at this point in the history
  • Loading branch information
edunham committed Sep 11, 2013
1 parent 1f5e178 commit 0ad363a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions wok/tests/test_util.py
Expand Up @@ -80,11 +80,12 @@ def test_just_date(self):
self.assertEquals(inp, out)

def test_just_time(self):
inp = {'time': self.time}
t = self.time # otherwise the datetime line gets awful
inp = {'time': t}
out = {
'datetime': datetime(1970, 1, 1),
'datetime': datetime(1970, 1, 1, t.hour, t.minute, t.second),
'date': date(1970, 1, 1),
'time': self.time,
'time': t,
}

util.date_and_times(inp)
Expand Down
8 changes: 5 additions & 3 deletions wok/util.py
Expand Up @@ -57,14 +57,16 @@ def date_and_times(meta):

time_part = time(hours, minutes, seconds)

if date_part is None:
date_part = date(1970, 1, 1)

meta['date'] = date_part

meta['time'] = time_part

if date_part is not None and time_part is not None:
meta['datetime'] = datetime(date_part.year, date_part.month,
date_part.day, time_part.hour, time_part.minute,
time_part.second, time_part.microsecond, time_part.tzinfo)
elif date_part is not None:
meta['datetime'] = datetime(date_part.year, date_part.month, date_part.day)
else:
meta['datetime'] = None
meta['datetime'] = datetime(date_part.year, date_part.month, date_part.day)

2 comments on commit 0ad363a

@abbgrade
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It think it's a bad idea to save wrong values instead None in the meta dict.

@ngokevin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably prefer None as well. 1970 is a weird fallback.

Please sign in to comment.