The default format of today_fmt and html_last_updated_fmt is back to strftime format again

`html_last_updated_fmt` is commonly used for non date formatting. But
LDML is difficult to represent them from its characteristics.

Now we moved to strftime format again (ref: #2394).
This commit is contained in:
Takeshi KOMIYA 2016-04-02 10:23:13 +09:00
parent 5e0b542e62
commit d35ccb9b4c
10 changed files with 49 additions and 27 deletions

View File

@ -1,6 +1,13 @@
Release 1.4.1 (in development) Release 1.4.1 (in development)
============================== ==============================
Incompatible changes
--------------------
* The default format of `today_fmt` and `html_last_updated_fmt` is back to
strftime format again. Locale Date Markup Language is also supported for
backward compatibility until Sphinx-1.5.
Translations Translations
------------ ------------

View File

@ -330,13 +330,12 @@ Project information
replacement for ``|today|``. replacement for ``|today|``.
* If you set :confval:`today` to a non-empty value, it is used. * If you set :confval:`today` to a non-empty value, it is used.
* Otherwise, the current time is formatted using `Locale Data Markup Language * Otherwise, the current time is formatted using :func:`time.strftime` and
<http://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns>`_ the format given in :confval:`today_fmt`.
and the format given in :confval:`today_fmt`.
The default is no :confval:`today` and a :confval:`today_fmt` of ``'MMMM dd, The default is no :confval:`today` and a :confval:`today_fmt` of ``'%B %d,
YYYY'`` (or, if translation is enabled with :confval:`language`, an %Y'`` (or, if translation is enabled with :confval:`language`, an equivalent
equivalent %format for the selected locale). format for the selected locale).
.. versionchanged:: 1.4 .. versionchanged:: 1.4
@ -344,6 +343,12 @@ Project information
Language. strftime format is also supported for backward compatibility Language. strftime format is also supported for backward compatibility
until Sphinx-1.5. until Sphinx-1.5.
.. versionchanged:: 1.4.1
Format specification was changed again from Locale Data Markup Language
to strftime. LDML format is also supported for backward compatibility
until Sphinx-1.5.
.. confval:: highlight_language .. confval:: highlight_language
The default language to highlight source code in. The default is The default language to highlight source code in. The default is
@ -696,9 +701,8 @@ that use Sphinx's HTMLWriter class.
.. confval:: html_last_updated_fmt .. confval:: html_last_updated_fmt
If this is not None, a 'Last updated on:' timestamp is inserted If this is not None, a 'Last updated on:' timestamp is inserted
at every page bottom, using the given `Locale Data Markup Language at every page bottom, using the given :func:`strftime` format.
<http://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns>`_ The empty string is equivalent to ``'%b %d, %Y'`` (or a
format. The empty string is equivalent to ``'MMM dd, YYYY'`` (or a
locale-dependent equivalent). locale-dependent equivalent).
.. versionchanged:: 1.4 .. versionchanged:: 1.4
@ -707,6 +711,13 @@ that use Sphinx's HTMLWriter class.
Language. strftime format is also supported for backward compatibility Language. strftime format is also supported for backward compatibility
until Sphinx-1.5. until Sphinx-1.5.
.. versionchanged:: 1.4.1
Format specification was changed again from Locale Data Markup Language
to strftime. LDML format is also supported for backward compatibility
until Sphinx-1.5.
.. confval:: html_use_smartypants .. confval:: html_use_smartypants
If true, `SmartyPants <http://daringfireball.net/projects/smartypants/>`_ If true, `SmartyPants <http://daringfireball.net/projects/smartypants/>`_

View File

@ -530,7 +530,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
metadata['copyright'] = self.esc(self.config.epub_copyright) metadata['copyright'] = self.esc(self.config.epub_copyright)
metadata['scheme'] = self.esc(self.config.epub_scheme) metadata['scheme'] = self.esc(self.config.epub_scheme)
metadata['id'] = self.esc(self.config.epub_identifier) metadata['id'] = self.esc(self.config.epub_identifier)
metadata['date'] = self.esc(format_date('YYYY-MM-dd', language=self.config.language, metadata['date'] = self.esc(format_date('%Y-%m-%d', language=self.config.language,
warn=self.warn)) warn=self.warn))
metadata['files'] = files metadata['files'] = files
metadata['spine'] = spine metadata['spine'] = spine

View File

@ -292,7 +292,7 @@ class StandaloneHTMLBuilder(Builder):
# typically doesn't include the time of day # typically doesn't include the time of day
lufmt = self.config.html_last_updated_fmt lufmt = self.config.html_last_updated_fmt
if lufmt is not None: if lufmt is not None:
self.last_updated = format_date(lufmt or _('MMM dd, YYYY'), self.last_updated = format_date(lufmt or _('%b %d, %Y'),
language=self.config.language, language=self.config.language,
warn=self.warn) warn=self.warn)
else: else:

View File

@ -54,7 +54,7 @@ class DefaultSubstitutions(Transform):
text = config[refname] text = config[refname]
if refname == 'today' and not text: if refname == 'today' and not text:
# special handling: can also specify a strftime format # special handling: can also specify a strftime format
text = format_date(config.today_fmt or _('MMMM dd, YYYY'), text = format_date(config.today_fmt or _('%b %d, %Y'),
language=config.language, warn=env.warn) language=config.language, warn=env.warn)
ref.replace_self(nodes.Text(text, text)) ref.replace_self(nodes.Text(text, text))

