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

Proposed by dann frazier on 2012-04-02
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 2012-04-02 Approve on 2012-04-05
Review via email: mp+100469@code.launchpad.net
To post a comment you must log in.
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.

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
1=== modified file 'laika'
2--- laika 2012-03-08 16:04:27 +0000
3+++ laika 2012-04-02 16:40:25 +0000
4@@ -24,11 +24,18 @@
5 UTCNOW = datetime.datetime.utcnow()
6
7 def lpdate2date(lpdate):
8- try:
9- dt = datetime.datetime.strptime(lpdate.split('.')[0], '%Y-%m-%dT%H:%M:%S')
10- return dt
11- except ValueError:
12- return None
13+ # launchpad date type is apparently in-flux
14+ if type(lpdate) is datetime.datetime:
15+ return lpdate.replace(tzinfo=None)
16+ elif type(lpdate) is str:
17+ try:
18+ print lpdate.split('.')[0]
19+ dt = datetime.datetime.strptime(lpdate.split('.')[0], '%Y-%m-%dT%H:%M:%S')
20+ return dt
21+ except ValueError:
22+ return None
23+ else:
24+ raise TypeError
25
26 class LPWrap:
27 '''Simple wrapper Cache-Proxy for LP objects'''

Subscribers

People subscribed via source and target branches