PageRenderTime 57ms CodeModel.GetById 14ms app.highlight 36ms RepoModel.GetById 1ms app.codeStats 0ms

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

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