Commit 47ab52be authored by Karamel's avatar Karamel
Browse files

Convert fiscal ticket date timestamp to a readable string format in archives.

parent 1682cee1
......@@ -334,6 +334,11 @@ class ArchiveAPI implements \Pasteque\Server\API\API
foreach ($tickets as $tkt) {
$struct = $tkt->toStruct();
$struct['signature_ok'] = $this->checkSignature($tkt, $prevTkt);
if (is_numeric($struct['date'])) {
$date = new \DateTime();
$date->setTimestamp($struct['date']);
$struct['date'] = $date->format('Y-m-d H:i:s');
}
$tkts[] = $struct;
$prevTkt = $tkt;
}
......
......@@ -262,12 +262,15 @@ class ArchiveAPICreateTest extends PastequeTestCase
$this->assertEquals('tkt', $tkt['type']);
$this->assertEquals('0001', $tkt['sequence']);
$this->assertEquals($i + 1, $tkt['number']);
$this->assertEquals(sprintf('2018-01-18 10:00:0%d', $i + 1),
$tkt['date']);
$this->assertEquals(sprintf('Ticket %d', $i + 1), $tkt['content']);
$this->assertEquals(true, $tkt['signature_ok']);
}
$this->assertEquals('z', $zs[0]['type']);
$this->assertEquals('0001', $zs[0]['sequence']);
$this->assertEquals(1, $zs[0]['number']);
$this->assertEquals('2018-01-18 12:05:00', $zs[0]['date']);
$this->assertEquals('Session 1', $zs[0]['content']);
$this->assertEquals(true, $zs[0]['signature_ok']);
}
......@@ -344,12 +347,15 @@ class ArchiveAPICreateTest extends PastequeTestCase
$this->assertEquals('tkt', $tkt['type']);
$this->assertEquals('0001', $tkt['sequence']);
$this->assertEquals($i + 1, $tkt['number']);
$this->assertEquals(sprintf('2018-01-18 10:00:0%d', $i + 1),
$tkt['date']);
$this->assertEquals(sprintf('Ticket %d', $i + 1), $tkt['content']);
$this->assertEquals(($i == 0), $tkt['signature_ok']);
}
$this->assertEquals('z', $zs[0]['type']);
$this->assertEquals('0001', $zs[0]['sequence']);
$this->assertEquals(1, $zs[0]['number']);
$this->assertEquals('2018-01-18 12:05:00', $zs[0]['date']);
$this->assertEquals('Session 1', $zs[0]['content']);
$this->assertEquals(true, $zs[0]['signature_ok']);
}
......@@ -483,39 +489,55 @@ class ArchiveAPICreateTest extends PastequeTestCase
// Check tkts
$this->assertEquals(ArchiveAPI::BATCH_SIZE, count($tkts1));
for ($i = 0; $i < ArchiveAPI::BATCH_SIZE; $i++) {
$min = floor(($i + 2) / 60);
$sec = ($i + 2) % 60;
$tkt = $tkts1[$i];
$this->assertEquals('tkt', $tkt['type']);
$this->assertEquals('0001', $tkt['sequence']);
$this->assertEquals($i + 2, $tkt['number']);
$this->assertEquals(sprintf('2018-01-18 10:%02d:%02d', $min, $sec),
$tkt['date']);
$this->assertEquals(sprintf('Ticket %d', $i + 2), $tkt['content']);
$this->assertEquals(true, $tkt['signature_ok']);
}
$this->assertEquals(4, count($tkts2));
for ($i = 0; $i < 4; $i++) {
$min = floor(($i + ArchiveAPI::BATCH_SIZE + 2) / 60);
$sec = ($i + ArchiveAPI::BATCH_SIZE + 2) % 60;
$tkt = $tkts2[$i];
$num = ArchiveAPI::BATCH_SIZE + $i + 2;
$this->assertEquals('tkt', $tkt['type']);
$this->assertEquals('0001', $tkt['sequence']);
$this->assertEquals($num, $tkt['number']);
$this->assertEquals(sprintf('2018-01-18 10:%02d:%02d', $min, $sec),
$tkt['date']);
$this->assertEquals(sprintf('Ticket %d', $num), $tkt['content']);
$this->assertEquals(true, $tkt['signature_ok']);
}
$this->assertEquals(ArchiveAPI::BATCH_SIZE, count($tkts3));
for ($i = 0; $i < ArchiveAPI::BATCH_SIZE; $i++) {
$min = floor(($i + 1) / 60);
$sec = ($i + 1) % 60;
$tkt = $tkts3[$i];
$this->assertEquals('tkt', $tkt['type']);
$this->assertEquals('0002', $tkt['sequence']);
$this->assertEquals($i + 1, $tkt['number']);
$this->assertEquals(sprintf('2018-01-12 14:%02d:%02d', $min, $sec),
$tkt['date']);
$this->assertEquals(sprintf('Ticket %d', $i + 1), $tkt['content']);
$this->assertEquals(true, $tkt['signature_ok']);
}
$this->assertEquals(3, count($tkts4));
for ($i = 0; $i < 3; $i++) {
$min = floor(($i + ArchiveAPI::BATCH_SIZE + 1) / 60);
$sec = ($i + ArchiveAPI::BATCH_SIZE + 1) % 60;
$tkt = $tkts4[$i];
$num = ArchiveAPI::BATCH_SIZE + $i + 1;
$this->assertEquals('tkt', $tkt['type']);
$this->assertEquals('0002', $tkt['sequence']);
$this->assertEquals($num, $tkt['number']);
$this->assertEquals(sprintf('2018-01-12 14:%02d:%02d', $min, $sec),
$tkt['date']);
$this->assertEquals(sprintf('Ticket %d', $num), $tkt['content']);
$this->assertEquals(true, $tkt['signature_ok']);
}
......@@ -524,12 +546,14 @@ class ArchiveAPICreateTest extends PastequeTestCase
$this->assertEquals('z', $zs1[0]['type']);
$this->assertEquals('0001', $zs1[0]['sequence']);
$this->assertEquals(2, $zs1[0]['number']);
$this->assertEquals('2018-01-18 12:05:00', $zs1[0]['date']);
$this->assertEquals('Session 2', $zs1[0]['content']);
$this->assertEquals(true, $zs1[0]['signature_ok']);
$this->assertEquals(1, count($zs2));
$this->assertEquals('z', $zs2[0]['type']);
$this->assertEquals('0002', $zs2[0]['sequence']);
$this->assertEquals(1, $zs2[0]['number']);
$this->assertEquals('2018-01-12 16:05:00', $zs2[0]['date']);
$this->assertEquals('Session 1', $zs2[0]['content']);
$this->assertEquals(true, $zs2[0]['signature_ok']);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment