Skip to content

Commit c948825

Browse files
committed
Merge pull request #622
2 parents caa518e + 4335eae commit c948825

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

src/BSON/Timestamp.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,36 @@ static PHP_METHOD(Timestamp, __construct)
163163
php_phongo_timestamp_init_from_string(intern, Z_STRVAL_P(increment), Z_STRLEN_P(increment), Z_STRVAL_P(timestamp), Z_STRLEN_P(timestamp) TSRMLS_CC);
164164
} /* }}} */
165165

166+
/* {{{ proto integer MongoDB\BSON\Timestamp::getIncrement()
167+
*/
168+
static PHP_METHOD(Timestamp, getIncrement)
169+
{
170+
php_phongo_timestamp_t *intern;
171+
172+
intern = Z_TIMESTAMP_OBJ_P(getThis());
173+
174+
if (zend_parse_parameters_none() == FAILURE) {
175+
return;
176+
}
177+
178+
RETVAL_LONG(intern->increment);
179+
} /* }}} */
180+
181+
/* {{{ proto integer MongoDB\BSON\Timestamp::getTimestamp()
182+
*/
183+
static PHP_METHOD(Timestamp, getTimestamp)
184+
{
185+
php_phongo_timestamp_t *intern;
186+
187+
intern = Z_TIMESTAMP_OBJ_P(getThis());
188+
189+
if (zend_parse_parameters_none() == FAILURE) {
190+
return;
191+
}
192+
193+
RETVAL_LONG(intern->timestamp);
194+
} /* }}} */
195+
166196
/* {{{ proto void MongoDB\BSON\Timestamp::__set_state(array $properties)
167197
*/
168198
static PHP_METHOD(Timestamp, __set_state)
@@ -357,6 +387,8 @@ static zend_function_entry php_phongo_timestamp_me[] = {
357387
PHP_ME(Timestamp, jsonSerialize, ai_Timestamp_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
358388
PHP_ME(Timestamp, serialize, ai_Timestamp_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
359389
PHP_ME(Timestamp, unserialize, ai_Timestamp_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
390+
PHP_ME(Timestamp, getIncrement, ai_Timestamp_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
391+
PHP_ME(Timestamp, getTimestamp, ai_Timestamp_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
360392
PHP_FE_END
361393
};
362394
/* }}} */
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
MongoDB\BSON\Timestamp::getIncrement()
3+
--FILE--
4+
<?php
5+
6+
$tests = [
7+
new MongoDB\BSON\Timestamp(1234, 5678),
8+
new MongoDB\BSON\Timestamp(2147483647, 0),
9+
new MongoDB\BSON\Timestamp(0, 2147483647),
10+
];
11+
12+
foreach ($tests as $test) {
13+
printf("Test %s\n", $test);
14+
var_dump($test->getIncrement());
15+
echo "\n";
16+
}
17+
18+
?>
19+
===DONE===
20+
<?php exit(0); ?>
21+
--EXPECTF--
22+
Test [1234:5678]
23+
int(1234)
24+
25+
Test [2147483647:0]
26+
int(2147483647)
27+
28+
Test [0:2147483647]
29+
int(0)
30+
31+
===DONE===
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
MongoDB\BSON\Timestamp::getTimestamp()
3+
--FILE--
4+
<?php
5+
6+
$tests = [
7+
new MongoDB\BSON\Timestamp(1234, 5678),
8+
new MongoDB\BSON\Timestamp(2147483647, 0),
9+
new MongoDB\BSON\Timestamp(0, 2147483647),
10+
];
11+
12+
foreach ($tests as $test) {
13+
printf("Test %s\n", $test);
14+
var_dump($test->getTimestamp());
15+
echo "\n";
16+
}
17+
18+
?>
19+
===DONE===
20+
<?php exit(0); ?>
21+
--EXPECTF--
22+
Test [1234:5678]
23+
int(5678)
24+
25+
Test [2147483647:0]
26+
int(0)
27+
28+
Test [0:2147483647]
29+
int(2147483647)
30+
31+
===DONE===

0 commit comments

Comments
 (0)