From 2c50ccb764bb67fcaaed641289e9e4c3649f0f91 Mon Sep 17 00:00:00 2001 From: OGINO Masanori Date: Tue, 10 Jun 2014 09:47:14 +0900 Subject: [PATCH] Add timezone to datetime objects. Refs #962. Based on https://github.com/getpelican/pelican/pull/977, but it adds timezone information before formatting. Signed-off-by: OGINO Masanori --- pelican/contents.py | 9 ++++++- .../basic/a-markdown-powered-article.html | 4 ++-- pelican/tests/output/basic/archives.html | 2 +- pelican/tests/output/basic/article-1.html | 4 ++-- pelican/tests/output/basic/article-2.html | 4 ++-- pelican/tests/output/basic/article-3.html | 4 ++-- .../output/basic/author/alexis-metaireau.html | 8 +++---- pelican/tests/output/basic/categories.html | 2 +- pelican/tests/output/basic/category/bar.html | 2 +- pelican/tests/output/basic/category/cat1.html | 10 ++++---- pelican/tests/output/basic/category/misc.html | 10 ++++---- pelican/tests/output/basic/category/yeah.html | 4 ++-- .../basic/feeds/alexis-metaireau.atom.xml | 6 ++--- .../basic/feeds/alexis-metaireau.rss.xml | 6 ++--- .../tests/output/basic/feeds/all-en.atom.xml | 22 ++++++++--------- .../tests/output/basic/feeds/all-fr.atom.xml | 4 ++-- pelican/tests/output/basic/feeds/all.atom.xml | 24 +++++++++---------- pelican/tests/output/basic/feeds/bar.atom.xml | 4 ++-- .../tests/output/basic/feeds/cat1.atom.xml | 10 ++++---- .../tests/output/basic/feeds/misc.atom.xml | 10 ++++---- .../tests/output/basic/feeds/yeah.atom.xml | 4 ++-- .../basic/filename_metadata-example.html | 4 ++-- pelican/tests/output/basic/index.html | 24 +++++++++---------- pelican/tests/output/basic/oh-yeah.html | 4 ++-- .../tests/output/basic/override/index.html | 2 +- .../pages/this-is-a-test-hidden-page.html | 2 +- .../basic/pages/this-is-a-test-page.html | 2 +- .../tests/output/basic/second-article-fr.html | 4 ++-- .../tests/output/basic/second-article.html | 4 ++-- pelican/tests/output/basic/tag/bar.html | 10 ++++---- pelican/tests/output/basic/tag/baz.html | 4 ++-- pelican/tests/output/basic/tag/foo.html | 8 +++---- pelican/tests/output/basic/tag/foobar.html | 4 ++-- pelican/tests/output/basic/tag/yeah.html | 2 +- .../output/basic/this-is-a-super-article.html | 6 ++--- pelican/tests/output/basic/unbelievable.html | 4 ++-- .../custom/a-markdown-powered-article.html | 4 ++-- pelican/tests/output/custom/article-1.html | 4 ++-- pelican/tests/output/custom/article-2.html | 4 ++-- pelican/tests/output/custom/article-3.html | 4 ++-- .../custom/author/alexis-metaireau.html | 10 ++++---- .../custom/author/alexis-metaireau2.html | 12 +++++----- .../custom/author/alexis-metaireau3.html | 4 ++-- pelican/tests/output/custom/category/bar.html | 2 +- .../tests/output/custom/category/cat1.html | 8 +++---- .../tests/output/custom/category/misc.html | 8 +++---- .../tests/output/custom/category/yeah.html | 4 ++-- .../output/custom/drafts/a-draft-article.html | 2 +- .../custom/filename_metadata-example.html | 2 +- pelican/tests/output/custom/index.html | 8 +++---- pelican/tests/output/custom/index2.html | 12 +++++----- pelican/tests/output/custom/index3.html | 4 ++-- pelican/tests/output/custom/oh-yeah-fr.html | 2 +- pelican/tests/output/custom/oh-yeah.html | 2 +- .../output/custom/second-article-fr.html | 2 +- .../tests/output/custom/second-article.html | 2 +- pelican/tests/output/custom/tag/bar.html | 10 ++++---- pelican/tests/output/custom/tag/baz.html | 2 +- pelican/tests/output/custom/tag/foo.html | 8 +++---- pelican/tests/output/custom/tag/foobar.html | 4 ++-- pelican/tests/output/custom/tag/yeah.html | 2 +- .../custom/this-is-a-super-article.html | 6 ++--- pelican/tests/output/custom/unbelievable.html | 2 +- .../author/alexis-metaireau.html | 8 +++---- .../author/alexis-metaireau2.html | 12 +++++----- .../author/alexis-metaireau3.html | 4 ++-- .../output/custom_locale/category/bar.html | 2 +- .../output/custom_locale/category/cat1.html | 8 +++---- .../output/custom_locale/category/misc.html | 8 +++---- .../output/custom_locale/category/yeah.html | 6 ++--- .../custom_locale/drafts/a-draft-article.html | 2 +- pelican/tests/output/custom_locale/index.html | 8 +++---- .../tests/output/custom_locale/index2.html | 12 +++++----- .../tests/output/custom_locale/index3.html | 4 ++-- .../output/custom_locale/oh-yeah-fr.html | 2 +- .../02/this-is-a-super-article/index.html | 6 ++--- .../2010/octobre/15/unbelievable/index.html | 2 +- .../posts/2010/octobre/20/oh-yeah/index.html | 2 +- .../20/a-markdown-powered-article/index.html | 2 +- .../2011/février/17/article-1/index.html | 2 +- .../2011/février/17/article-2/index.html | 2 +- .../2011/février/17/article-3/index.html | 2 +- .../2012/février/29/second-article/index.html | 2 +- .../30/filename_metadata-example/index.html | 2 +- .../custom_locale/second-article-fr.html | 2 +- .../tests/output/custom_locale/tag/bar.html | 10 ++++---- .../tests/output/custom_locale/tag/baz.html | 2 +- .../tests/output/custom_locale/tag/foo.html | 8 +++---- .../output/custom_locale/tag/foobar.html | 6 ++--- .../tests/output/custom_locale/tag/yeah.html | 2 +- pelican/tests/test_utils.py | 3 +++ pelican/utils.py | 4 +++- 92 files changed, 259 insertions(+), 247 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index 297a537b..7a9a8bc0 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -16,7 +16,7 @@ from pelican import signals from pelican.settings import DEFAULT_CONFIG from pelican.utils import (slugify, truncate_html_words, memoized, strftime, python_2_unicode_compatible, deprecated_attribute, - path_to_url, SafeDatetime) + path_to_url, set_date_tzinfo, SafeDatetime) # Import these so that they're avalaible when you import from pelican.contents. from pelican.urlwrappers import (URLWrapper, Author, Category, Tag) # NOQA @@ -117,9 +117,16 @@ class Content(object): locale.setlocale(locale.LC_ALL, locale_string) self.date_format = self.date_format[1] + # manage timezone + default_timezone = settings.get('TIMEZONE', 'UTC') + timezone = getattr(self, 'timezone', default_timezone) + if hasattr(self, 'date'): + self.date = set_date_tzinfo(self.date, timezone) self.locale_date = strftime(self.date, self.date_format) + if hasattr(self, 'modified'): + self.modified = set_date_tzinfo(self.modified, timezone) self.locale_modified = strftime(self.modified, self.date_format) # manage status diff --git a/pelican/tests/output/basic/a-markdown-powered-article.html b/pelican/tests/output/basic/a-markdown-powered-article.html index 40c96766..5fcc42a9 100644 --- a/pelican/tests/output/basic/a-markdown-powered-article.html +++ b/pelican/tests/output/basic/a-markdown-powered-article.html @@ -34,7 +34,7 @@
- + Published: Wed 20 April 2011 @@ -66,4 +66,4 @@
- \ No newline at end of file + diff --git a/pelican/tests/output/basic/archives.html b/pelican/tests/output/basic/archives.html index e32c92ba..f8f1a67f 100644 --- a/pelican/tests/output/basic/archives.html +++ b/pelican/tests/output/basic/archives.html @@ -69,4 +69,4 @@ - \ No newline at end of file + diff --git a/pelican/tests/output/basic/article-1.html b/pelican/tests/output/basic/article-1.html index 15a1496d..4ea7f4e3 100644 --- a/pelican/tests/output/basic/article-1.html +++ b/pelican/tests/output/basic/article-1.html @@ -34,7 +34,7 @@
- + Published: Thu 17 February 2011 @@ -65,4 +65,4 @@
- \ No newline at end of file + diff --git a/pelican/tests/output/basic/article-2.html b/pelican/tests/output/basic/article-2.html index c4b09e35..45130e55 100644 --- a/pelican/tests/output/basic/article-2.html +++ b/pelican/tests/output/basic/article-2.html @@ -34,7 +34,7 @@
- + Published: Thu 17 February 2011 @@ -65,4 +65,4 @@
- \ No newline at end of file + diff --git a/pelican/tests/output/basic/article-3.html b/pelican/tests/output/basic/article-3.html index 1c07e5e2..8603430f 100644 --- a/pelican/tests/output/basic/article-3.html +++ b/pelican/tests/output/basic/article-3.html @@ -34,7 +34,7 @@
- + Published: Thu 17 February 2011 @@ -65,4 +65,4 @@
- \ No newline at end of file + diff --git a/pelican/tests/output/basic/author/alexis-metaireau.html b/pelican/tests/output/basic/author/alexis-metaireau.html index d1dc6da6..11d54185 100644 --- a/pelican/tests/output/basic/author/alexis-metaireau.html +++ b/pelican/tests/output/basic/author/alexis-metaireau.html @@ -29,11 +29,11 @@

This is a super article !

- + Published: Thu 02 December 2010
- + Updated: Sun 17 November 2013 @@ -69,7 +69,7 @@
- + Published: Wed 20 October 2010 @@ -109,4 +109,4 @@ YEAH !

- \ No newline at end of file + diff --git a/pelican/tests/output/basic/categories.html b/pelican/tests/output/basic/categories.html index fa2fc012..55e955c8 100644 --- a/pelican/tests/output/basic/categories.html +++ b/pelican/tests/output/basic/categories.html @@ -49,4 +49,4 @@
- \ No newline at end of file + diff --git a/pelican/tests/output/basic/category/bar.html b/pelican/tests/output/basic/category/bar.html index 763cfe77..18e434cb 100644 --- a/pelican/tests/output/basic/category/bar.html +++ b/pelican/tests/output/basic/category/bar.html @@ -29,7 +29,7 @@

Oh yeah !