Page MenuHomePhabricator

TS_UNIX_MICRO gets things wrong for timestamps before the epoch
Closed, ResolvedPublic

Description

With HHVM,

hphpd> =Wikimedia\Timestamp\ConvertibleTimestamp::convert( TS_ORACLE, '-1.1' )
=Wikimedia\Timestamp\ConvertibleTimestamp::convert( TS_ORACLE, '-1.1' )
false

hphpd> =Wikimedia\Timestamp\ConvertibleTimestamp::convert( TS_UNIX_MICRO, '31-12-1969 23:59:58.900000' )
=Wikimedia\Timestamp\ConvertibleTimestamp::convert( TS_UNIX_MICRO, '31-12-1969 23:59:58.900000' )
"-2.900000"

It refuses -1.1 entirely, and it returns a timestamp after "31-12-1969 23:59:58" returns a value that comes earlier.

With PHP 7.2,

>>> Wikimedia\Timestamp\ConvertibleTimestamp::convert( TS_ORACLE, '-1.1' )
=> "31-12-1969 23:59:59.100000"

>>> Wikimedia\Timestamp\ConvertibleTimestamp::convert( TS_UNIX_MICRO, '31-12-1969 23:59:58.900000' )
=> "-2.900000"

Here -1.1 works, but again returns an out-of-order value.

In both cases, what it's doing is treating "-1.1" as "-1 seconds + 100000 microseconds" => "-0.9 seconds", both on input and output. Further, HHVM has a bug where DateTime::createFromFormat( 'U' ) doesn't accept negative values.

Event Timeline

Change 512071 had a related patch set uploaded (by Anomie; owner: Anomie):
[mediawiki/libs/Timestamp@master] Honor timezones in input, and correct some odd accepted values

https://gerrit.wikimedia.org/r/512071

Change 512071 merged by jenkins-bot:
[mediawiki/libs/Timestamp@master] Honor timezones in input, and correct some odd accepted values

https://gerrit.wikimedia.org/r/512071