Browse Source

Fix meridian tests failing around TZ offset issues.

When local time and UTC are in different halves of the meridian tests
would fail as the new changes in DateTimeWidget would default the
meridian to pm.
Mark Story 11 years ago
parent
commit
4e6cb44dd3
2 changed files with 6 additions and 4 deletions
  1. 3 1
      src/View/Helper/FormHelper.php
  2. 3 3
      tests/TestCase/View/Helper/FormHelperTest.php

+ 3 - 1
src/View/Helper/FormHelper.php

@@ -2075,9 +2075,11 @@ class FormHelper extends Helper
         $options = $this->_singleDatetime($options, 'meridian');
 
         if (isset($options['val'])) {
+            $hour = date('H');
             $options['val'] = [
-                'hour' => date('H'),
+                'hour' => $hour,
                 'minute' => (int)$options['val'],
+                'meridian' => $hour > 11 ? 'pm' : 'am',
             ];
         }
         return $this->datetime($fieldName, $options);

+ 3 - 3
tests/TestCase/View/Helper/FormHelperTest.php

@@ -5355,15 +5355,15 @@ class FormHelperTest extends TestCase
     {
         extract($this->dateRegex);
 
-        $now = time();
+        $now = new \DateTime();
         $result = $this->Form->meridian('Model.field', ['value' => 'am']);
         $expected = [
             ['select' => ['name' => 'Model[field][meridian]']],
             ['option' => ['value' => '']],
             '/option',
             $meridianRegex,
-            ['option' => ['value' => date('a', $now), 'selected' => 'selected']],
-            date('a', $now),
+            ['option' => ['value' => $now->format('a'), 'selected' => 'selected']],
+            $now->format('a'),
             '/option',
             '*/select'
         ];