Skip to content

Commit

Permalink
Give format a default parameter
Browse files Browse the repository at this point in the history
Everything else in arrow has the most sane defaults ever, but getting
a human readable string from format requires a format. Just default to
something.
  • Loading branch information
emonty committed Aug 5, 2014
1 parent 9e0ecf9 commit e91a9c5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ And then:
>>> local.timestamp
1368303838

>>> local.format()
'2013-05-11 13:23:58 -07:00'

>>> local.format('YYYY-MM-DD HH:mm:ss ZZ')
'2013-05-11 13:23:58 -07:00'

Expand Down
6 changes: 5 additions & 1 deletion arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def ceil(self, frame):

# string output and formatting.

def format(self, fmt, locale='en_us'):
def format(self, fmt='YYYY-MM-DD HH:mm:ss ZZ', locale='en_us'):
''' Returns a string representation of the :class:`Arrow <arrow.arrow.Arrow>` object,
formatted according to a format string.
Expand All @@ -549,6 +549,10 @@ def format(self, fmt, locale='en_us'):
>>> arrow.utcnow().format('MMMM DD, YYYY')
'May 09, 2013'
>>> arrow.utcnow().format()
'2013-05-09 03:56:47 -00:00'
'''

return formatter.DateTimeFormatter(locale).format(self._datetime, fmt)
Expand Down
3 changes: 3 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ Quickstart
>>> local.timestamp
1368303838
>>> local.format()
'2013-05-11 13:23:58 -07:00'
>>> local.format('YYYY-MM-DD HH:mm:ss ZZ')
'2013-05-11 13:23:58 -07:00'
Expand Down
6 changes: 6 additions & 0 deletions tests/arrow_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ def test_format(self):

assertEqual(result, '2013-02-03')

def test_bare_format(self):

result = self.arrow.format()

assertEqual(result, '2013-02-03 12:30:45 -00:00')

def test_format_no_format_string(self):

result = '{0}'.format(self.arrow)
Expand Down

0 comments on commit e91a9c5

Please sign in to comment.