Bug #69150 [Opn->Nab]: DateTime object does not update micro seconds

From: Date: Mon, 02 Mar 2015 18:46:20 +0000
Subject: Bug #69150 [Opn->Nab]: DateTime object does not update micro seconds
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191051@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69150&edit=1

 ID:                 69150
 Updated by:         aharvey@php.net
 Reported by:        remyfox at hotmail dot com
 Summary:            DateTime object does not update micro seconds
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Date/time related
 Operating System:   Windows 7
 PHP Version:        5.6.6
 Block user comment: N
 Private report:     N

 New Comment:

Yep: any date/time function that deals with UNIX timestamps is limited to second precision by
definition, since PHP always treats them as integers.

Closing not a bug.


Previous Comments:
------------------------------------------------------------------------
[2015-03-02 00:09:38] cmbecker69 at gmx dot de

This is not a bug.

It is documented that DateTime::setTimestamp()[1] expects a Unix
timestamp as int argument.  Any float passed to this method is
casted to integer.

[1] <http://php.net/manual/en/datetime.settimestamp.php>

------------------------------------------------------------------------
[2015-02-28 23:47:47] remyfox at hotmail dot com

Description:
------------
Micro seconds on the date property (and consequently, formatted output) do not update after the
initial creation of the DateTime object.

Test script:
---------------
$datetime = Datetime::createFromFormat('Y-m-d H:i:s.u', '2009-02-09
15:16:17.015750');
$datetime->setTimeStamp(0);
print_r($datetime);
	
$datetime = Datetime::createFromFormat('Y-m-d H:i:s', '2009-02-09 15:16:17');
$datetime->setTimeStamp(0.123);
print_r($datetime);

Expected result:
----------------
DateTime Object
(
    [date] => 1970-01-01 01:00:00.000000
    [timezone_type] => 3
    [timezone] => Europe/Berlin
)
DateTime Object
(
    [date] => 1970-01-01 01:00:00.123000
    [timezone_type] => 3
    [timezone] => Europe/Berlin
)

Actual result:
--------------
DateTime Object
(
    [date] => 1970-01-01 01:00:00.015750
    [timezone_type] => 3
    [timezone] => Europe/Berlin
)
DateTime Object
(
    [date] => 1970-01-01 01:00:00.000000
    [timezone_type] => 3
    [timezone] => Europe/Berlin
)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69150&edit=1


Thread (3 messages)

« previous php.bugs (#191051) next »