TimeLibTest.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <?php
  2. App::uses('TimeLib', 'Tools.Utility');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. class TimeLibTest extends MyCakeTestCase {
  5. public $Time = null;
  6. public function testObject() {
  7. $this->Time = new TimeLib();
  8. $this->assertTrue(is_object($this->Time));
  9. $this->assertTrue(is_a($this->Time, 'TimeLib'));
  10. }
  11. public function testNiceDate() {
  12. $res = setlocale(LC_TIME, 'de_DE.UTF-8', 'deu_deu');
  13. //debug($res);
  14. $values = array(
  15. array('2009-12-01 00:00:00', FORMAT_NICE_YMD, '01.12.2009'),
  16. array('2009-12-01 00:00:00', FORMAT_NICE_M_FULL, 'December'),
  17. );
  18. foreach ($values as $v) {
  19. $ret = TimeLib::niceDate($v[0], $v[1]);
  20. //pr($ret);
  21. $this->assertEquals($ret, $v[2]);
  22. }
  23. }
  24. public function testLocalDate() {
  25. $res = setlocale(LC_TIME, array('de_DE.UTF-8', 'deu_deu'));
  26. //debug($res);
  27. $values = array(
  28. array('2009-12-01 00:00:00', FORMAT_LOCAL_YMD, '01.12.2009'),
  29. array('2009-12-01 00:00:00', FORMAT_LOCAL_M_FULL, 'Dezember'),
  30. );
  31. foreach ($values as $v) {
  32. $ret = TimeLib::localDate($v[0], $v[1]);
  33. //pr($ret);
  34. $this->assertEquals($ret, $v[2]);
  35. }
  36. }
  37. public function testParseLocalizedDate() {
  38. $this->out($this->_header(__FUNCTION__));
  39. $ret = TimeLib::parseLocalizedDate('15-Feb-2009', 'j-M-Y', 'start');
  40. //pr($ret);
  41. $this->assertEquals($ret, '2009-02-15 00:00:00');
  42. # problem when not passing months or days as well - no way of knowing how exact the date was
  43. $ret = TimeLib::parseLocalizedDate('2009', 'Y', 'start');
  44. //pr($ret);
  45. //$this->assertEquals($ret, '2009-01-01 00:00:00');
  46. $ret = TimeLib::parseLocalizedDate('Feb 2009', 'M Y', 'start');
  47. //pr($ret);
  48. //$this->assertEquals($ret, '2009-02-01 00:00:00');
  49. $values = array(
  50. array(__('Today'), array(date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y'))), date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y'))))),
  51. array('2010', array('2010-01-01 00:00:00', '2010-12-31 23:59:59')),
  52. array('23.02.2011', array('2011-02-23 00:00:00', '2011-02-23 23:59:59')),
  53. array('22/02/2011', array('2011-02-22 00:00:00', '2011-02-22 23:59:59')),
  54. array('3/2/11', array('2011-02-03 00:00:00', '2011-02-03 23:59:59')),
  55. array('2/12/9', array('2009-12-02 00:00:00', '2009-12-02 23:59:59')),
  56. array('12/2009', array('2009-12-01 00:00:00', '2009-12-31 23:59:59')),
  57. );
  58. foreach ($values as $v) {
  59. $ret = TimeLib::parseLocalizedDate($v[0], null, 'start');
  60. //pr($ret);
  61. $this->assertEquals($ret, $v[1][0]);
  62. $ret = TimeLib::parseLocalizedDate($v[0], null, 'end');
  63. //pr($ret);
  64. $this->assertEquals($ret, $v[1][1]);
  65. }
  66. }
  67. public function testPeriod() {
  68. $this->out($this->_header(__FUNCTION__));
  69. $values = array(
  70. array(__('Today'), array(date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y'))), date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y'))))),
  71. array('2010', array('2010-01-01 00:00:00', '2010-12-31 23:59:59')),
  72. array('2011-02', array('2011-02-01 00:00:00', '2011-02-28 23:59:59')),
  73. array('2012-02', array('2012-02-01 00:00:00', '2012-02-29 23:59:59')),
  74. array('2010-02-23', array('2010-02-23 00:00:00', '2010-02-23 23:59:59')),
  75. array('2010-02-23 bis 2010-02-26', array('2010-02-23 00:00:00', '2010-02-26 23:59:59')),
  76. //array('2010-02-23 11:11:11 bis 2010-02-23 11:12:01', array('2010-02-23 11:11:11', '2010-02-23 11:12:01')),
  77. # localized
  78. array('23.02.2011', array('2011-02-23 00:00:00', '2011-02-23 23:59:59')),
  79. array('23.2.2010 bis 26.2.2011', array('2010-02-23 00:00:00', '2011-02-26 23:59:59')),
  80. );
  81. foreach ($values as $v) {
  82. $ret = TimeLib::period($v[0]);
  83. //pr($ret);
  84. $this->assertEquals($ret, $v[1]);
  85. }
  86. }
  87. public function testPeriodAsSql() {
  88. $this->out($this->_header(__FUNCTION__));
  89. $values = array(
  90. array(__('Today'), "(Model.field >= '".date(FORMAT_DB_DATE)." 00:00:00') AND (Model.field <= '".date(FORMAT_DB_DATE)." 23:59:59')"),
  91. array(__('Yesterday').' '.__('until').' '.__('Today'), "(Model.field >= '".date(FORMAT_DB_DATE, time()-DAY)." 00:00:00') AND (Model.field <= '".date(FORMAT_DB_DATE)." 23:59:59')"),
  92. array(__('Today').' '.__('until').' '.__('Tomorrow'), "(Model.field >= '".date(FORMAT_DB_DATE, time())." 00:00:00') AND (Model.field <= '".date(FORMAT_DB_DATE, time()+DAY)." 23:59:59')"),
  93. array(__('Yesterday').' '.__('until').' '.__('Tomorrow'), "(Model.field >= '".date(FORMAT_DB_DATE, time()-DAY)." 00:00:00') AND (Model.field <= '".date(FORMAT_DB_DATE, time()+DAY)." 23:59:59')"),
  94. );
  95. foreach ($values as $v) {
  96. $ret = TimeLib::periodAsSql($v[0], 'Model.field');
  97. //pr($v[1]);
  98. //pr($ret);
  99. $this->assertSame($v[1], $ret);
  100. }
  101. }
  102. public function testDifference() {
  103. $this->out($this->_header(__FUNCTION__));
  104. $values = array(
  105. array('2010-02-23 11:11:11', '2010-02-23 11:12:01', 50),
  106. array('2010-02-23 11:11:11', '2010-02-24 11:12:01', DAY+50)
  107. );
  108. foreach ($values as $v) {
  109. $ret = TimeLib::difference($v[0], $v[1]);
  110. $this->assertEquals($v[2], $ret);
  111. }
  112. }
  113. public function testAgeBounds() {
  114. $this->out($this->_header(__FUNCTION__));
  115. $values = array(
  116. array(20, 20, array('min'=>'1990-07-07', 'max'=>'1991-07-06')),
  117. array(10, 30, array('min'=>'1980-07-07', 'max'=>'2001-07-06')),
  118. array(11, 12, array('min'=>'1998-07-07', 'max'=>'2000-07-06'))
  119. );
  120. foreach ($values as $v) {
  121. //echo $v[0].'/'.$v[1];
  122. $ret = TimeLib::ageBounds($v[0], $v[1], true, '2011-07-06'); //TODO: relative time
  123. //pr($ret);
  124. if (isset($v[2])) {
  125. $this->assertSame($v[2], $ret);
  126. $this->assertEquals($v[0], TimeLib::age($v[2]['max'], '2011-07-06'));
  127. $this->assertEquals($v[1], TimeLib::age($v[2]['min'], '2011-07-06'));
  128. }
  129. }
  130. }
  131. public function testAgeByYear() {
  132. $this->out($this->_header(__FUNCTION__));
  133. # year only
  134. $is = TimeLib::ageByYear(2000);
  135. $this->out($is);
  136. $this->assertEquals($is, (date('Y')-2001).'/'.(date('Y')-2000));
  137. $is = TimeLib::ageByYear(1985);
  138. $this->assertEquals($is, (date('Y')-1986).'/'.(date('Y')-1985));
  139. # with month
  140. if (($month = date('n')+1) <= 12) {
  141. $is = TimeLib::ageByYear(2000, $month);
  142. $this->out($is);
  143. //$this->assertEquals($is, (date('Y')-2001).'/'.(date('Y')-2000), null, '2000/'.$month);
  144. $this->assertSame($is, (date('Y')-2001), null, '2000/'.$month);
  145. }
  146. if (($month = date('n')-1) >= 1) {
  147. $is = TimeLib::ageByYear(2000, $month);
  148. $this->out($is);
  149. //$this->assertEquals($is, (date('Y')-2001).'/'.(date('Y')-2000), null, '2000/'.$month);
  150. $this->assertSame($is, (date('Y')-2000), null, '2000/'.$month);
  151. }
  152. }
  153. public function testDaysInMonth() {
  154. $this->out($this->_header(__FUNCTION__));
  155. $ret = TimeLib::daysInMonth('2004', '3');
  156. $this->assertEquals($ret, 31);
  157. $ret = TimeLib::daysInMonth('2006', '4');
  158. $this->assertEquals($ret, 30);
  159. $ret = TimeLib::daysInMonth('2007', '2');
  160. $this->assertEquals($ret, 28);
  161. $ret = TimeLib::daysInMonth('2008', '2');
  162. $this->assertEquals($ret, 29);
  163. }
  164. public function testDay() {
  165. $this->out($this->_header(__FUNCTION__));
  166. $ret = TimeLib::day('0');
  167. $this->assertEquals(__('Sunday'), $ret);
  168. $ret = TimeLib::day(2, true);
  169. $this->assertEquals(__('Tue'), $ret);
  170. $ret = TimeLib::day(6);
  171. $this->assertEquals(__('Saturday'), $ret);
  172. $ret = TimeLib::day(6, false, 1);
  173. $this->assertEquals(__('Sunday'), $ret);
  174. $ret = TimeLib::day(0, false, 2);
  175. $this->assertEquals(__('Tuesday'), $ret);
  176. $ret = TimeLib::day(1, false, 6);
  177. $this->assertEquals(__('Sunday'), $ret);
  178. }
  179. public function testMonth() {
  180. $this->out($this->_header(__FUNCTION__));
  181. $ret = TimeLib::month('11');
  182. $this->assertEquals(__('November'), $ret);
  183. $ret = TimeLib::month(1);
  184. $this->assertEquals(__('January'), $ret);
  185. $ret = TimeLib::month(2, true, array('appendDot'=>true));
  186. $this->assertEquals(__('Feb').'.', $ret);
  187. $ret = TimeLib::month(5, true, array('appendDot'=>true));
  188. $this->assertEquals(__('May'), $ret);
  189. }
  190. public function testDays() {
  191. $this->out($this->_header(__FUNCTION__));
  192. $ret = TimeLib::days();
  193. $this->assertTrue(count($ret) === 7);
  194. }
  195. public function testMonths() {
  196. $this->out($this->_header(__FUNCTION__));
  197. $ret = TimeLib::months();
  198. $this->assertTrue(count($ret) === 12);
  199. }
  200. public function testRelLengthOfTime() {
  201. $this->out($this->_header(__FUNCTION__));
  202. $ret = TimeLib::relLengthOfTime('1990-11-20');
  203. //pr($ret);
  204. $ret = TimeLib::relLengthOfTime('2012-11-20');
  205. //pr($ret);
  206. }
  207. public function testLengthOfTime() {
  208. $this->out($this->_header(__FUNCTION__));
  209. $ret = TimeLib::lengthOfTime(60);
  210. //pr($ret);
  211. # FIX ME! Doesn't work!
  212. $ret = TimeLib::lengthOfTime(-60);
  213. //pr($ret);
  214. $ret = TimeLib::lengthOfTime(-121);
  215. //pr($ret);
  216. }
  217. public function testFuzzyFromOffset() {
  218. $this->out($this->_header(__FUNCTION__));
  219. $ret = TimeLib::fuzzyFromOffset(MONTH);
  220. //pr($ret);
  221. $ret = TimeLib::fuzzyFromOffset(120);
  222. //pr($ret);
  223. $ret = TimeLib::fuzzyFromOffset(DAY);
  224. //pr($ret);
  225. $ret = TimeLib::fuzzyFromOffset(DAY+2*MINUTE);
  226. //pr($ret);
  227. # FIX ME! Doesn't work!
  228. $ret = TimeLib::fuzzyFromOffset(-DAY);
  229. //pr($ret);
  230. }
  231. public function testCweekMod() {
  232. }
  233. public function testCweekDay() {
  234. $this->out($this->_header(__FUNCTION__));
  235. # wednesday
  236. $ret = TimeLib::cweekDay(51, 2011, 2);
  237. $this->out('51, 2011, 2');
  238. $this->out(date(FORMAT_DB_DATETIME, $ret));
  239. $this->assertTrue($ret >= 1324422000 && $ret <= 1324425600);
  240. //$this->assertEquals(1324422000, $ret);
  241. }
  242. public function testCweeks() {
  243. $this->out($this->_header(__FUNCTION__));
  244. $ret = TimeLib::cweeks('2004');
  245. $this->assertEquals($ret, 53);
  246. $ret = TimeLib::cweeks('2010');
  247. $this->assertEquals($ret, 52);
  248. $ret = TimeLib::cweeks('2006');
  249. $this->assertEquals($ret, 52);
  250. $ret = TimeLib::cweeks('2007');
  251. $this->assertEquals($ret, 52);
  252. /*
  253. for ($i = 1990; $i < 2020; $i++) {
  254. $this->out(TimeLib::cweeks($i).BR;
  255. }
  256. */
  257. }
  258. public function testCweekBeginning() {
  259. $this->out($this->_header(__FUNCTION__));
  260. $values = array(
  261. '2001' => 978303600, # Mon 01.01.2001, 00:00
  262. '2006' => 1136156400, # Mon 02.01.2006, 00:00
  263. '2010' => 1262559600, # Mon 04.01.2010, 00:00
  264. '2013' => 1356908400, # Mon 31.12.2012, 00:00
  265. );
  266. foreach ($values as $year => $expected) {
  267. $ret = TimeLib::cweekBeginning($year);
  268. $this->out($ret);
  269. $this->out(TimeLib::niceDate($ret, 'D').' '.TimeLib::niceDate($ret, FORMAT_NICE_YMDHMS));
  270. //$this->assertEquals($ret, $expected, null, $year);
  271. $this->assertTrue($ret <= $expected + HOUR && $ret >= $expected);
  272. }
  273. $values = array(
  274. array('2001', '1', 978303600), # Mon 01.01.2001, 00:00:00
  275. array('2001', '2', 978908400), # Mon 08.01.2001, 00:00:00
  276. array('2001', '5', 980722800), # Mon 29.01.2001, 00:00:00
  277. array('2001', '52', 1009148400), # Mon 24.12.2001, 00:00:00
  278. array('2013', '11', 1362956400), # Mon 11.03.2013, 00:00:00
  279. array('2006', '3', 1137366000), # Mon 16.01.2006, 00:00:00
  280. );
  281. foreach ($values as $v) {
  282. $ret = TimeLib::cweekBeginning($v[0], $v[1]);
  283. $this->out($ret);
  284. $this->out(TimeLib::niceDate($ret, 'D').' '.TimeLib::niceDate($ret, FORMAT_NICE_YMDHMS));
  285. //$this->assertSame($v[2], $ret, null, $v[1].'/'.$v[0]);
  286. $this->assertTrue($ret <= $v[2] + HOUR && $ret >= $v[2]);
  287. }
  288. }
  289. public function testCweekEnding() {
  290. $this->out($this->_header(__FUNCTION__));
  291. $values = array(
  292. '2001' => 1009753199, # Sun 30.12.2001, 23:59:59
  293. '2006' => 1167605999, # Sun 31.12.2006, 23:59:59
  294. '2010' => 1294009199, # Sun 02.01.2011, 23:59:59
  295. '2013' => 1388357999, # Sun 29.12.2013, 23:59:59
  296. );
  297. foreach ($values as $year => $expected) {
  298. $ret = TimeLib::cweekEnding($year);
  299. $this->out($ret);
  300. $this->out(TimeLib::niceDate($ret, 'D').' '.TimeLib::niceDate($ret, FORMAT_NICE_YMDHMS));
  301. //$this->assertSame($ret, $expected);
  302. $this->assertTrue($ret <= $expected + HOUR && $ret >= $expected);
  303. }
  304. $values = array(
  305. array('2001', '1', 978908399), # Sun 07.01.2001, 23:59:59
  306. array('2001', '2', 979513199), # Sun 14.01.2001, 23:59:59
  307. array('2001', '5', 981327599), # Sun 04.02.2001, 23:59:59
  308. array('2001', '52', 1009753199), # Sun 30.12.2001, 23:59:59
  309. array('2013', '11', 1363561199), # Sun 17.03.2013, 23:59:59
  310. array('2006', '3', 1137970799), # Sun 22.01.2006, 23:59:59
  311. );
  312. foreach ($values as $v) {
  313. $ret = TimeLib::cweekEnding($v[0], $v[1]);
  314. $this->out($ret);
  315. $this->out(TimeLib::niceDate($ret, 'D').' '.TimeLib::niceDate($ret, FORMAT_NICE_YMDHMS));
  316. //$this->assertSame($v[2], $ret, null, $v[1].'/'.$v[0]);
  317. $this->assertTrue($ret <= $v[2] + HOUR && $ret >= $v[2]);
  318. }
  319. }
  320. public function testAgeByHoroscop() {
  321. App::uses('ZodiacLib', 'Tools.Misc');
  322. $is = TimeLib::ageByHoroscope(2000, ZodiacLib::SIGN_VIRGO);
  323. //pr($is);
  324. $this->assertEquals(date('Y') - 2000 - 1, $is);
  325. $is = TimeLib::ageByHoroscope(1991, ZodiacLib::SIGN_LIBRA);
  326. //pr($is);
  327. $this->assertEquals(date('Y') - 1991 - 1, $is);
  328. $is = TimeLib::ageByHoroscope(1986, ZodiacLib::SIGN_CAPRICORN);
  329. //pr($is);
  330. $this->assertEquals($is, array(date('Y') - 1986 - 1, date('Y') - 1986));
  331. $is = TimeLib::ageByHoroscope(2000, ZodiacLib::SIGN_SCORPIO);
  332. //debug($is); ob_flush();
  333. $this->assertEquals(date('Y') - 2000 - 1, $is); //array(10, 11)
  334. }
  335. public function testAgeRange() {
  336. $is = TimeLib::ageRange(2000);
  337. //pr($is);
  338. $this->assertEquals(date('Y') - 2000 - 1, $is);
  339. $is = TimeLib::ageRange(2002, null, null, 5);
  340. //pr($is);
  341. $this->assertEquals($is, array(6, 10));
  342. $is = TimeLib::ageRange(2000, null, null, 5);
  343. //pr($is);
  344. $this->assertEquals($is, array(11, 15));
  345. $is = TimeLib::ageRange(1985, 23, 11);
  346. //pr($is);
  347. $this->assertEquals(date('Y') - 1985 - 1, $is);
  348. $is = TimeLib::ageRange(1985, null, null, 6);
  349. //pr($is);
  350. $this->assertEquals($is, array(25, 30));
  351. $is = TimeLib::ageRange(1985, 21, 11, 7);
  352. //pr($is);
  353. $this->assertEquals($is, array(22, 28));
  354. }
  355. public function testParseDate() {
  356. //echo $this->_header(__FUNCTION__);
  357. $tests = array(
  358. '2010-12-11' => 1292022000,
  359. '2010-01-02' => 1262386800,
  360. '10-01-02' => 1262386800,
  361. '2.1.2010' => 1262386800,
  362. '2.1.10' => 1262386800,
  363. '02.01.10' => 1262386800,
  364. '02.01.2010' => 1262386800,
  365. '02.01.2010 22:11' => 1262386800,
  366. '2010-01-02 22:11' => 1262386800,
  367. );
  368. foreach ($tests as $was => $expected) {
  369. $is = TimeLib::parseDate($was);
  370. //pr($is);
  371. //pr(date(FORMAT_NICE_YMDHMS, $is));
  372. //$this->assertSame($expected, $is); //, null, $was
  373. $this->assertTrue($is <= $expected + HOUR && $is >= $expected);
  374. }
  375. }
  376. public function testParseTime() {
  377. //echo $this->_header(__FUNCTION__);
  378. $tests = array(
  379. '2:4' => 7440,
  380. '2:04' => 7440,
  381. '2' => 7200,
  382. '1,5' => 3600+1800,
  383. '1.5' => 3600+1800,
  384. '1.50' => 3600+1800,
  385. '1.01' => 3660,
  386. ':4' => 240,
  387. ':04' => 240,
  388. ':40' => 40*MINUTE,
  389. '1:2:4' => 1*HOUR+2*MINUTE+4*SECOND,
  390. '01:2:04' => 1*HOUR+2*MINUTE+4*SECOND,
  391. '0:2:04' => 2*MINUTE+4*SECOND,
  392. '::4' => 4*SECOND,
  393. '::04' => 4*SECOND,
  394. '::40' => 40*SECOND,
  395. '2011-11-12 10:10:10' => 10*HOUR+10*MINUTE+10*SECOND,
  396. );
  397. # positive
  398. foreach ($tests as $was => $expected) {
  399. $is = TimeLib::parseTime($was);
  400. //pr($is);
  401. $this->assertEquals($expected, $is); //null, $was
  402. }
  403. unset($tests['2011-11-12 10:10:10']);
  404. # negative
  405. foreach ($tests as $was => $expected) {
  406. $is = TimeLib::parseTime('-'.$was);
  407. //pr($is);
  408. $this->assertEquals($is, -$expected); //, null, '-'.$was.' ['.$is.' => '.(-$expected).']'
  409. }
  410. }
  411. public function testBuildTime() {
  412. //echo $this->_header(__FUNCTION__);
  413. $tests = array(
  414. 7440 => '2:04',
  415. 7220 => '2:00', # 02:00:20 => rounded to 2:00:00
  416. 5400 => '1:30',
  417. 3660 => '1:01',
  418. );
  419. # positive
  420. foreach ($tests as $was => $expected) {
  421. $is = TimeLib::buildTime($was);
  422. //pr($is);
  423. $this->assertEquals($expected, $is);
  424. }
  425. # negative
  426. foreach ($tests as $was => $expected) {
  427. $is = TimeLib::buildTime(-$was);
  428. //pr($is);
  429. $this->assertEquals($is, '-'.$expected);
  430. }
  431. }
  432. public function testBuildDefaultTime() {
  433. //echo $this->_header(__FUNCTION__);
  434. $tests = array(
  435. 7440 => '02:04:00',
  436. 7220 => '02:00:20',
  437. 5400 => '01:30:00',
  438. 3660 => '01:01:00',
  439. 1*HOUR+2*MINUTE+4*SECOND => '01:02:04',
  440. );
  441. foreach ($tests as $was => $expected) {
  442. $is = TimeLib::buildDefaultTime($was);
  443. //pr($is);
  444. $this->assertEquals($expected, $is);
  445. }
  446. }
  447. /**
  448. * 9.30 => 9.50
  449. */
  450. public function testStandardDecimal() {
  451. //echo $this->_header(__FUNCTION__);
  452. $value = '9.30';
  453. $is = TimeLib::standardToDecimalTime($value);
  454. $this->assertEquals(round($is, 2), '9.50');
  455. $value = '9.3';
  456. $is = TimeLib::standardToDecimalTime($value);
  457. $this->assertEquals(round($is, 2), '9.50');
  458. }
  459. /**
  460. * 9.50 => 9.30
  461. */
  462. public function testDecimalStandard() {
  463. //echo $this->_header(__FUNCTION__);
  464. $value = '9.50';
  465. $is = TimeLib::decimalToStandardTime($value);
  466. $this->assertEquals(round($is, 2), '9.3');
  467. $value = '9.5';
  468. $is = TimeLib::decimalToStandardTime($value);
  469. //pr($is);
  470. $this->assertEquals($is, '9.3');
  471. $is = TimeLib::decimalToStandardTime($value, 2);
  472. //pr($is);
  473. $this->assertEquals($is, '9.30');
  474. $is = TimeLib::decimalToStandardTime($value, 2, ':');
  475. //pr($is);
  476. $this->assertEquals($is, '9:30');
  477. }
  478. }