mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #4510 from tk0miya/4275_update_strftime
Fix #4275: Formats accepted by sphinx.util.i18n.format_date are limite
This commit is contained in:
commit
4b89d5900a
1
CHANGES
1
CHANGES
@ -28,6 +28,7 @@ Bugs fixed
|
||||
* #4490: autodoc: type annotation is broken with python 3.7.0a4+
|
||||
* utils package is installed
|
||||
* #3952: apidoc: module header is too escaped
|
||||
* #4275: Formats accepted by sphinx.util.i18n.format_date are limited
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
@ -157,21 +157,30 @@ date_format_mappings = {
|
||||
'%b': 'MMM', # Month as locale’s abbreviated name.
|
||||
'%B': 'MMMM', # Month as locale’s full name.
|
||||
'%c': 'medium', # Locale’s appropriate date and time representation.
|
||||
'%-d': 'd', # Day of the month as a decimal number.
|
||||
'%d': 'dd', # Day of the month as a zero-padded decimal number.
|
||||
'%H': 'HH', # Hour (24-hour clock) as a decimal number [00,23].
|
||||
'%I': 'hh', # Hour (12-hour clock) as a decimal number [01,12].
|
||||
'%-H': 'H', # Hour (24-hour clock) as a decimal number [0,23].
|
||||
'%H': 'HH', # Hour (24-hour clock) as a zero-padded decimal number [00,23].
|
||||
'%-I': 'h', # Hour (12-hour clock) as a decimal number [1,12].
|
||||
'%I': 'hh', # Hour (12-hour clock) as a zero-padded decimal number [01,12].
|
||||
'%-j': 'D', # Day of the year as a decimal number.
|
||||
'%j': 'DDD', # Day of the year as a zero-padded decimal number.
|
||||
'%-m': 'M', # Month as a decimal number.
|
||||
'%m': 'MM', # Month as a zero-padded decimal number.
|
||||
'%M': 'mm', # Minute as a decimal number [00,59].
|
||||
'%-M': 'm', # Minute as a decimal number [0,59].
|
||||
'%M': 'mm', # Minute as a zero-padded decimal number [00,59].
|
||||
'%p': 'a', # Locale’s equivalent of either AM or PM.
|
||||
'%S': 'ss', # Second as a decimal number.
|
||||
'%-S': 's', # Second as a decimal number.
|
||||
'%S': 'ss', # Second as a zero-padded decimal number.
|
||||
'%U': 'WW', # Week number of the year (Sunday as the first day of the week)
|
||||
# as a zero padded decimal number. All days in a new year preceding
|
||||
# the first Sunday are considered to be in week 0.
|
||||
'%w': 'e', # Weekday as a decimal number, where 0 is Sunday and 6 is Saturday.
|
||||
'%W': 'WW', # Week number of the year (Monday as the first day of the week)
|
||||
'%-W': 'W', # Week number of the year (Monday as the first day of the week)
|
||||
# as a decimal number. All days in a new year preceding the first
|
||||
# Monday are considered to be in week 0.
|
||||
'%W': 'WW', # Week number of the year (Monday as the first day of the week)
|
||||
# as a zero-padded decimal number.
|
||||
'%x': 'medium', # Locale’s appropriate date representation.
|
||||
'%X': 'medium', # Locale’s appropriate time representation.
|
||||
'%y': 'YY', # Year without century as a zero-padded decimal number.
|
||||
@ -180,6 +189,8 @@ date_format_mappings = {
|
||||
'%%': '%',
|
||||
}
|
||||
|
||||
date_format_re = re.compile('(%s)' % '|'.join(date_format_mappings))
|
||||
|
||||
|
||||
def babel_format_date(date, format, locale, formatter=babel.dates.format_date):
|
||||
# type: (datetime, unicode, unicode, Callable) -> unicode
|
||||
@ -214,7 +225,7 @@ def format_date(format, date=None, language=None):
|
||||
date = datetime.now()
|
||||
|
||||
result = []
|
||||
tokens = re.split('(%.)', format)
|
||||
tokens = date_format_re.split(format)
|
||||
for token in tokens:
|
||||
if token in date_format_mappings:
|
||||
babel_format = date_format_mappings.get(token, '')
|
||||
|
@ -176,6 +176,8 @@ def test_format_date():
|
||||
datet = datetime.datetime(2016, 2, 7, 5, 11, 17, 0)
|
||||
assert i18n.format_date(format, date=datet) == 'February 07, 2016, 05:11:17 05 AM'
|
||||
|
||||
format = '%B %-d, %Y, %-H:%-M:%-S %-I %p'
|
||||
assert i18n.format_date(format, date=datet) == 'February 7, 2016, 5:11:17 5 AM'
|
||||
format = '%x'
|
||||
assert i18n.format_date(format, date=datet) == 'Feb 7, 2016'
|
||||
format = '%X'
|
||||
|
Loading…
Reference in New Issue
Block a user