Merge lp:~dannf/laika/support-multiple-date-types into lp:laika

Proposed by dann frazier
Status: Merged
Merged at revision: 20
Proposed branch: lp:~dannf/laika/support-multiple-date-types
Merge into: lp:laika
Diff against target: 27 lines (+12/-5)
1 file modified
laika (+12/-5)
To merge this branch: bzr merge lp:~dannf/laika/support-multiple-date-types
Reviewer Review Type Date Requested Status
Alex Chiang Approve
Review via email: mp+100469@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Peter Petrakis (peter-petrakis) wrote :

Why not just cast lpdate to str and take split from there? The lang is
duck typing after all and there isn't any other actions taken here. Now
you've got two code paths that do the same thing when:

dt = datetime.datetime.strptime(str(lpdate).split('.')[0], '%Y-%m-%dT%H:%M:%S')

will do.

Revision history for this message
Alex Chiang (achiang) wrote :

Thanks dannf.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'laika'
--- laika 2012-03-08 16:04:27 +0000
+++ laika 2012-04-02 16:40:25 +0000
@@ -24,11 +24,18 @@
24UTCNOW = datetime.datetime.utcnow()24UTCNOW = datetime.datetime.utcnow()
2525
26def lpdate2date(lpdate):26def lpdate2date(lpdate):
27 try:27 # launchpad date type is apparently in-flux
28 dt = datetime.datetime.strptime(lpdate.split('.')[0], '%Y-%m-%dT%H:%M:%S')28 if type(lpdate) is datetime.datetime:
29 return dt29 return lpdate.replace(tzinfo=None)
30 except ValueError:30 elif type(lpdate) is str:
31 return None31 try:
32 print lpdate.split('.')[0]
33 dt = datetime.datetime.strptime(lpdate.split('.')[0], '%Y-%m-%dT%H:%M:%S')
34 return dt
35 except ValueError:
36 return None
37 else:
38 raise TypeError
32 39
33class LPWrap:40class LPWrap:
34 '''Simple wrapper Cache-Proxy for LP objects'''41 '''Simple wrapper Cache-Proxy for LP objects'''

Subscribers

People subscribed via source and target branches