/** * Make sure that we handle microseconds correctly * * When we Date->__toString() it should preserve the microseconds, * and we should be able to parse it again to yield the exact same * value in another object. */ public function testMicrosecondsToStringAndBack() { $date0 = new Date(); // Format the current date without any microseconds, but use // a "@" char where the micros should be $stringDate = $date0->format('Y-m-d\\TH:i:s@O'); // Explicitly add microseconds to the date format string, so // we _guarantee_ that the date contains microseconds $stringDate = str_replace('@', '.123456', $stringDate); $date1 = new Date($stringDate); $string1 = $date1->__toString(); $date2 = new Date($string1); $this->assertEquals($date1->getTimestamp(), $date2->getTimestamp(), "Parsing __toString result should yield same date as before"); }
public function testRenderCellJsonWithFormattingAndProperties() { $expected = '{"v":new Date(2013,9,19),"f":"2013-10-19","p":{"prop":"val"}}'; $date = new Date('Oct 19, 2013'); $formattedDate = $date->format("Y-m-d"); $cell = new TableCell(new DateValue($date), $formattedDate); $cell->setCustomProperty('prop', 'val'); $renderer = new JsonRenderer(); $actual = $renderer->renderCellJson($cell, true, false, true); $this->assertSame($expected, $actual, "TableCell rendered json must match expected value"); }