Repository: getnikola/nikola

Issue:
Webiso date_format should always ask Python
Currently, the date format handlers are asked no matter whichdate_format is passed to them, including webiso. This could lead to the `time` element to have the wrong `datetime` value.
Webiso date_format should always ask Python
Currently, the date format handlers are asked no matter whichdate_format is passed to them, including webiso. This could lead to the `time` element to have the wrong `datetime` value.


Discussion:
Uh, what?
@sukiletxe: That only happens if you have a date format handler which handles `webiso` incorrectly. That would be a bug in the date format handler.

We could of course also always use Nikola code when `webiso` is requested.

@Kwpolska: he is referring to the code around here: https://github.com/getnikola/nikola/blob/master/nikola/utils.py#L1234
@felixfontein: I know, but isn't that a behaviour that should be taken into account? Imho, webiso is a Nikola-specific date format, whose output should always be the default one.
I don't really care too much :) Feel free to make a PR which changes this, i.e. which only asks the date format handlers when the format isn't `webiso`.
Uh, what?
@sukiletxe: That only happens if you have a date format handler which handles `webiso` incorrectly. That would be a bug in the date format handler.

We could of course also always use Nikola code when `webiso` is requested.

@Kwpolska: he is referring to the code around here: https://github.com/getnikola/nikola/blob/master/nikola/utils.py#L1234
@felixfontein: I know, but isn't that a behaviour that should be taken into account? Imho, webiso is a Nikola-specific date format, whose output should always be the default one.
I don't really care too much :) Feel free to make a PR which changes this, i.e. which only asks the date format handlers when the format isn't `webiso`.

Resolving patch:
diff --git a/nikola/utils.py b/nikola/utils.py
--- a/nikola/utils.py
+++ b/nikola/utils.py
@@ -1230,18 +1230,19 @@ def formatted_date(self, date_format, date):
             # Get a string out of a TranslatableSetting
             if isinstance(date_format, TranslatableSetting):
                 date_format = date_format(current_lang)
-            # First check handlers
-            for handler in self.formatted_date_handlers:
-                fmt_date = handler(date_format, date, current_lang)
-                if fmt_date is not None:
-                    break
-            # If no handler was able to format the date, ask Python
-            if fmt_date is None:
-                if date_format == 'webiso':
-                    # Formatted after RFC 3339 (web ISO 8501 profile) with Zulu
-                    # zone desgignator for times in UTC and no microsecond precision.
-                    fmt_date = date.replace(microsecond=0).isoformat().replace('+00:00', 'Z')
-                else:
+            # Always ask Python if the date_format is webiso
+            if date_format == 'webiso':
+                # Formatted after RFC 3339 (web ISO 8501 profile) with Zulu
+                # zone designator for times in UTC and no microsecond precision.
+                fmt_date = date.replace(microsecond=0).isoformat().replace('+00:00', 'Z')
+            # If not, check handlers
+            else:
+                for handler in self.formatted_date_handlers:
+                    fmt_date = handler(date_format, date, current_lang)
+                    if fmt_date is not None:
+                        break
+                # If no handler was able to format the date, ask Python
+                if fmt_date is None:
                     fmt_date = date.strftime(date_format)
 
             # Issue #383, this changes from py2 to py3


Test patch: