New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create DateTime with nanoseconds #90

Open
thomasmuehlschlegel opened this Issue Oct 21, 2015 · 4 comments

Comments

2 participants
@thomasmuehlschlegel

thomasmuehlschlegel commented Oct 21, 2015

The uuid1 is using nanoseconds, but the UuidInterface returns a DateTime object which does not include the nanoseconds.

DateTime can handle it if you adjust the initialization:

\DateTime::createFromFormat('U.u', sprintf('%.f', ($this->getTimestamp() - 0x01b21dd213814000) / 1e7))
@ramsey

This comment has been minimized.

Show comment
Hide comment
@ramsey

ramsey Oct 21, 2015

Owner

Unfortunately, this is failing our tests, since the U option does not support negative timestamps. I'm still looking into it, though.

Owner

ramsey commented Oct 21, 2015

Unfortunately, this is failing our tests, since the U option does not support negative timestamps. I'm still looking into it, though.

@ramsey

This comment has been minimized.

Show comment
Hide comment
@ramsey

ramsey Oct 21, 2015

Owner

I spoke with Derick about it, and he has already fixed it in timelib. It will sync into PHP shortly: derickr/timelib@483fbab

Derick supposes it will hit PHP versions 5.5.31 / 5.6.15 / 7.0.0RC6. Since we still support 5.4 (and versions earlier than 5.5.31 and 5.6.15) in this library, we may not be able to use this functionality for a while. I'm investigating other options.

Owner

ramsey commented Oct 21, 2015

I spoke with Derick about it, and he has already fixed it in timelib. It will sync into PHP shortly: derickr/timelib@483fbab

Derick supposes it will hit PHP versions 5.5.31 / 5.6.15 / 7.0.0RC6. Since we still support 5.4 (and versions earlier than 5.5.31 and 5.6.15) in this library, we may not be able to use this functionality for a while. I'm investigating other options.

@thomasmuehlschlegel

This comment has been minimized.

Show comment
Hide comment
@thomasmuehlschlegel

thomasmuehlschlegel Oct 21, 2015

Another try:

$unixTime = ($this->getTimestamp() - 0x01b21dd213814000) / 1e7;
$microTime = abs($unixTime * 1e6 - (int)$unixTime * 1e6);

return new \DateTime(date('Y-m-d H:i:s', (int)$unixTime) . '.' . (int)$microTime);

thomasmuehlschlegel commented Oct 21, 2015

Another try:

$unixTime = ($this->getTimestamp() - 0x01b21dd213814000) / 1e7;
$microTime = abs($unixTime * 1e6 - (int)$unixTime * 1e6);

return new \DateTime(date('Y-m-d H:i:s', (int)$unixTime) . '.' . (int)$microTime);
@ramsey

This comment has been minimized.

Show comment
Hide comment
@ramsey

ramsey Oct 25, 2015

Owner

I'm still working on this, but it's causing test failures, and I want to be careful, since changing the tests without considering the consequences in these cases could break software that depends on this library.

See #93 for the changes.

Owner

ramsey commented Oct 25, 2015

I'm still working on this, but it's causing test failures, and I want to be careful, since changing the tests without considering the consequences in these cases could break software that depends on this library.

See #93 for the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment