@@ -124,15 +124,6 @@ public function testGetInt()
124
124
$ this ->assertEquals (0 , $ bag ->getInt ('unknown ' ), '->getInt() returns zero if a parameter is not defined ' );
125
125
}
126
126
127
- public function testGetDateTime ()
128
- {
129
- $ format = 'Y-m-d H:i:s ' ;
130
- $ bag = new ParameterBag (array ('d1 ' => '2016-01-01 00:00:00 ' ));
131
- $ date = \DateTime::createFromFormat ($ format , '2016-01-01 00:00:00 ' );
132
-
133
- $ this ->assertEquals ($ date , $ bag ->getDateTime ('d1 ' , $ format ), '->getDateTime() returns a date from the specified format ' );
134
- }
135
-
136
127
public function testGetDate ()
137
128
{
138
129
$ isoDate = '2016-07-05T15:30:00UTC ' ;
@@ -142,17 +133,21 @@ public function testGetDate()
142
133
));
143
134
144
135
$ date = \DateTime::createFromFormat ('Y-m-d ' , '2016-01-01 ' );
145
- $ diff = $ date ->diff ($ bag ->getDate ('d1 ' ));
136
+ $ diff = $ date ->diff ($ bag ->getDate ('d1 ' , ' Y-m-d ' ));
146
137
147
138
$ this ->assertEquals (0 , $ diff ->days , '->getDate() returns a date via the format specified ' );
148
- $ this ->assertNull ($ bag ->getDate ('d1 ' , 'd/m/Y ' ), '->getDate() returns false if the format is not valid ' );
139
+ $ this ->assertNull ($ bag ->getDate ('d1 ' , 'd/m/Y ' ), '->getDate() returns null if the format is not valid ' );
149
140
$ this ->assertNull ($ bag ->getDate ('d2 ' , 'd/m/Y ' ), '->getDate() returns null if the parameter is not found ' );
150
141
151
142
$ date = $ bag ->getDate ('iso ' , \DateTime::ISO8601 );
152
143
$ this ->assertEquals (new \DateTime ($ isoDate ), $ date );
153
144
$ this ->assertEquals ('UTC ' , $ date ->getTimezone ()->getName ());
154
145
155
- $ this ->assertEquals ($ date , $ bag ->getDate ('nokey ' , 'Y-m-d ' , $ date ));
146
+ $ this ->assertEquals ($ date , $ bag ->getDate ('nokey ' , \DateTime::ISO8601 , $ isoDate ));
147
+ $ this ->assertNull ($ bag ->getDate ('nokey ' , 'd/m/Y ' , $ isoDate ), '->getDate() returns null when the default value is not in the specified format ' );
148
+
149
+ $ tz = $ bag ->getDate ('d1 ' , 'Y-m-d ' , null , new \DateTimeZone ('Europe/Tirane ' ))->getTimezone ()->getName ();
150
+ $ this ->assertEquals ('Europe/Tirane ' , $ tz , '->getDate() accepts a DateTimeZone object which specifies the preferred timezone ' );
156
151
}
157
152
158
153
public function testFilter ()
0 commit comments