@@ -18,18 +18,43 @@ class DateTimeToStringTransformerTest extends DateTimeTestCase
18
18
public function dataProvider ()
19
19
{
20
20
return array (
21
- array ('Y-m-d H:i:s ' , '2010-02-03 04 :05:06 ' , '2010-02-03 04 :05:06 UTC ' ),
22
- array ('Y-m-d H:i:00 ' , '2010-02-03 04 :05:00 ' , '2010-02-03 04 :05:00 UTC ' ),
23
- array ('Y-m-d H:i ' , '2010-02-03 04 :05 ' , '2010-02-03 04 :05:00 UTC ' ),
24
- array ('Y-m-d H ' , '2010-02-03 04 ' , '2010-02-03 04 :00:00 UTC ' ),
21
+ array ('Y-m-d H:i:s ' , '2010-02-03 16 :05:06 ' , '2010-02-03 16 :05:06 UTC ' ),
22
+ array ('Y-m-d H:i:00 ' , '2010-02-03 16 :05:00 ' , '2010-02-03 16 :05:00 UTC ' ),
23
+ array ('Y-m-d H:i ' , '2010-02-03 16 :05 ' , '2010-02-03 16 :05:00 UTC ' ),
24
+ array ('Y-m-d H ' , '2010-02-03 16 ' , '2010-02-03 16 :00:00 UTC ' ),
25
25
array ('Y-m-d ' , '2010-02-03 ' , '2010-02-03 00:00:00 UTC ' ),
26
26
array ('Y-m ' , '2010-02 ' , '2010-02-01 00:00:00 UTC ' ),
27
27
array ('Y ' , '2010 ' , '2010-01-01 00:00:00 UTC ' ),
28
28
array ('d-m-Y ' , '03-02-2010 ' , '2010-02-03 00:00:00 UTC ' ),
29
- array ('H:i:s ' , '04:05:06 ' , '1970-01-01 04:05:06 UTC ' ),
30
- array ('H:i:00 ' , '04:05:00 ' , '1970-01-01 04:05:00 UTC ' ),
31
- array ('H:i ' , '04:05 ' , '1970-01-01 04:05:00 UTC ' ),
32
- array ('H ' , '04 ' , '1970-01-01 04:00:00 UTC ' ),
29
+ array ('H:i:s ' , '16:05:06 ' , '1970-01-01 16:05:06 UTC ' ),
30
+ array ('H:i:00 ' , '16:05:00 ' , '1970-01-01 16:05:00 UTC ' ),
31
+ array ('H:i ' , '16:05 ' , '1970-01-01 16:05:00 UTC ' ),
32
+ array ('H ' , '16 ' , '1970-01-01 16:00:00 UTC ' ),
33
+
34
+ // different day representations
35
+ array ('Y-m-j ' , '2010-02-3 ' , '2010-02-03 00:00:00 UTC ' ),
36
+ array ('Y-z ' , '2010-33 ' , '2010-02-03 00:00:00 UTC ' ),
37
+ array ('z ' , '33 ' , '1970-02-03 00:00:00 UTC ' ),
38
+
39
+ // not bijective
40
+ //array('Y-m-D', '2010-02-Wed', '2010-02-03 00:00:00 UTC'),
41
+ //array('Y-m-l', '2010-02-Wednesday', '2010-02-03 00:00:00 UTC'),
42
+
43
+ // different month representations
44
+ array ('Y-n-d ' , '2010-2-03 ' , '2010-02-03 00:00:00 UTC ' ),
45
+ array ('Y-M-d ' , '2010-Feb-03 ' , '2010-02-03 00:00:00 UTC ' ),
46
+ array ('Y-F-d ' , '2010-February-03 ' , '2010-02-03 00:00:00 UTC ' ),
47
+
48
+ // different year representations
49
+ array ('y-m-d ' , '10-02-03 ' , '2010-02-03 00:00:00 UTC ' ),
50
+
51
+ // different time representations
52
+ array ('G:i:s ' , '16:05:06 ' , '1970-01-01 16:05:06 UTC ' ),
53
+ array ('g:i:s a ' , '4:05:06 pm ' , '1970-01-01 16:05:06 UTC ' ),
54
+ array ('h:i:s a ' , '04:05:06 pm ' , '1970-01-01 16:05:06 UTC ' ),
55
+
56
+ // seconds since unix
57
+ array ('U ' , '1265213106 ' , '2010-02-03 16:05:06 UTC ' ),
33
58
);
34
59
}
35
60
@@ -75,8 +100,24 @@ public function testTransformExpectsDateTime()
75
100
/**
76
101
* @dataProvider dataProvider
77
102
*/
78
- public function testReverseTransform ($ format , $ input , $ output )
103
+ public function testReverseTransformBeforePhp538 ($ format , $ input , $ output )
79
104
{
105
+ $ reverseTransformer = new DateTimeToStringTransformer ('UTC ' , 'UTC ' , $ format , false );
106
+
107
+ $ output = new \DateTime ($ output );
108
+
109
+ $ this ->assertDateTimeEquals ($ output , $ reverseTransformer ->reverseTransform ($ input ));
110
+ }
111
+
112
+ /**
113
+ * @dataProvider dataProvider
114
+ */
115
+ public function testReverseTransformAsOfPhp538 ($ format , $ input , $ output )
116
+ {
117
+ if (version_compare (phpversion (), '5.3.8 ' , '< ' )) {
118
+ $ this ->markTestSkipped ('Requires PHP 5.3.8 or newer ' );
119
+ }
120
+
80
121
$ reverseTransformer = new DateTimeToStringTransformer ('UTC ' , 'UTC ' , $ format );
81
122
82
123
$ output = new \DateTime ($ output );
@@ -95,7 +136,7 @@ public function testReverseTransform_differentTimezones()
95
136
{
96
137
$ reverseTransformer = new DateTimeToStringTransformer ('America/New_York ' , 'Asia/Hong_Kong ' , 'Y-m-d H:i:s ' );
97
138
98
- $ output = new \DateTime ('2010-02-03 04 :05:06 Asia/Hong_Kong ' );
139
+ $ output = new \DateTime ('2010-02-03 16 :05:06 Asia/Hong_Kong ' );
99
140
$ input = $ output ->format ('Y-m-d H:i:s ' );
100
141
$ output ->setTimeZone (new \DateTimeZone ('America/New_York ' ));
101
142
0 commit comments