Permalink
Browse files

Add extended date handling

  • Loading branch information...
1 parent 11d0196 commit cdbad27939990785695bec5d49fe3cc9dff04b7f @zachwill committed May 31, 2012
Showing with 20 additions and 14 deletions.
  1. +0 −12 TODO.md
  2. +8 −0 test.py
  3. +12 −2 yc/times.py
View
12 TODO.md
@@ -1,18 +1,6 @@
Usage I see for the CLI going forward.
-
-### dates
-
-```
-hn -d 031612
-hn -d 20120316
-
-hn -d 03-16-12 -t 0 12
-hn -d 03-16-12 -t 12am 12pm
-```
-
-
### filter
```
View
8 test.py
@@ -85,6 +85,10 @@ def test_date_and_hour_options(self):
self.create_cli('-d 03-16-12 -t 0 12')
self.assertSearchParameters(day='2012-03-16', time=['0', '12'])
+ def test_funky_date_and_hour_options(self):
+ self.create_cli('-d 031612 -t 12am 12pm')
+ self.assertSearchParameters(day='2012-03-16', time=['12am', '12pm'])
+
def test_sortby_parameter(self):
self.create_cli('pg -S points')
self.assertSearchParameters(q='pg', sortby='points desc')
@@ -98,6 +102,10 @@ def test_year_month_day(self):
def test_month_day_year(self):
self.assertEquals(date_format('03-16-12'), '2012-03-16')
+ def test_without_dashes(self):
+ self.assertEquals(date_format('031612'), '2012-03-16')
+ self.assertEquals(date_format('20120316'), '2012-03-16')
+
class HourFormat(TestCase):
View
14 yc/times.py
@@ -11,8 +11,18 @@ def date_format(date):
"""Convert the given input to a date."""
if isinstance(date, str):
if '-' not in date:
- # It has no separating dashes.
- print "No dashes"
+ if len(date) == 8:
+ # It's a YYYYMMDD date.
+ year = date[:4]
+ month = date[4:6]
+ day = date[6:]
+ date = "%s-%s-%s" % (year, month, day)
+ else:
+ # Then it's MMDDYY.
+ year = date[4:]
+ month = date[:2]
+ day = date[2:4]
+ date = '20%s-%s-%s' % (year, month, day)
elif len(date) == 8:
# Then it's in MM-DD-YY format.
month, day, year = date.split('-')

0 comments on commit cdbad27

Please sign in to comment.