summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2016-04-02 10:23:13 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2016-04-03 10:25:32 +0900
commitd35ccb9b4c3b15dbfd81e8349f0a1464f2e423d8 (patch)
tree85a645b4541a7841d35a6420c91adc14600243a0
parent5e0b542e627dda7ee2786e6a725baf2fc33b3157 (diff)
downloadsphinx-git-d35ccb9b4c3b15dbfd81e8349f0a1464f2e423d8.tar.gz
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).
-rw-r--r--CHANGES7
-rw-r--r--doc/config.rst29
-rw-r--r--sphinx/builders/epub.py2
-rw-r--r--sphinx/builders/html.py2
-rw-r--r--sphinx/transforms.py2
-rw-r--r--sphinx/util/i18n.py8
-rw-r--r--sphinx/writers/latex.py3
-rw-r--r--sphinx/writers/manpage.py3
-rw-r--r--sphinx/writers/texinfo.py3
-rw-r--r--tests/test_util_i18n.py17
10 files changed, 49 insertions, 27 deletions
diff --git a/CHANGES b/CHANGES
index 472ca6e81..d78473a84 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,13 @@
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
------------
diff --git a/doc/config.rst b/doc/config.rst
index c87db8dd3..9fc086955 100644
--- a/doc/config.rst
+++ b/doc/config.rst
@@ -330,13 +330,12 @@ Project information
replacement for ``|today|``.
* If you set :confval:`today` to a non-empty value, it is used.
- * Otherwise, the current time is formatted using `Locale Data Markup Language
- <http://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns>`_
- and the format given in :confval:`today_fmt`.
+ * Otherwise, the current time is formatted using :func:`time.strftime` and
+ the format given in :confval:`today_fmt`.
- The default is no :confval:`today` and a :confval:`today_fmt` of ``'MMMM dd,
- YYYY'`` (or, if translation is enabled with :confval:`language`, an
- equivalent %format for the selected locale).
+ The default is no :confval:`today` and a :confval:`today_fmt` of ``'%B %d,
+ %Y'`` (or, if translation is enabled with :confval:`language`, an equivalent
+ format for the selected locale).
.. versionchanged:: 1.4
@@ -344,6 +343,12 @@ Project information
Language. strftime format is also supported for backward compatibility
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
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
If this is not None, a 'Last updated on:' timestamp is inserted
- at every page bottom, using the given `Locale Data Markup Language
- <http://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns>`_
- format. The empty string is equivalent to ``'MMM dd, YYYY'`` (or a
+ at every page bottom, using the given :func:`strftime` format.
+ The empty string is equivalent to ``'%b %d, %Y'`` (or a
locale-dependent equivalent).
.. versionchanged:: 1.4
@@ -707,6 +711,13 @@ that use Sphinx's HTMLWriter class.
Language. strftime format is also supported for backward compatibility
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
If true, `SmartyPants <http://daringfireball.net/projects/smartypants/>`_
diff --git a/sphinx/builders/epub.py b/sphinx/builders/epub.py
index 265421d2c..cc839d757 100644
--- a/sphinx/builders/epub.py
+++ b/sphinx/builders/epub.py
@@ -530,7 +530,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
metadata['copyright'] = self.esc(self.config.epub_copyright)
metadata['scheme'] = self.esc(self.config.epub_scheme)
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))
metadata['files'] = files
metadata['spine'] = spine
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
index 1b3db1402..f541daa1a 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -292,7 +292,7 @@ class StandaloneHTMLBuilder(Builder):
# typically doesn't include the time of day
lufmt = self.config.html_last_updated_fmt
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,
warn=self.warn)
else:
diff --git a/sphinx/transforms.py b/sphinx/transforms.py
index 7272d3b19..2e3fb7f0b 100644
--- a/sphinx/transforms.py
+++ b/sphinx/transforms.py
@@ -54,7 +54,7 @@ class DefaultSubstitutions(Transform):
text = config[refname]
if refname == 'today' and not text:
# 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)
ref.replace_self(nodes.Text(text, text))
diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py
index 5d98b115c..16fa7a21c 100644
--- a/sphinx/util/i18n.py
+++ b/sphinx/util/i18n.py
@@ -179,13 +179,13 @@ def format_date(format, date=None, language=None, warn=None):
else:
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
- return babel_format_date(date, format, locale=language, warn=warn)
- else:
- warnings.warn('ustrftime format support will be dropped at Sphinx-1.5',
+ warnings.warn('LDML format support will be dropped at Sphinx-1.5',
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
result = []
tokens = re.split('(%.)', format)
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index 2e9cc784e..6019d04ed 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -371,8 +371,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
if builder.config.today:
self.elements['date'] = builder.config.today
else:
- self.elements['date'] = format_date(builder.config.today_fmt or
- _('MMMM dd, YYYY'),
+ self.elements['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'),
language=builder.config.language)
if builder.config.latex_logo:
self.elements['logo'] = '\\includegraphics{%s}\\par' % \
diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py
index 2651ec2e4..223ed78fd 100644
--- a/sphinx/writers/manpage.py
+++ b/sphinx/writers/manpage.py
@@ -97,8 +97,7 @@ class ManualPageTranslator(BaseTranslator):
if builder.config.today:
self._docinfo['date'] = builder.config.today
else:
- self._docinfo['date'] = format_date(builder.config.today_fmt or
- _('MMMM dd, YYYY'),
+ self._docinfo['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'),
language=builder.config.language)
self._docinfo['copyright'] = builder.config.copyright
self._docinfo['version'] = builder.config.version
diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py
index fc7d31534..978d56c0b 100644
--- a/sphinx/writers/texinfo.py
+++ b/sphinx/writers/texinfo.py
@@ -218,8 +218,7 @@ class TexinfoTranslator(nodes.NodeVisitor):
'project': self.escape(self.builder.config.project),
'copyright': self.escape(self.builder.config.copyright),
'date': self.escape(self.builder.config.today or
- format_date(self.builder.config.today_fmt or
- _('MMMM dd, YYYY'),
+ format_date(self.builder.config.today_fmt or _('%b %d, %Y'),
language=self.builder.config.language))
})
# title
diff --git a/tests/test_util_i18n.py b/tests/test_util_i18n.py
index a534b2771..5a54cbb80 100644
--- a/tests/test_util_i18n.py
+++ b/tests/test_util_i18n.py
@@ -169,6 +169,7 @@ def test_get_catalogs_with_compact(dir):
def test_format_date():
date = datetime.date(2016, 2, 7)
+ # default format
format = None
assert i18n.format_date(format, date=date) == '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='de') == '07.02.2016'
+ # strftime format
format = '%B %d, %Y'
assert i18n.format_date(format, date=date) == '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='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'
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():
app = TestApp()