Skip to content

Fixed #74298 - IntlDateFormatter->format() doesn't return microseconds/fractions #2432

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

Closed

Conversation

andrewnester
Copy link
Contributor

FIx for https://bugs.php.net/bug.php?id=74298

udat_format supports formatting only milliseconds (3 digits of fractions).

Here is the statement from documentation:
Appends zeros if more than 3 letters specified. Truncates at three significant digits when parsing.

@andrewnester andrewnester changed the base branch from master to PHP-7.1 March 24, 2017 16:25
@inoas
Copy link

inoas commented Mar 25, 2017

Hmpf, luckily MariaDB / MySQL and PostgreSQL do 6 digits precision (I am using datetime(6) as a revisioning candidate/unique key part).

So AFAIU PHP's datetime objects do (unless buggy) the same; however ICU parsing/formatting - by spec - cuts at 3 digits, right?

THanks for caring @ PR.

@andrewnester
Copy link
Contributor Author

@inoas yes, 3 digits precision relates only to ICU

@andrewnester
Copy link
Contributor Author

@krakjoe @nikic any feedback about it? thanks!

@@ -137,7 +139,8 @@ U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz,
return FAILURE;
}

*millis = U_MILLIS_PER_SECOND * (double)Z_LVAL(retval);
datetime = Z_PHPDATE_P(z);
*millis = U_MILLIS_PER_SECOND * ((double)Z_LVAL(retval) + datetime->time->f);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that the timestamp is retrieved through a getTimestamp() method while the fraction is obtained directly from the structure feels like a breach of abstraction. On the other hand, it does not seem like DateTime has a direct way of getting the fraction (or timestamp with fraction).

@derickr Do you have any thoughts on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think getTimestamp should have been call as a PHP function at all here. THen again, timelib should have a function for returning timestamp/fraction, and all the other fields really.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derickr I think the idea here might have been (I don't know) that people might extend DateTime::getTimestamp() in userland. If this is not something we want to respect, then directly fetching the value from the underlying structure is of course much better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikic agree, I thought that it's because of extending of DateTime::getTimestamp(). From my perspective it seems reasonable

@krakjoe krakjoe added the Bug label Mar 31, 2017
@inoas
Copy link

inoas commented Apr 8, 2017

Any news on this?

@nikic
Copy link
Member

nikic commented Apr 9, 2017

Merged as 1ce355a, thanks!

@nikic nikic closed this Apr 9, 2017
@inoas
Copy link

inoas commented Apr 9, 2017

This is awesome! ❤️ x 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants