1: <?php
2: namespace phpcassa\Schema\DataType;
3:
4: use phpcassa\Schema\DataType\LongType;
5: use phpcassa\Schema\DataType\Serialized;
6:
7: 8: 9: 10: 11:
12: class DateType extends LongType implements Serialized {
13:
14: public function pack($value, $is_name=true, $slice_end=null, $is_data=false)
15: {
16: if (false !== strpos($value, ' ')) {
17: list($usec, $sec) = explode(' ', $value);
18: $value = $sec + $usec;
19: } else if ($is_name && $is_data) {
20: $value = unserialize($value);
21: }
22:
23: $value = floor($value * 1e3);
24: return parent::pack($value);
25: }
26:
27: public function unpack($data, $handle_serialize=true)
28: {
29: $value = parent::unpack($data, false) / 1e3;
30: if ($handle_serialize) {
31: return serialize($value);
32: } else {
33: return $value;
34: }
35: }
36: }
37: