Permalink
Browse files

Refactor the way dates are handled

  • Loading branch information...
1 parent cb65183 commit eee13896fb04c8b17878c498082eef553602088b @zachwill committed May 31, 2012
Showing with 14 additions and 32 deletions.
  1. +1 −1 test.py
  2. +0 −1 yc/__init__.py
  3. +2 −2 yc/cli.py
  4. +2 −2 yc/core.py
  5. +9 −26 yc/times.py
View
@@ -52,7 +52,7 @@ class Search(TestCase):
def setUp(self):
cli.News = Mock()
cli.present = Mock()
- times.Date = Mock()
+ times.date_format = Mock()
def create_cli(self, args):
parser = cli.create_parser()
View
@@ -1,5 +1,4 @@
from .core import News
-from .times import Date
def get(**params):
View
@@ -15,7 +15,7 @@
has_pygments = False
from .core import News
-from .times import Date
+from .times import date_format
def create_parser():
@@ -54,7 +54,7 @@ def search(options):
if options.start:
params['start'] = options.start
if options.day:
- params['day'] = Date(options.day)
+ params['day'] = date_format(options.day)
if options.time:
params['time'] = options.time
if options.sort:
View
@@ -6,7 +6,7 @@
import simplejson as json
from . import thriftdb
-from .times import Date
+from .times import date_format
class News(object):
@@ -23,7 +23,7 @@ def get(self, **params):
def date(self, day, **params):
"""Query a specific date."""
- params['day'] = str(Date(day))
+ params['day'] = date_format(day)
return self.get(**params)
def facet(self, term, **params):
View
@@ -7,39 +7,22 @@
from collections import Iterable
-class Date(object):
-
- def __init__(self, date):
- self._d = date
- self._date = self._convert_date(date)
-
- def _convert_date(self, date):
- """Convert the given input to a date."""
- if isinstance(date, str):
- date = self._convert_string(date)
- elif isinstance(date, Iterable):
- date = '-'.join(str(n) for n in date)
- else:
- # it's a datetime
- print date
- return date
-
- def _convert_string(self, date):
- """Convert a string to the right format."""
+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"
elif len(date) == 8:
# Then it's in MM-DD-YY format.
month, day, year = date.split('-')
date = '20%s-%s-%s' % (year, month, day)
- return date
-
- def __str__(self):
- return self._date
-
- def __repr__(self):
- return self.__str__()
+ elif isinstance(date, Iterable):
+ date = '-'.join(str(n) for n in date)
+ else:
+ # it's a datetime
+ print date
+ return date
def hour_format(hour):

0 comments on commit eee1389

Please sign in to comment.