PageRenderTime 75ms CodeModel.GetById 43ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/tests/cases/libs/view/helpers/time.test.php

https://github.com/Forbin/cakephp2x
PHP | 654 lines | 389 code | 87 blank | 178 comment | 22 complexity | b64d9cdd744b2a1a2a4be0f1f7ef11b2 MD5 | raw file
  1<?php
  2/**
  3 * TimeHelperTest file
  4 *
  5 * PHP Version 5.x
  6 *
  7 * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  8 * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9 *
 10 * Licensed under The Open Group Test Suite License
 11 * Redistributions of files must retain the above copyright notice.
 12 *
 13 * @copyright     Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
 14 * @link          https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
 15 * @package       cake
 16 * @subpackage    cake.tests.cases.libs.view.helpers
 17 * @since         CakePHP(tm) v 1.2.0.4206
 18 * @license       http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
 19 */
 20if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
 21	define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
 22}
 23App::import('Helper', 'Time');
 24
 25/**
 26 * TimeHelperTest class
 27 *
 28 * @package       cake
 29 * @subpackage    cake.tests.cases.libs.view.helpers
 30 */
 31class TimeHelperTest extends CakeTestCase {
 32
 33/**
 34 * setUp method
 35 *
 36 * @access public
 37 * @return void
 38 */
 39	function setUp() {
 40		$this->Time = new TimeHelper();
 41	}
 42
 43/**
 44 * tearDown method
 45 *
 46 * @access public
 47 * @return void
 48 */
 49	function tearDown() {
 50		unset($this->Time);
 51	}
 52
 53/**
 54 * testToQuarter method
 55 *
 56 * @access public
 57 * @return void
 58 */
 59	function testToQuarter() {
 60		$result = $this->Time->toQuarter('2007-12-25');
 61		$this->assertEqual($result, 4);
 62
 63		$result = $this->Time->toQuarter('2007-9-25');
 64		$this->assertEqual($result, 3);
 65
 66		$result = $this->Time->toQuarter('2007-3-25');
 67		$this->assertEqual($result, 1);
 68
 69		$result = $this->Time->toQuarter('2007-3-25', true);
 70		$this->assertEqual($result, array('2007-01-01', '2007-03-31'));
 71
 72		$result = $this->Time->toQuarter('2007-5-25', true);
 73		$this->assertEqual($result, array('2007-04-01', '2007-06-30'));
 74
 75		$result = $this->Time->toQuarter('2007-8-25', true);
 76		$this->assertEqual($result, array('2007-07-01', '2007-09-30'));
 77
 78		$result = $this->Time->toQuarter('2007-12-25', true);
 79		$this->assertEqual($result, array('2007-10-01', '2007-12-31'));
 80	}
 81
 82/**
 83 * testTimeAgoInWords method
 84 *
 85 * @access public
 86 * @return void
 87 */
 88	function testTimeAgoInWords() {
 89		$result = $this->Time->timeAgoInWords(strtotime('4 months, 2 weeks, 3 days'), array('end' => '8 years'), true);
 90		$this->assertEqual($result, '4 months, 2 weeks, 3 days');
 91
 92		$result = $this->Time->timeAgoInWords(strtotime('4 months, 2 weeks, 2 days'), array('end' => '8 years'), true);
 93		$this->assertEqual($result, '4 months, 2 weeks, 2 days');
 94
 95		$result = $this->Time->timeAgoInWords(strtotime('4 months, 2 weeks, 1 day'), array('end' => '8 years'), true);
 96		$this->assertEqual($result, '4 months, 2 weeks, 1 day');
 97
 98		$result = $this->Time->timeAgoInWords(strtotime('3 months, 2 weeks, 1 day'), array('end' => '8 years'), true);
 99		$this->assertEqual($result, '3 months, 2 weeks, 1 day');
100
101		$result = $this->Time->timeAgoInWords(strtotime('3 months, 2 weeks'), array('end' => '8 years'), true);
102		$this->assertEqual($result, '3 months, 2 weeks');
103
104		$result = $this->Time->timeAgoInWords(strtotime('3 months, 1 week, 6 days'), array('end' => '8 years'), true);
105		$this->assertEqual($result, '3 months, 1 week, 6 days');
106
107		$result = $this->Time->timeAgoInWords(strtotime('2 months, 2 weeks, 1 day'), array('end' => '8 years'), true);
108		$this->assertEqual($result, '2 months, 2 weeks, 1 day');
109
110		$result = $this->Time->timeAgoInWords(strtotime('2 months, 2 weeks'), array('end' => '8 years'), true);
111		$this->assertEqual($result, '2 months, 2 weeks');
112
113		$result = $this->Time->timeAgoInWords(strtotime('2 months, 1 week, 6 days'), array('end' => '8 years'), true);
114		$this->assertEqual($result, '2 months, 1 week, 6 days');
115
116		$result = $this->Time->timeAgoInWords(strtotime('1 month, 1 week, 6 days'), array('end' => '8 years'), true);
117		$this->assertEqual($result, '1 month, 1 week, 6 days');
118
119		for($i = 0; $i < 200; $i ++) {
120			$years = mt_rand(0, 3);
121			$months = mt_rand(0, 11);
122			$weeks = mt_rand(0, 3);
123			$days = mt_rand(0, 6);
124			$hours = 0;
125			$minutes = 0;
126			$seconds = 0;
127			$relative_date = '';
128
129			if ($years > 0) {
130				// years and months and days
131				$relative_date .= ($relative_date ? ', -' : '-') . $years . ' year' . ($years > 1 ? 's' : '');
132				$relative_date .= $months > 0 ? ($relative_date ? ', -' : '-') . $months . ' month' . ($months > 1 ? 's' : '') : '';
133				$relative_date .= $weeks > 0 ? ($relative_date ? ', -' : '-') . $weeks . ' week' . ($weeks > 1 ? 's' : '') : '';
134				$relative_date .= $days > 0 ? ($relative_date ? ', -' : '-') . $days . ' day' . ($days > 1 ? 's' : '') : '';
135			} elseif (abs($months) > 0) {
136				// months, weeks and days
137				$relative_date .= ($relative_date ? ', -' : '-') . $months . ' month' . ($months > 1 ? 's' : '');
138				$relative_date .= $weeks > 0 ? ($relative_date ? ', -' : '-') . $weeks . ' week' . ($weeks > 1 ? 's' : '') : '';
139				$relative_date .= $days > 0 ? ($relative_date ? ', -' : '-') . $days . ' day' . ($days > 1 ? 's' : '') : '';
140			} elseif (abs($weeks) > 0) {
141				// weeks and days
142				$relative_date .= ($relative_date ? ', -' : '-') . $weeks . ' week' . ($weeks > 1 ? 's' : '');
143				$relative_date .= $days > 0 ? ($relative_date ? ', -' : '-') . $days . ' day' . ($days > 1 ? 's' : '') : '';
144			} elseif (abs($days) > 0) {
145				// days and hours
146				$relative_date .= ($relative_date ? ', -' : '-') . $days . ' day' . ($days > 1 ? 's' : '');
147				$relative_date .= $hours > 0 ? ($relative_date ? ', -' : '-') . $hours . ' hour' . ($hours > 1 ? 's' : '') : '';
148			} elseif (abs($hours) > 0) {
149				// hours and minutes
150				$relative_date .= ($relative_date ? ', -' : '-') . $hours . ' hour' . ($hours > 1 ? 's' : '');
151				$relative_date .= $minutes > 0 ? ($relative_date ? ', -' : '-') . $minutes . ' minute' . ($minutes > 1 ? 's' : '') : '';
152			} elseif (abs($minutes) > 0) {
153				// minutes only
154				$relative_date .= ($relative_date ? ', -' : '-') . $minutes . ' minute' . ($minutes > 1 ? 's' : '');
155			} else {
156				// seconds only
157				$relative_date .= ($relative_date ? ', -' : '-') . $seconds . ' second' . ($seconds != 1 ? 's' : '');
158			}
159
160			if (date('j/n/y', strtotime($relative_date)) != '1/1/70') {
161				$result = $this->Time->timeAgoInWords(strtotime($relative_date), array('end' => '8 years'), true);
162				if ($relative_date == '0 seconds') {
163					$relative_date = '0 seconds ago';
164				}
165
166				$relative_date = str_replace('-', '', $relative_date) . ' ago';
167				$this->assertEqual($result, $relative_date);
168
169			}
170		}
171
172		for ($i = 0; $i < 200; $i ++) {
173			$years = mt_rand(0, 3);
174			$months = mt_rand(0, 11);
175			$weeks = mt_rand(0, 3);
176			$days = mt_rand(0, 6);
177			$hours = 0;
178			$minutes = 0;
179			$seconds = 0;
180
181			$relative_date = '';
182
183			if ($years > 0) {
184				// years and months and days
185				$relative_date .= ($relative_date ? ', ' : '') . $years . ' year' . ($years > 1 ? 's' : '');
186				$relative_date .= $months > 0 ? ($relative_date ? ', ' : '') . $months . ' month' . ($months > 1 ? 's' : '') : '';
187				$relative_date .= $weeks > 0 ? ($relative_date ? ', ' : '') . $weeks . ' week' . ($weeks > 1 ? 's' : '') : '';
188				$relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '') : '';
189			} elseif (abs($months) > 0) {
190				// months, weeks and days
191				$relative_date .= ($relative_date ? ', ' : '') . $months . ' month' . ($months > 1 ? 's' : '');
192				$relative_date .= $weeks > 0 ? ($relative_date ? ', ' : '') . $weeks . ' week' . ($weeks > 1 ? 's' : '') : '';
193				$relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '') : '';
194			} elseif (abs($weeks) > 0) {
195				// weeks and days
196				$relative_date .= ($relative_date ? ', ' : '') . $weeks . ' week' . ($weeks > 1 ? 's' : '');
197				$relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '') : '';
198			} elseif (abs($days) > 0) {
199				// days and hours
200				$relative_date .= ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '');
201				$relative_date .= $hours > 0 ? ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : '') : '';
202			} elseif (abs($hours) > 0) {
203				// hours and minutes
204				$relative_date .= ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : '');
205				$relative_date .= $minutes > 0 ? ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : '') : '';
206			} elseif (abs($minutes) > 0) {
207				// minutes only
208				$relative_date .= ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : '');
209			} else {
210				// seconds only
211				$relative_date .= ($relative_date ? ', ' : '') . $seconds . ' second' . ($seconds != 1 ? 's' : '');
212			}
213
214			if (date('j/n/y', strtotime($relative_date)) != '1/1/70') {
215				// echo $relative_date."<br />";
216				$result = $this->Time->timeAgoInWords(strtotime($relative_date), array('end' => '8 years'), true);
217				if ($relative_date == '0 seconds') {
218					$relative_date = '0 seconds ago';
219				}
220
221				$relative_date = str_replace('-', '', $relative_date) . '';
222				$this->assertEqual($result, $relative_date);
223			}
224		}
225
226		$result = $this->Time->timeAgoInWords(strtotime('-2 years, -5 months, -2 days'), array('end' => '3 years'), true);
227		$this->assertEqual($result, '2 years, 5 months, 2 days ago');
228
229		$result = $this->Time->timeAgoInWords('2007-9-25');
230		$this->assertEqual($result, 'on 25/9/07');
231
232		$result = $this->Time->timeAgoInWords('2007-9-25', 'Y-m-d');
233		$this->assertEqual($result, 'on 2007-09-25');
234
235		$result = $this->Time->timeAgoInWords('2007-9-25', 'Y-m-d', true);
236		$this->assertEqual($result, 'on 2007-09-25');
237
238		$result = $this->Time->timeAgoInWords(strtotime('-2 weeks, -2 days'), 'Y-m-d', false);
239		$this->assertEqual($result, '2 weeks, 2 days ago');
240
241		$result = $this->Time->timeAgoInWords(strtotime('2 weeks, 2 days'), 'Y-m-d', true);
242		$this->assertPattern('/^2 weeks, [1|2] day(s)?$/', $result);
243
244		$result = $this->Time->timeAgoInWords(strtotime('2 months, 2 days'), array('end' => '1 month'));
245		$this->assertEqual($result, 'on ' . date('j/n/y', strtotime('2 months, 2 days')));
246
247		$result = $this->Time->timeAgoInWords(strtotime('2 months, 2 days'), array('end' => '3 month'));
248		$this->assertPattern('/2 months/', $result);
249
250		$result = $this->Time->timeAgoInWords(strtotime('2 months, 12 days'), array('end' => '3 month'));
251		$this->assertPattern('/2 months, 1 week/', $result);
252
253		$result = $this->Time->timeAgoInWords(strtotime('3 months, 5 days'), array('end' => '4 month'));
254		$this->assertEqual($result, '3 months, 5 days');
255
256		$result = $this->Time->timeAgoInWords(strtotime('-2 months, -2 days'), array('end' => '3 month'));
257		$this->assertEqual($result, '2 months, 2 days ago');
258
259		$result = $this->Time->timeAgoInWords(strtotime('-2 months, -2 days'), array('end' => '3 month'));
260		$this->assertEqual($result, '2 months, 2 days ago');
261
262		$result = $this->Time->timeAgoInWords(strtotime('2 months, 2 days'), array('end' => '3 month'));
263		$this->assertPattern('/2 months/', $result);
264
265		$result = $this->Time->timeAgoInWords(strtotime('2 months, 2 days'), array('end' => '1 month', 'format' => 'Y-m-d'));
266		$this->assertEqual($result, 'on ' . date('Y-m-d', strtotime('2 months, 2 days')));
267
268		$result = $this->Time->timeAgoInWords(strtotime('-2 months, -2 days'), array('end' => '1 month', 'format' => 'Y-m-d'));
269		$this->assertEqual($result, 'on ' . date('Y-m-d', strtotime('-2 months, -2 days')));
270
271		$result = $this->Time->timeAgoInWords(strtotime('-13 months, -5 days'), array('end' => '2 years'));
272		$this->assertEqual($result, '1 year, 1 month, 5 days ago');
273
274		$fourHours = $this->Time->timeAgoInWords(strtotime('-5 days, -2 hours'), array('userOffset' => -4));
275		$result = $this->Time->timeAgoInWords(strtotime('-5 days, -2 hours'), array('userOffset' => 4));
276		$this->assertEqual($fourHours, $result);
277
278		$result = $this->Time->timeAgoInWords(strtotime('-2 hours'));
279		$expected = '2 hours ago';
280		$this->assertEqual($expected, $result);
281
282		$result = $this->Time->timeAgoInWords(strtotime('-12 minutes'));
283		$expected = '12 minutes ago';
284		$this->assertEqual($expected, $result);
285
286		$result = $this->Time->timeAgoInWords(strtotime('-12 seconds'));
287		$expected = '12 seconds ago';
288		$this->assertEqual($expected, $result);
289
290		$time = strtotime('-3 years -12 months');
291		$result = $this->Time->timeAgoInWords($time);
292		$expected = 'on ' . date('j/n/y', $time);
293		$this->assertEqual($expected, $result);
294	}
295
296/**
297 * testRelative method
298 *
299 * @access public
300 * @return void
301 */
302	function testRelative() {
303		$result = $this->Time->relativeTime('-1 week');
304		$this->assertEqual($result, '1 week ago');
305		$result = $this->Time->relativeTime('+1 week');
306		$this->assertEqual($result, '1 week');
307	}
308
309/**
310 * testNice method
311 *
312 * @access public
313 * @return void
314 */
315	function testNice() {
316		$time = time() + 2 * DAY;
317		$this->assertEqual(date('D, M jS Y, H:i', $time), $this->Time->nice($time));
318
319		$time = time() - 2 * DAY;
320		$this->assertEqual(date('D, M jS Y, H:i', $time), $this->Time->nice($time));
321
322		$time = time();
323		$this->assertEqual(date('D, M jS Y, H:i', $time), $this->Time->nice($time));
324
325		$time = 0;
326		$this->assertEqual(date('D, M jS Y, H:i', time()), $this->Time->nice($time));
327
328		$time = null;
329		$this->assertEqual(date('D, M jS Y, H:i', time()), $this->Time->nice($time));
330	}
331
332/**
333 * testNiceShort method
334 *
335 * @access public
336 * @return void
337 */
338	function testNiceShort() {
339		$time = time() + 2 * DAY;
340		if (date('Y', $time) == date('Y')) {
341			$this->assertEqual(date('M jS, H:i', $time), $this->Time->niceShort($time));
342		} else {
343			$this->assertEqual(date('M jSY, H:i', $time), $this->Time->niceShort($time));
344		}
345
346		$time = time();
347		$this->assertEqual('Today, '.date('H:i', $time), $this->Time->niceShort($time));
348
349		$time = time() - DAY;
350		$this->assertEqual('Yesterday, '.date('H:i', $time), $this->Time->niceShort($time));
351	}
352
353/**
354 * testDaysAsSql method
355 *
356 * @access public
357 * @return void
358 */
359	function testDaysAsSql() {
360		$begin = time();
361		$end = time() + DAY;
362		$field = 'my_field';
363		$expected = '(my_field >= \''.date('Y-m-d', $begin).' 00:00:00\') AND (my_field <= \''.date('Y-m-d', $end).' 23:59:59\')';
364		$this->assertEqual($expected, $this->Time->daysAsSql($begin, $end, $field));
365	}
366
367/**
368 * testDayAsSql method
369 *
370 * @access public
371 * @return void
372 */
373	function testDayAsSql() {
374		$time = time();
375		$field = 'my_field';
376		$expected = '(my_field >= \''.date('Y-m-d', $time).' 00:00:00\') AND (my_field <= \''.date('Y-m-d', $time).' 23:59:59\')';
377		$this->assertEqual($expected, $this->Time->dayAsSql($time, $field));
378	}
379
380/**
381 * testToUnix method
382 *
383 * @access public
384 * @return void
385 */
386	function testToUnix() {
387		$this->assertEqual(time(), $this->Time->toUnix(time()));
388		$this->assertEqual(strtotime('+1 day'), $this->Time->toUnix('+1 day'));
389		$this->assertEqual(strtotime('+0 days'), $this->Time->toUnix('+0 days'));
390		$this->assertEqual(strtotime('-1 days'), $this->Time->toUnix('-1 days'));
391		$this->assertEqual(false, $this->Time->toUnix(''));
392		$this->assertEqual(false, $this->Time->toUnix(null));
393	}
394
395/**
396 * testToAtom method
397 *
398 * @access public
399 * @return void
400 */
401	function testToAtom() {
402		$this->assertEqual(date('Y-m-d\TH:i:s\Z'), $this->Time->toAtom(time()));
403	}
404
405/**
406 * testToRss method
407 *
408 * @access public
409 * @return void
410 */
411	function testToRss() {
412		$this->assertEqual(date('r'), $this->Time->toRss(time()));
413	}
414
415/**
416 * testFormat method
417 *
418 * @access public
419 * @return void
420 */
421	function testFormat() {
422		$format = 'D-M-Y';
423		$arr = array(time(), strtotime('+1 days'), strtotime('+1 days'), strtotime('+0 days'));
424		foreach ($arr as $val) {
425			$this->assertEqual(date($format, $val), $this->Time->format($format, $val));
426		}
427
428		$result = $this->Time->format('Y-m-d', null, 'never');
429		$this->assertEqual($result, 'never');
430	}
431
432/**
433 * testOfGmt method
434 *
435 * @access public
436 * @return void
437 */
438	function testGmt() {
439		$hour = 3;
440		$min = 4;
441		$sec = 2;
442		$month = 5;
443		$day = 14;
444		$year = 2007;
445		$time = mktime($hour, $min, $sec, $month, $day, $year);
446		$expected = gmmktime($hour, $min, $sec, $month, $day, $year);
447		$this->assertEqual($expected, $this->Time->gmt(date('Y-n-j G:i:s', $time)));
448
449		$hour = date('H');
450		$min = date('i');
451		$sec = date('s');
452		$month = date('m');
453		$day = date('d');
454		$year = date('Y');
455		$expected = gmmktime($hour, $min, $sec, $month, $day, $year);
456		$this->assertEqual($expected, $this->Time->gmt(null));
457	}
458
459/**
460 * testIsToday method
461 *
462 * @access public
463 * @return void
464 */
465	function testIsToday() {
466		$result = $this->Time->isToday('+1 day');
467		$this->assertFalse($result);
468		$result = $this->Time->isToday('+1 days');
469		$this->assertFalse($result);
470		$result = $this->Time->isToday('+0 day');
471		$this->assertTrue($result);
472		$result = $this->Time->isToday('-1 day');
473		$this->assertFalse($result);
474	}
475
476/**
477 * testIsThisWeek method
478 *
479 * @access public
480 * @return void
481 */
482	function testIsThisWeek() {
483		// A map of days which goes from -1 day of week to +1 day of week
484		$map = array(
485			'Mon' => array(-1, 7), 'Tue' => array(-2, 6), 'Wed' => array(-3, 5),
486			'Thu' => array(-4, 4), 'Fri' => array(-5, 3), 'Sat' => array(-6, 2),
487			'Sun' => array(-7, 1)
488		);
489		$days = $map[date('D')];
490
491		for ($day = $days[0] + 1; $day < $days[1]; $day++) {
492			$this->assertTrue($this->Time->isThisWeek(($day > 0 ? '+' : '') . $day . ' days'));
493		}
494		$this->assertFalse($this->Time->isThisWeek($days[0] . ' days'));
495		$this->assertFalse($this->Time->isThisWeek('+' . $days[1] . ' days'));
496	}
497
498/**
499 * testIsThisMonth method
500 *
501 * @access public
502 * @return void
503 */
504	function testIsThisMonth() {
505		$result = $this->Time->isThisMonth('+0 day');
506		$this->assertTrue($result);
507		$result = $this->Time->isThisMonth($time = mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y')));
508		$this->assertTrue($result);
509		$result = $this->Time->isThisMonth(mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y') - mt_rand(1, 12)));
510		$this->assertFalse($result);
511		$result = $this->Time->isThisMonth(mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y') + mt_rand(1, 12)));
512		$this->assertFalse($result);
513
514	}
515
516/**
517 * testIsThisYear method
518 *
519 * @access public
520 * @return void
521 */
522	function testIsThisYear() {
523		$result = $this->Time->isThisYear('+0 day');
524		$this->assertTrue($result);
525		$result = $this->Time->isThisYear(mktime(0, 0, 0, mt_rand(1, 12), mt_rand(1, 28), date('Y')));
526		$this->assertTrue($result);
527	}
528	/**
529 * testWasYesterday method
530 *
531 * @access public
532 * @return void
533 */
534	function testWasYesterday() {
535		$result = $this->Time->wasYesterday('+1 day');
536		$this->assertFalse($result);
537		$result = $this->Time->wasYesterday('+1 days');
538		$this->assertFalse($result);
539		$result = $this->Time->wasYesterday('+0 day');
540		$this->assertFalse($result);
541		$result = $this->Time->wasYesterday('-1 day');
542		$this->assertTrue($result);
543		$result = $this->Time->wasYesterday('-1 days');
544		$this->assertTrue($result);
545		$result = $this->Time->wasYesterday('-2 days');
546		$this->assertFalse($result);
547	}
548	/**
549 * testIsTomorrow method
550 *
551 * @access public
552 * @return void
553 */
554	function testIsTomorrow() {
555		$result = $this->Time->isTomorrow('+1 day');
556		$this->assertTrue($result);
557		$result = $this->Time->isTomorrow('+1 days');
558		$this->assertTrue($result);
559		$result = $this->Time->isTomorrow('+0 day');
560		$this->assertFalse($result);
561		$result = $this->Time->isTomorrow('-1 day');
562		$this->assertFalse($result);
563	}
564
565/**
566 * testWasWithinLast method
567 *
568 * @access public
569 * @return void
570 */
571	function testWasWithinLast() {
572		$this->assertTrue($this->Time->wasWithinLast('1 day', '-1 day'));
573		$this->assertTrue($this->Time->wasWithinLast('1 week', '-1 week'));
574		$this->assertTrue($this->Time->wasWithinLast('1 year', '-1 year'));
575		$this->assertTrue($this->Time->wasWithinLast('1 second', '-1 second'));
576		$this->assertTrue($this->Time->wasWithinLast('1 minute', '-1 minute'));
577		$this->assertTrue($this->Time->wasWithinLast('1 year', '-1 year'));
578		$this->assertTrue($this->Time->wasWithinLast('1 month', '-1 month'));
579		$this->assertTrue($this->Time->wasWithinLast('1 day', '-1 day'));
580
581		$this->assertTrue($this->Time->wasWithinLast('1 week', '-1 day'));
582		$this->assertTrue($this->Time->wasWithinLast('2 week', '-1 week'));
583		$this->assertFalse($this->Time->wasWithinLast('1 second', '-1 year'));
584		$this->assertTrue($this->Time->wasWithinLast('10 minutes', '-1 second'));
585		$this->assertTrue($this->Time->wasWithinLast('23 minutes', '-1 minute'));
586		$this->assertFalse($this->Time->wasWithinLast('0 year', '-1 year'));
587		$this->assertTrue($this->Time->wasWithinLast('13 month', '-1 month'));
588		$this->assertTrue($this->Time->wasWithinLast('2 days', '-1 day'));
589
590		$this->assertFalse($this->Time->wasWithinLast('1 week', '-2 weeks'));
591		$this->assertFalse($this->Time->wasWithinLast('1 second', '-2 seconds'));
592		$this->assertFalse($this->Time->wasWithinLast('1 day', '-2 days'));
593		$this->assertFalse($this->Time->wasWithinLast('1 hour', '-2 hours'));
594		$this->assertFalse($this->Time->wasWithinLast('1 month', '-2 months'));
595		$this->assertFalse($this->Time->wasWithinLast('1 year', '-2 years'));
596
597		$this->assertFalse($this->Time->wasWithinLast('1 day', '-2 weeks'));
598		$this->assertFalse($this->Time->wasWithinLast('1 day', '-2 days'));
599		$this->assertFalse($this->Time->wasWithinLast('0 days', '-2 days'));
600		$this->assertTrue($this->Time->wasWithinLast('1 hour', '-20 seconds'));
601		$this->assertTrue($this->Time->wasWithinLast('1 year', '-60 minutes -30 seconds'));
602		$this->assertTrue($this->Time->wasWithinLast('3 years', '-2 months'));
603		$this->assertTrue($this->Time->wasWithinLast('5 months', '-4 months'));
604
605		$this->assertTrue($this->Time->wasWithinLast('5 ', '-3 days'));
606		$this->assertTrue($this->Time->wasWithinLast('1   ', '-1 hour'));
607		$this->assertTrue($this->Time->wasWithinLast('1   ', '-1 minute'));
608		$this->assertTrue($this->Time->wasWithinLast('1   ', '-23 hours -59 minutes -59 seconds'));
609	}
610	/**
611 * testUserOffset method
612 *
613 * @access public
614 * @return void
615 */
616	function testUserOffset() {
617		if ($this->skipIf(!class_exists('DateTimeZone'), '%s DateTimeZone class not available.')) {
618			return;
619		}
620
621
622		$timezoneServer = new DateTimeZone(date_default_timezone_get());
623		$timeServer = new DateTime('now', $timezoneServer);
624		$yourTimezone = $timezoneServer->getOffset($timeServer) / HOUR;
625
626		$expected = time();
627		$result = $this->Time->fromString(time(), $yourTimezone);
628		$this->assertEqual($result, $expected);
629	}
630
631/**
632 * test fromString()
633 *
634 * @access public
635 * @return void
636 */
637	function testFromString() {
638		$result = $this->Time->fromString('');
639		$this->assertFalse($result);
640
641		$result = $this->Time->fromString(0, 0);
642		$this->assertFalse($result);
643
644		$result = $this->Time->fromString('+1 hour');
645		$expected = strtotime('+1 hour');
646		$this->assertEqual($result, $expected);
647
648		$timezone = date('Z', time());
649		$result = $this->Time->fromString('+1 hour', $timezone);
650		$expected = $this->Time->convert(strtotime('+1 hour'), $timezone);
651		$this->assertEqual($result, $expected);
652	}
653}
654?>