TimeLibTest.php 17 KB

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