瀏覽代碼

Fix Date meta header parsing with ISO-8601 datetime strings

Symfony YAML interprets ISO-8601 datetime strings and returns timestamps instead of the string. This behavior conforms to the YAML standard, i.e. this is no bug of Symfony YAML.

Fixes #336. Thanks @csholmq for reporting this.
Daniel Rudolf 9 年之前
父節點
當前提交
bbd8ef8847
共有 1 個文件被更改,包括 11 次插入1 次删除
  1. 11 1
      lib/Pico.php

+ 11 - 1
lib/Pico.php

@@ -791,7 +791,17 @@ class Pico
             }
 
             if (!empty($meta['date'])) {
-                $meta['time'] = strtotime($meta['date']);
+                // workaround for issue #336
+                // Symfony YAML interprets ISO-8601 datetime strings and returns timestamps instead of the string
+                // this behavior conforms to the YAML standard, i.e. this is no bug of Symfony YAML
+                if (is_int($meta['date'])) {
+                    $meta['time'] = $meta['date'];
+
+                    $rawDateFormat = (date('H:i:s', $meta['time']) === '00:00:00') ? 'Y-m-d' : 'Y-m-d H:i:s';
+                    $meta['date'] = date($rawDateFormat, $meta['time']);
+                } else {
+                    $meta['time'] = strtotime($meta['date']);
+                }
                 $meta['date_formatted'] = utf8_encode(strftime($this->getConfig('date_format'), $meta['time']));
             } else {
                 $meta['time'] = $meta['date_formatted'] = '';