File: bson-objectid-getTimestamp-002.phpt

package info (click to toggle)
php-mongodb 1.15.0%2B1.11.1%2B1.9.2%2B1.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 63,984 kB
  • sloc: ansic: 328,429; xml: 10,797; php: 4,235; sh: 179; python: 47; pascal: 36; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 719 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
--TEST--
MongoDB\BSON\ObjectId::getTimestamp: Ensure that the Timestamp field is represented as an unsigned 32-bit integer
--FILE--
<?php
date_default_timezone_set("UTC");

function create_object_id($oid_string)
{
    $objectid = new MongoDB\BSON\ObjectId($oid_string);
    $ts = sprintf("%u", $objectid->getTimestamp());
    echo $ts, "\n";
    echo date_create("@{$ts}")->format("Y-m-d H:i:s"), "\n";
}

create_object_id('000000000000000000000000');
create_object_id('7FFFFFFF0000000000000000');
create_object_id('800000000000000000000000');
create_object_id('FFFFFFFF0000000000000000');

?>
--EXPECT--
0
1970-01-01 00:00:00
2147483647
2038-01-19 03:14:07
2147483648
2038-01-19 03:14:08
4294967295
2106-02-07 06:28:15