Skip to content
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

Closed
thomasmuehlschlegel opened this issue Oct 21, 2015 · 7 comments
Closed

create DateTime with nanoseconds #90

thomasmuehlschlegel opened this issue Oct 21, 2015 · 7 comments
Labels
contact after release Respond to issue after functionality is released. enhancement
Milestone

Comments

@thomasmuehlschlegel
Copy link

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
Copy link
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
Copy link
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
Copy link
Author

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
Copy link
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.

@ramsey ramsey added this to the Version 4.0.0 milestone Mar 26, 2016
@ramsey ramsey added the contact after release Respond to issue after functionality is released. label Jan 12, 2020
ramsey added a commit that referenced this issue Jan 20, 2020
@ramsey ramsey closed this as completed in a8d5210 Jan 22, 2020
@ramsey
Copy link
Owner

ramsey commented Jan 22, 2020

Please see version 4.0.0-alpha1. The getDateTime() method now returns a \DateTimeInterface instance that includes the microseconds.

@azerpas
Copy link

azerpas commented Jan 28, 2020

Please see version 4.0.0-alpha1. The getDateTime() method now returns a \DateTimeInterface instance that includes the microseconds.

How can we get 4.0.0 through composer? Waiting for that release for a project. 👍

@ramsey
Copy link
Owner

ramsey commented Jan 28, 2020

While the 4.0.0-alpha1 API is fairly stable, I don't recommend using it in production until the 4.0.0 release. That said, if you'd like to test it, I would recommend using this in your composer.json:

"ramsey/uuid": "4.0.0-alpha1 as 4.0.0"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contact after release Respond to issue after functionality is released. enhancement
Projects
None yet
Development

No branches or pull requests

3 participants