Skip to content

Commit

Permalink
Added support for the 'now' value for dates and datetimes.
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanOC committed Mar 25, 2011
1 parent f4f219e commit ef6fe82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
22 changes: 14 additions & 8 deletions sharpy/client.py
Expand Up @@ -45,19 +45,25 @@ def build_url(self, path, params=None):
return url

def format_datetime(self, to_format):
if getattr(to_format, 'tzinfo', None) is not None:
utc_value = to_format.astimezone(tzutc())
if to_format == 'now':
str_dt = to_format
else:
utc_value = to_format
str_dt = utc_value.strftime('%Y-%m-%dT%H:%M:%S+00:00')
if getattr(to_format, 'tzinfo', None) is not None:
utc_value = to_format.astimezone(tzutc())
else:
utc_value = to_format
str_dt = utc_value.strftime('%Y-%m-%dT%H:%M:%S+00:00')
return str_dt

def format_date(self, to_format):
if getattr(to_format, 'tzinfo', None) is not None:
utc_value = to_format.astimezone(tzutc())
if to_format == 'now':
str_dt = to_format
else:
utc_value = to_format
str_dt = utc_value.strftime('%Y-%m-%d')
if getattr(to_format, 'tzinfo', None) is not None:
utc_value = to_format.astimezone(tzutc())
else:
utc_value = to_format
str_dt = utc_value.strftime('%Y-%m-%d')
return str_dt

def make_request(self, path, params=None, data=None, method=None):
Expand Down
13 changes: 6 additions & 7 deletions tests/client_tests.py
Expand Up @@ -209,17 +209,16 @@ def test_format_datetime_with_date(self):

self.assertEquals(expected, result)

def test_format_date_with_datetime(self):
def test_format_date_with_now(self):
client = self.get_client()
result = client.format_date(datetime(year=2010,month=9,day=19,hour=20,minute=10,second=39))
expected = '2010-09-19'
result = client.format_date('now')
expected = 'now'

self.assertEquals(expected, result)

def test_format_date_with_date(self):
def test_format_datetime_with_now(self):
client = self.get_client()
result = client.format_date(date(year=2010,month=9,day=19))
expected = '2010-09-19'
result = client.format_datetime('now')
expected = 'now'

self.assertEquals(expected, result)

0 comments on commit ef6fe82

Please sign in to comment.