2 require_once 'include/TimeDate.php';
4 class TimeDateTest extends Sugar_PHPUnit_Framework_TestCase
11 const DEFAULT_TIME_FORMAT = 'H:i';
13 protected $date_tests = array(
14 array("db" => '2005-10-25 07:00:00', "df" => 'd-m-Y', 'tz' => 'America/Los_Angeles', "display" => '25-10-2005', "dbdate" => "2005-10-25 00:00:00"),
16 array("db" => '2005-10-26 06:42:00', "df" => 'd-m-Y', "tf" => 'h.iA', 'tz' => 'America/Los_Angeles', "display" => '25-10-2005 11.42PM', "dbdate" => "2005-10-25 23:42:00"),
18 array("db" => '2005-11-25 00:00:00', "df" => 'd-m-Y', 'tz' => 'Europe/London', "display" => '25-11-2005', "dbdate" => "2005-11-25 00:00:00"),
20 array("db" => '2005-11-24 23:00:00', "dbdate" => "2005-11-25", "df" => 'd;m;Y', 'tz' => 'Europe/Oslo', "display" => '25;11;2005', "dbdate" => "2005-11-25 00:00:00"),
22 array("db" => '2005-10-24 23:00:00', "dbdate" => "2005-10-25", "df" => 'd-m-Y', 'tz' => 'Europe/London', "display" => '25-10-2005', "dbdate" => "2005-10-25 00:00:00"),
24 array("db" => '1997-10-25 07:00:00', "df" => 'Y-m-d', 'tz' => 'America/Los_Angeles', "display" => '1997-10-25', "dbdate" => "1997-10-25 00:00:00"),
25 array("db" => '1997-01-25 00:00:00', "df" => 'm-d-Y', 'tz' => 'Europe/London', "display" => '01-25-1997', "dbdate" => "1997-01-25 00:00:00"),
27 array("db" => '2005-10-25 10:42:24', "df" => 'd/m/Y', "tf" => "H:i:s", 'tz' => 'America/Los_Angeles', "display" => '25/10/2005 03:42:24', "dbdate" => "2005-10-25 03:42:24"),
28 array("db" => '2005-10-25 02:42:24', "df" => 'd/m/Y', "tf" => "H:i:s", 'tz' => 'Europe/London', "display" => '25/10/2005 03:42:24', "dbdate" => "2005-10-25 03:42:24"),
29 array("db" => '2005-10-25 01:42:24', "df" => 'd/m/Y', "tf" => "H:i:s", 'tz' => 'Asia/Jerusalem', "display" => '25/10/2005 03:42:24', "dbdate" => "2005-10-25 03:42:24"),
30 // FAIL! FIXME: same format leads to no TZ conversion
31 array("db" => '2005-10-25 10:42:24', "df" => 'Y-m-d', "tf" => "H:i:s", 'tz' => 'America/Los_Angeles', "display" => '2005-10-25 03:42:24', "dbdate" => "2005-10-25 03:42:24"),
33 array("db" => '2005-10-25 10:42:00', "df" => 'd/m/Y', "tf" => "H:i", 'tz' => 'America/Los_Angeles', "display" => '25/10/2005 03:42', "dbdate" => "2005-10-25 03:42:00"),
34 array("db" => '2005-10-25 22:00:00', "df" => 'd/m/Y', "tf" => "ha", 'tz' => 'America/Los_Angeles', "display" => '25/10/2005 03pm', "dbdate" => "2005-10-25 15:00:00"),
35 array("db" => '2005-10-25 10:00:00', "df" => 'd/m/Y', "tf" => "h", 'tz' => 'America/Los_Angeles', "display" => '25/10/2005 03', "dbdate" => "2005-10-25 03:00:00"),
36 array("db" => '2005-10-25 20:00:00', "df" => 'd/m/Y', "tf" => "H", 'tz' => 'America/Los_Angeles', "display" => '25/10/2005 13', "dbdate" => "2005-10-25 13:00:00"),
39 protected $time_tests = array(
41 array("db" => "11:45:00", "display" => "11:45"),
42 array("db" => "05:17:28", "tf" => "H.i.s", "display" => "05.17.28"),
44 array("db" => "17:34:00", "tf" => "H:i", "display" => "17:34"),
45 array("db" => "11:42:00", "tf" => "h.iA", "display" => "11.42AM"),
46 array("db" => "15:00:00", "tf" => "ha", "display" => "03pm"),
47 array("db" => "15:00:00", "tf" => "H", "display" => "15"),
48 // FIXME: is this a valid format? it doesn't allow roundtrip
49 array("db" => "03:00:00", "tf" => "h", "display" => "03"),
51 array("db" => "16:42:34", "tf" => "s:i:H", "display" => "34:42:16"),
54 public function setUp()
56 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
57 $this->time_date = new TimeDate();
58 $this->_noUserCache();
61 public function tearDown()
63 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
64 unset($GLOBALS['current_user']);
65 unset($this->time_date);
68 protected function _noUserCache()
70 $this->time_date->allow_cache = false;
73 protected function _setPrefs($datef, $timef, $tz) {
74 $GLOBALS['current_user']->setPreference('datef', $datef);
75 $GLOBALS['current_user']->setPreference('timef', $timef);
76 $GLOBALS['current_user']->setPreference('timezone', $tz);
77 // new object to avoid TZ caching
78 $this->time_date = new TimeDate();
79 $this->_noUserCache();
82 protected function _dateOnly($datetime)
84 // FIXME: assumes dates have no spaces
85 $dt = explode(' ', $datetime);
89 protected function _timeOnly($datetime)
91 // FIXME: assumes dates have no spaces
92 $dt = explode(' ', $datetime);
100 * test conversion from local datetime to DB datetime
102 public function testToDbFormats()
104 foreach($this->date_tests as $datetest) {
105 $tf = isset($datetest["tf"]) ? $datetest["tf"] : self::DEFAULT_TIME_FORMAT;
106 $this->_setPrefs($datetest["df"], $tf, $datetest["tz"]);
107 $this->assertEquals($datetest["db"],
108 $this->time_date->to_db($datetest["display"]),
109 "Broken conversion for '{$datetest["df"]} $tf' with date '{$datetest["display"]}' and TZ {$datetest["tz"]}");
114 * test conversion from full local datetime to DB date
116 public function testToDbDateFormatsWithOffset()
118 foreach($this->date_tests as $datetest) {
119 $tf = isset($datetest["tf"]) ? $datetest["tf"] : self::DEFAULT_TIME_FORMAT;
120 $this->_setPrefs($datetest["df"], $tf, $datetest["tz"]);
122 $this->_dateOnly($datetest["db"]),
123 $this->time_date->to_db_date($datetest["display"], true),
124 "Broken conversion for '{$datetest["df"]} $tf' with date '{$datetest["display"]}' and TZ {$datetest["tz"]}");
129 * test conversion from local date to DB date, no TZ handling
131 public function testToDbDateFormatsNoOffset()
133 foreach($this->date_tests as $datetest) {
134 $tf = isset($datetest["tf"]) ? $datetest["tf"] : self::DEFAULT_TIME_FORMAT;
135 $this->_setPrefs($datetest["df"], $tf, $datetest["tz"]);
137 $this->_dateOnly($datetest["dbdate"]),
138 $this->time_date->to_db_date($this->_dateOnly($datetest["display"]), false),
139 "Broken conversion for '{$datetest["df"]} $tf' with date '{$datetest["display"]}' and TZ {$datetest["tz"]}");
144 * test conversion from full local datetime to DB time
146 public function testToDbTimeFormatsWithTz()
148 foreach($this->date_tests as $datetest) {
149 $tf = isset($datetest["tf"]) ? $datetest["tf"] : self::DEFAULT_TIME_FORMAT;
150 $this->_setPrefs($datetest["df"], $tf, $datetest["tz"]);
152 $this->_timeOnly($datetest["db"]),
153 $this->time_date->to_db_time($datetest["display"], true),
154 "Broken conversion for '{$datetest["df"]} $tf' with date '{$datetest["display"]}' and TZ {$datetest["tz"]}");
159 * test conversion from local time to DB time, no TZ handling
161 public function testToDbTimeFormatsNoTz()
163 foreach($this->time_tests as $datetest) {
164 $tf = isset($datetest["tf"]) ? $datetest["tf"] : self::DEFAULT_TIME_FORMAT;
165 $this->_setPrefs('Y-m-d', $tf, '');
168 $this->time_date->to_db_time($datetest["display"], false),
169 "Broken conversion for '$tf' with date '{$datetest["display"]}'");
174 * test conversion from local date+time to DB date+time, no TZ handling
176 public function testToDbDateTimeFormats()
178 foreach($this->date_tests as $datetest) {
179 $tf = isset($datetest["tf"]) ? $datetest["tf"] : self::DEFAULT_TIME_FORMAT;
180 $this->_setPrefs($datetest["df"], $tf, $datetest["tz"]);
181 $dt = explode(' ', $datetest["display"]);
183 list($date, $time) = $dt;
186 $z = new DateTime("@0", new DateTimeZone("GMT"));
187 $time = $z->format($tf);
190 explode(' ',$datetest["dbdate"]),
191 $this->time_date->to_db_date_time($date, $time),
192 "Broken conversion for '{$datetest["df"]} $tf' with date '{$datetest["display"]}' and TZ {$datetest["tz"]}");
198 * test conversion from DB date+time to local date+time with TZ handling
200 public function testToDisplayDateTimeFormats()
202 foreach($this->date_tests as $datetest) {
203 if(!isset($datetest["tf"])) {
206 $tf = $datetest["tf"];
208 $df = $datetest["df"]." ".$tf;
209 $this->_setPrefs($datetest["df"], $tf, $datetest["tz"]);
210 $result = $this->time_date->to_display_date_time($datetest["db"], true, true, $GLOBALS['current_user']);
211 if(!isset($datetest["tf"])) {
212 $result = $this->_dateOnly($result);
215 $datetest["display"],
217 "Broken conversion for '$df' with date '{$datetest["db"]}' and TZ {$datetest["tz"]}");
222 * test conversion from DB date+time to local date+time without TZ handling
224 public function testToDisplayFormatsNoTz()
226 foreach($this->date_tests as $datetest) {
227 if(!isset($datetest["tf"])) {
230 $tf = $datetest["tf"];
232 $df = $datetest["df"]." ".$tf;
233 $this->_setPrefs($datetest["df"], $tf, $datetest["tz"]);
234 $result = $this->time_date->to_display($datetest["dbdate"], $this->time_date->get_db_date_time_format(), $df);
235 if(!isset($datetest["tf"])) {
236 $result = $this->_dateOnly($result);
239 $datetest["display"],
241 "Broken conversion for '$df' with date '{$datetest["db"]}' and TZ {$datetest["tz"]}");
246 * test conversion from DB time to local time without TZ conversion
248 public function testToDisplayTimeFormatsNoTZ()
250 foreach($this->time_tests as $datetest) {
251 $tf = isset($datetest["tf"]) ? $datetest["tf"] : self::DEFAULT_TIME_FORMAT;
252 $this->_setPrefs('Y-m-d', $tf, '');
254 $datetest["display"],
255 $this->time_date->to_display_time($datetest["db"], true, false),
256 "Broken conversion for '$tf' with date '{$datetest["db"]}'");
261 * test conversion from DB time to local time with TZ conversion
263 public function testToDisplayTimeFormatsWithTZ()
265 foreach($this->date_tests as $datetest) {
266 if(!isset($datetest["tf"])) continue;
267 $this->_setPrefs($datetest["df"], $datetest["tf"], $datetest["tz"]);
268 $result = $this->time_date->to_display_time($datetest["db"], true, true);
269 $result = $this->_timeOnly($result);
271 $this->_timeOnly($datetest["display"]),
273 "Broken conversion for '{$datetest["tf"]}' with date '{$datetest["db"]}' and TZ {$datetest["tz"]}");
279 * test conversion from DB date to local date without TZ handling
281 public function testToDisplayDateFormatsNoTz()
283 foreach($this->date_tests as $datetest) {
284 if(!isset($datetest["tf"])) {
287 $tf = $datetest["tf"];
289 $df = $datetest["df"]." ".$tf;
290 $this->_setPrefs($datetest["df"], $tf, $datetest["tz"]);
291 $result = $this->time_date->to_display_date($this->_dateOnly($datetest["dbdate"]), false);
293 $this->_dateOnly($datetest["display"]),
294 $this->_dateOnly($result),
295 "Broken conversion for '{$datetest["df"]}' with date '{$datetest["dbdate"]}' and TZ {$datetest["tz"]}");
300 * test conversion from DB date to local date with TZ handling
302 public function testToDisplayDateFormatsWithTz()
304 foreach($this->date_tests as $datetest) {
305 if(!isset($datetest["tf"])) {
308 $tf = $datetest["tf"];
310 $df = $datetest["df"]." ".$tf;
311 $this->_setPrefs($datetest["df"], $tf, $datetest["tz"]);
312 $result = $this->time_date->to_display_date($datetest["db"], true);
314 $this->_dateOnly($datetest["display"]),
315 $this->_dateOnly($result),
316 "Broken conversion for '{$datetest["df"]}' with date '{$datetest["dbdate"]}' and TZ {$datetest["tz"]}");
321 * test midnight formatting
323 public function testGetMidnight()
325 if(!is_callable(array($this->time_date, "get_default_midnight"))) {
326 $this->markTestSkipped("Method is no longer public");
329 array("tf" => "H:i", "time" => "00:00"),
330 array("tf" => "H:i:s", "time" => "00:00:00"),
331 array("tf" => "h:i", "time" => "12:00"),
332 array("tf" => "h:i:s", "time" => "12:00:00"),
333 array("tf" => "h`iA", "time" => "12`00AM"),
334 array("tf" => "h`i`sa", "time" => "12`00`00am"),
336 foreach($times as $timetest) {
337 $this->_setPrefs('', $timetest["tf"], "America/Los_Angeles");
338 $this->assertEquals($timetest["time"], $this->time_date->get_default_midnight(true),
339 "Bad midnight value for {$timetest["time"]} format {$timetest["tf"]}");
343 public function testSwapFormatsWithTheSameDateFormat()
345 $original_date = '2005-12-25';
346 $original_format = 'Y-m-d';
347 $new_format = $original_format;
348 $expected_new_date = $original_date;
350 $new_date = $this->time_date->swap_formats($original_date,
351 $original_format, $new_format);
353 $this->assertEquals($expected_new_date, $new_date);
356 public function testSwapFormatsFromMdyFormatToDmyFormat()
358 $original_date = '12-25-2005';
359 $original_format = 'm-d-Y';
360 $new_format = 'd-m-Y';
361 $expected_new_date = '25-12-2005';
363 $new_date = $this->time_date->swap_formats($original_date,
364 $original_format, $new_format);
366 $this->assertEquals($expected_new_date, $new_date,
367 "Convert from $original_format to $new_format failed.");
370 public function testSwapFormatsWithTheSameDatetimeFormat()
372 $original_date = '2005-12-25 12:55:35';
373 $original_format = 'Y-m-d H:i:s';
374 $new_format = $original_format;
375 $expected_new_date = $original_date;
377 $new_date = $this->time_date->swap_formats($original_date,
378 $original_format, $new_format);
380 $this->assertEquals($expected_new_date, $new_date,
381 'Same datetime format not returned.');
384 public function testSwapFormatsFromYmdhiFormatToYmdhisFormat()
386 $original_date = '2005-12-25 12:55';
387 $original_format = 'Y-m-d H:i';
388 $new_format = 'Y-m-d H:i:s';
389 $expected_new_date = '2005-12-25 12:55:00';
391 $new_date = $this->time_date->swap_formats($original_date,
392 $original_format, $new_format);
394 $this->assertEquals($expected_new_date, $new_date);
397 public function testSwapFormatsFromYmdhiFormatToYmdhiaFormat()
399 $original = '2005-12-25 13:55';
400 $original_format = 'Y-m-d H:i';
401 $new_format = 'Y-m-d h:ia';
402 $expected = '2005-12-25 01:55pm';
404 $new = $this->time_date->swap_formats($original,
405 $original_format, $new_format);
407 $this->assertEquals($expected, $new);
410 public function testAllDateFormatSwappingCombinations()
412 $orig_formats_and_dates = array(
413 'Y-m-d' => '2006-12-23',
414 'm-d-Y' => '12-23-2006',
415 'd-m-Y' => '23-12-2006',
416 'Y/m/d' => '2006/12/23',
417 'm/d/Y' => '12/23/2006',
418 'd/m/Y' => '23/12/2006');
420 $new_formats_and_dates = $orig_formats_and_dates;
422 foreach($orig_formats_and_dates as $orig_format => $orig_date)
424 foreach($new_formats_and_dates as $new_format => $expected_date)
426 $new_date = $this->time_date->swap_formats($orig_date,
427 $orig_format, $new_format);
429 $this->assertEquals($expected_date, $new_date,
430 "Convert from $orig_format to $new_format failed.");
432 if($expected_date != $new_date)
443 public function testSwapDatetimeFormatToDbFormat()
445 $date = '10-25-2007 12:00am';
446 $format = $this->time_date->get_date_time_format();
447 $db_format = $this->time_date->get_db_date_time_format();
450 $this->time_date->swap_formats(
453 $this->time_date->get_db_date_time_format()
455 '2007-10-25 00:00:00'
462 public function testTodbCanHandleDdmmyyyyFormats()
464 $old_pattern = $GLOBALS['current_user']->getPreference('datef');
465 $GLOBALS['current_user']->setPreference('datef','d-m-Y');
466 $db_date_pattern = '/2007-10-25 [0-9]{2}:[0-9]{2}:[0-9]{2}/';
469 $this->time_date->to_db('25-10-2007')
472 $this->_noUserCache();
473 $GLOBALS['current_user']->setPreference('datef','m-d-Y');
476 $this->time_date->to_db('10-25-2007')
478 $GLOBALS['current_user']->setPreference('datef',$old_pattern);
484 public function testTodbCanHandleMmddyyyyFormats()
486 $old_date = $GLOBALS['current_user']->getPreference('datef');
488 $GLOBALS['current_user']->setPreference('datef','m-d-Y');
489 $db_date_pattern = '/2007-10-25 [0-9]{2}:[0-9]{2}:[0-9]{2}/';
492 $this->time_date->to_db('10-25-2007')
495 $GLOBALS['current_user']->setPreference('datef',$old_date);
501 public function testTodbdateCanHandleDdmmyyyyFormats()
503 $old_date = $GLOBALS['current_user']->getPreference('datef');
505 $GLOBALS['current_user']->setPreference('datef','d-m-Y');
507 $this->time_date->to_db_date('25-10-2007'),
511 $GLOBALS['current_user']->setPreference('datef',$old_date);
517 public function testTodbdateCanHandleMmddyyyyFormats()
519 $old_date = $GLOBALS['current_user']->getPreference('datef');
520 $GLOBALS['current_user']->setPreference('datef','m-d-Y');
523 $this->time_date->to_db_date('10-25-2007')
526 $GLOBALS['current_user']->setPreference('datef',$old_date);
529 public function testConvertMmddyyyyFormatToYyyymmdd()
533 $this->time_date->swap_formats(
541 public function testGeneratingDefaultMidnight()
543 if(!is_callable(array($this->time_date, "get_default_midnight"))) {
544 $this->markTestSkipped("Method is no longer public");
546 $old_time = $GLOBALS['current_user']->getPreference('timef');
548 $GLOBALS['current_user']->setPreference('timef','H:i:s');
551 $this->time_date->get_default_midnight(true)
554 $GLOBALS['current_user']->setPreference('timef','h:ia');
557 $this->time_date->get_default_midnight(true)
560 $GLOBALS['current_user']->setPreference('timef',$old_time);
563 public function providerGetDateFromRules()
566 array('2009',10,1,0,7200,"2009-10-04 02:00:00"),
567 array('2009',4,1,0,7200,"2009-04-05 02:00:00"),
568 array('2010',3,24,5,7200,"2010-03-26 02:00:00"),
569 array('2010',9,12,0,7200,"2010-09-12 02:00:00"),
574 * @dataProvider providerGetDateFromRules
576 public function testGetDateFromRules(
585 if(!is_callable(array($this->time_date, "getDateFromRules"))) {
586 $this->markTestSkipped("Method is no longer public");
589 $this->time_date->getDateFromRules($year, $startMonth, $startDate, $weekday, $startTime),
595 * tests for check_matching_format
597 public function testCheckMatchingFormats()
599 foreach($this->date_tests as $datetest) {
600 if(isset($datetest["tf"])) {
601 $df = $this->time_date->merge_date_time($df = $datetest["df"], $datetest["tf"]);
603 $df = $datetest["df"];
605 $this->assertTrue($this->time_date->check_matching_format($datetest["display"], $df),
606 "Broken match for '$df' with date '{$datetest["display"]}'");
609 // Some bad dates not detected by current code, it's too lenient
611 array("format" => "Y-m-d", "date" => ""),
612 array("format" => "Y-m-d", "date" => "blah-blah-blah"),
613 array("format" => "Y-m-d", "date" => "1-2"),
614 array("format" => "Y-m-d", "date" => "2007-10"),
615 //FIXME: array("format" => "Y-m-d", "date" => "200-10-25"),
616 array("format" => "Y-m-d", "date" => "2007-101-25"),
617 array("format" => "Y-m-d", "date" => "2007-Oct-25"),
618 //FIXME: array("format" => "Y-m-d", "date" => "2007-10-250"),
619 array("format" => "d-m-Y", "date" => "2007-10-25"),
620 array("format" => "d-m-Y", "date" => "10/25/2007"),
621 //FIXME: array("format" => "Y-m-d", "date" => "here: 2007-20-25"),
622 //FIXME: array("format" => "Y-m-d", "date" => "2007-20-25 here"),
624 foreach($badtests as $datetest) {
625 $this->assertFalse($this->time_date->check_matching_format($datetest["date"], $datetest["format"]),
626 "Broken match for '{$datetest["format"]}' with date '{$datetest["date"]}'");
631 * test fetching user settings
633 public function testGetUserSettings()
635 $this->_setPrefs('d/m/Y', 'h:i:sA', "America/Lima");
636 $this->assertEquals('dd/mm/yyyy', $this->time_date->get_user_date_format());
637 //FIXME: $this->assertEquals('11:00:00PM', $this->time_date->get_user_time_format());
638 $tz = $this->time_date->getUserTimeZone();
639 $this->assertEquals(-300, $tz["gmtOffset"]);
640 // $this->assertEquals(60, $tz["dstOffset"]);
644 * test getting GMT dates
646 public function testGetGMT()
648 $gmt = $this->time_date->get_gmt_db_datetime();
649 $dt = strptime($gmt, "%Y-%m-%d %H:%M:%S");
650 $this->assertEquals($dt['tm_year']+1900, gmdate("Y"));
651 $this->assertEquals($dt['tm_mon']+1, gmdate("m"));
652 $this->assertEquals($dt['tm_mday'], gmdate("d"));
654 $gmt = $this->time_date->get_gmt_db_date();
655 $dt = strptime($gmt, "%Y-%m-%d");
656 $this->assertEquals($dt['tm_year']+1900, gmdate("Y"));
657 $this->assertEquals($dt['tm_mon']+1, gmdate("m"));
658 $this->assertEquals($dt['tm_mday'], gmdate("d"));
662 * test getting DB date formats indifferent ways
664 public function testGetDB()
666 $this->assertEquals(gmdate($this->time_date->merge_date_time($this->time_date->get_db_date_format(),
667 $this->time_date->get_db_time_format())),
668 $this->time_date->get_gmt_db_datetime());
671 public function testGetCalFormats()
674 array("df" => "Y-m-d", "caldf" => "%Y-%m-%d", "tf" => "H:i:s", "caltf" => "%H:%M:%S"),
675 array("df" => "d/m/Y", "caldf" => "%d/%m/%Y", "tf" => "h:i:sa", "caltf" => "%I:%M:%S%P"),
676 array("df" => "m/d/Y", "caldf" => "%m/%d/%Y", "tf" => "H:i", "caltf" => "%H:%M"),
677 array("df" => "Y-m-d", "caldf" => "%Y-%m-%d", "tf" => "h:iA", "caltf" => "%I:%M%p"),
679 foreach($cal_tests as $datetest) {
680 $this->_setPrefs($datetest["df"], $datetest["tf"], "America/Los_Angeles");
683 $this->time_date->get_cal_date_format(),
684 "Bad cal date format for '{$datetest["df"]}'");
687 $this->time_date->get_cal_time_format(),
688 "Bad cal time format for '{$datetest["tf"]}'");
690 $this->time_date->merge_date_time($datetest["caldf"], $datetest["caltf"]),
691 $this->time_date->get_cal_date_time_format(),
692 "Bad cal datetime format for '{$datetest["df"]} {$datetest["tf"]}'");
697 * test for handleOffsetMax
699 public function testDayMinMax()
702 array("date" => "2010-05-19", "start" => "2010-05-19 07:00:00", "end" => "2010-05-20 06:59:59", 'tz' => 'America/Los_Angeles'),
703 array("date" => "2010-01-19", "start" => "2010-01-19 08:00:00", "end" => "2010-01-20 07:59:59", 'tz' => 'America/Los_Angeles'),
704 array("date" => "2010-05-19", "start" => "2010-05-18 23:00:00", "end" => "2010-05-19 22:59:59", 'tz' => 'Europe/London'),
705 array("date" => "2010-01-19", "start" => "2010-01-19 00:00:00", "end" => "2010-01-19 23:59:59", 'tz' => 'Europe/London'),
706 array("date" => "2010-05-19", "start" => "2010-05-18 22:00:00", "end" => "2010-05-19 21:59:59", 'tz' => 'Europe/Oslo'),
708 foreach($day_tests as $datetest) {
709 $this->_setPrefs('', '', $datetest["tz"]);
710 $dates = $this->time_date->handleOffsetMax($datetest["date"], '');
711 $this->assertEquals($datetest["start"], $dates["min"],
712 "Bad min result for {$datetest["date"]} tz {$datetest["tz"]}");
713 $this->assertEquals($datetest["end"], $dates["max"],
714 "Bad max result for {$datetest["date"]} tz {$datetest["tz"]}");
719 * test for getDayStartEndGMT
721 public function testGetDayStartEnd()
724 array("date" => "05/19/2010", "start" => "2010-05-19 07:00:00", "end" => "2010-05-20 06:59:59", 'tz' => 'America/Los_Angeles'),
725 array("date" => "01/19/2010", "start" => "2010-01-19 08:00:00", "end" => "2010-01-20 07:59:59", 'tz' => 'America/Los_Angeles'),
726 array("date" => "05/19/2010", "start" => "2010-05-18 23:00:00", "end" => "2010-05-19 22:59:59", 'tz' => 'Europe/London'),
727 array("date" => "01/19/2010", "start" => "2010-01-19 00:00:00", "end" => "2010-01-19 23:59:59", 'tz' => 'Europe/London'),
728 array("date" => "05/19/2010", "start" => "2010-05-18 22:00:00", "end" => "2010-05-19 21:59:59", 'tz' => 'Europe/Oslo'),
730 foreach($day_tests as $datetest) {
731 $this->_setPrefs('m/d/Y', '', $datetest["tz"]);
732 $dates = $this->time_date->getDayStartEndGMT($datetest["date"], '');
733 $this->assertEquals($datetest["start"], $dates["start"],
734 "Bad min result for {$datetest["date"]} tz {$datetest["tz"]}");
735 $this->assertEquals($datetest["end"], $dates["end"],
736 "Bad max result for {$datetest["date"]} tz {$datetest["tz"]}");
741 * test for merge_time_meridiem
743 public function testMergeAmPm()
746 array("date" => "05:17:28", "mer" => "am", "tf" => "H:i:s", "display" => "05:17:28"),
747 array("date" => "05:17:28", "mer" => "am", "tf" => "h:i:sa", "display" => "05:17:28am"),
749 array("date" => "17:34", "mer" => "pm", "tf" => "H:i", "display" => "17:34"),
750 array("date" => "11:42", "mer" => "PM", "tf" => "h:iA", "display" => "11:42PM"),
751 array("date" => "11:42", "mer" => "pm", "tf" => "h:iA", "display" => "11:42pm"),
752 array("date" => "03", "mer" => "AM", "tf" => "ha", "display" => "03AM"),
753 array("date" => "15", "mer" => "AM", "tf" => "H", "display" => "15"),
755 foreach($ampm_tests as $datetest) {
756 $amdate = $this->time_date->merge_time_meridiem($datetest["date"], $datetest["tf"], $datetest["mer"]);
757 $this->assertEquals($datetest["display"], $amdate,
758 "Bad min result for {$datetest["date"]} format {$datetest["tf"]}");
762 public function providerSplitDateTime()
765 array("2009-10-04 02:00:00","2009-10-04","02:00:00"),
766 array("10/04/2010 2:00pm","10/04/2010","2:00pm"),
767 array("10-04-2010 2:00","10-04-2010","2:00"),
772 * @dataProvider providerSplitDateTime
774 public function testSplitDateTime(
780 $this->assertEquals($date,$this->time_date->getDatePart($datetime));
781 $this->assertEquals($time,$this->time_date->getTimePart($datetime));