View File

@ -179,13 +179,13 @@ def format_date(format, date=None, language=None, warn=None):
else: else:
date = datetime.now() date = datetime.now()
if '%' not in format: if re.match('EEE|MMM|dd|DDD|MM|WW|medium|YY', format):
# consider the format as babel's # consider the format as babel's
return babel_format_date(date, format, locale=language, warn=warn) warnings.warn('LDML format support will be dropped at Sphinx-1.5',
else:
warnings.warn('ustrftime format support will be dropped at Sphinx-1.5',
DeprecationWarning) DeprecationWarning)
return babel_format_date(date, format, locale=language, warn=warn)
else:
# consider the format as ustrftime's and try to convert it to babel's # consider the format as ustrftime's and try to convert it to babel's
result = [] result = []
tokens = re.split('(%.)', format) tokens = re.split('(%.)', format)

View File

@ -371,8 +371,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
if builder.config.today: if builder.config.today:
self.elements['date'] = builder.config.today self.elements['date'] = builder.config.today
else: else:
self.elements['date'] = format_date(builder.config.today_fmt or self.elements['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'),
_('MMMM dd, YYYY'),
language=builder.config.language) language=builder.config.language)
if builder.config.latex_logo: if builder.config.latex_logo:
self.elements['logo'] = '\\includegraphics{%s}\\par' % \ self.elements['logo'] = '\\includegraphics{%s}\\par' % \

View File

@ -97,8 +97,7 @@ class ManualPageTranslator(BaseTranslator):
if builder.config.today: if builder.config.today:
self._docinfo['date'] = builder.config.today self._docinfo['date'] = builder.config.today
else: else:
self._docinfo['date'] = format_date(builder.config.today_fmt or self._docinfo['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'),
_('MMMM dd, YYYY'),
language=builder.config.language) language=builder.config.language)
self._docinfo['copyright'] = builder.config.copyright self._docinfo['copyright'] = builder.config.copyright
self._docinfo['version'] = builder.config.version self._docinfo['version'] = builder.config.version

View File

@ -218,8 +218,7 @@ class TexinfoTranslator(nodes.NodeVisitor):
'project': self.escape(self.builder.config.project), 'project': self.escape(self.builder.config.project),
'copyright': self.escape(self.builder.config.copyright), 'copyright': self.escape(self.builder.config.copyright),
'date': self.escape(self.builder.config.today or 'date': self.escape(self.builder.config.today or
format_date(self.builder.config.today_fmt or format_date(self.builder.config.today_fmt or _('%b %d, %Y'),
_('MMMM dd, YYYY'),
language=self.builder.config.language)) language=self.builder.config.language))
}) })
# title # title

View File

@ -169,6 +169,7 @@ def test_get_catalogs_with_compact(dir):
def test_format_date(): def test_format_date():
date = datetime.date(2016, 2, 7) date = datetime.date(2016, 2, 7)
# default format
format = None format = None
assert i18n.format_date(format, date=date) == 'Feb 7, 2016' assert i18n.format_date(format, date=date) == 'Feb 7, 2016'
assert i18n.format_date(format, date=date, language='') == 'Feb 7, 2016' assert i18n.format_date(format, date=date, language='') == 'Feb 7, 2016'
@ -177,6 +178,7 @@ def test_format_date():
assert i18n.format_date(format, date=date, language='ja') == '2016/02/07' assert i18n.format_date(format, date=date, language='ja') == '2016/02/07'
assert i18n.format_date(format, date=date, language='de') == '07.02.2016' assert i18n.format_date(format, date=date, language='de') == '07.02.2016'
# strftime format
format = '%B %d, %Y' format = '%B %d, %Y'
assert i18n.format_date(format, date=date) == 'February 07, 2016' assert i18n.format_date(format, date=date) == 'February 07, 2016'
assert i18n.format_date(format, date=date, language='') == 'February 07, 2016' assert i18n.format_date(format, date=date, language='') == 'February 07, 2016'
@ -185,14 +187,19 @@ def test_format_date():
assert i18n.format_date(format, date=date, language='ja') == u'2月 07, 2016' assert i18n.format_date(format, date=date, language='ja') == u'2月 07, 2016'
assert i18n.format_date(format, date=date, language='de') == 'Februar 07, 2016' assert i18n.format_date(format, date=date, language='de') == 'Februar 07, 2016'
# invalid date format # LDML format
format = 'MMM dd, YYYY'
assert i18n.format_date(format, date=date) == 'Feb 07, 2016'
assert i18n.format_date(format, date=date, language='') == 'Feb 07, 2016'
assert i18n.format_date(format, date=date, language='unknown') == 'Feb 07, 2016'
assert i18n.format_date(format, date=date, language='en') == 'Feb 07, 2016'
assert i18n.format_date(format, date=date, language='ja') == u'2月 07, 2016'
assert i18n.format_date(format, date=date, language='de') == 'Feb. 07, 2016'
# raw string
format = 'Mon Mar 28 12:37:08 2016, commit 4367aef' format = 'Mon Mar 28 12:37:08 2016, commit 4367aef'
assert i18n.format_date(format, date=date) == format assert i18n.format_date(format, date=date) == format
# quoted format
quoted_format = "'Mon Mar 28 12:37:08 2016, commit 4367aef'"
assert i18n.format_date(quoted_format, date=date) == format
def test_get_filename_for_language(): def test_get_filename_for_language():
app = TestApp() app = TestApp()