You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2018/10/23 15:01:49 UTC

[45/50] [abbrv] ignite git commit: IGNITE-9951 PHP: Fixes for Date data type

IGNITE-9951 PHP: Fixes for Date data type

This closes #5043


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/685c008a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/685c008a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/685c008a

Branch: refs/heads/ignite-gg-14206
Commit: 685c008af3c5c07f02e7d311fdf0c39f6e3941e0
Parents: 3f7109f
Author: Pavel Petroshenko <pa...@petroshenko.com>
Authored: Tue Oct 23 13:35:37 2018 +0300
Committer: Igor Sapego <is...@apache.org>
Committed: Tue Oct 23 13:35:37 2018 +0300

----------------------------------------------------------------------
 modules/platforms/php/src/Apache/Ignite/Data/Date.php      | 9 ++++-----
 modules/platforms/php/src/Apache/Ignite/Data/Timestamp.php | 4 +++-
 2 files changed, 7 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/685c008a/modules/platforms/php/src/Apache/Ignite/Data/Date.php
----------------------------------------------------------------------
diff --git a/modules/platforms/php/src/Apache/Ignite/Data/Date.php b/modules/platforms/php/src/Apache/Ignite/Data/Date.php
index 356cc36..fa5f394 100644
--- a/modules/platforms/php/src/Apache/Ignite/Data/Date.php
+++ b/modules/platforms/php/src/Apache/Ignite/Data/Date.php
@@ -47,7 +47,8 @@ class Date
      */
     public static function fromDateTime(DateTime $dateTime)
     {
-        return new Date($dateTime->getTimestamp() * 1000);
+        $millis = intval($dateTime->format('u') / 1000);
+        return new Date($dateTime->getTimestamp() * 1000 + $millis);
     }
     
     /**
@@ -57,11 +58,9 @@ class Date
      */
     public function toDateTime(): DateTime
     {
-        $dateTime = new DateTime();
-        $dateTime->setTimestamp($this->getSeconds());
-        return $dateTime;
+        return DateTime::createFromFormat('U.u', number_format($this->getMillis() / 1000, 6, '.', ''));
     }
-    
+
     /**
      * Returns the date value as number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC.
      * 

http://git-wip-us.apache.org/repos/asf/ignite/blob/685c008a/modules/platforms/php/src/Apache/Ignite/Data/Timestamp.php
----------------------------------------------------------------------
diff --git a/modules/platforms/php/src/Apache/Ignite/Data/Timestamp.php b/modules/platforms/php/src/Apache/Ignite/Data/Timestamp.php
index 39ef984..a404d46 100644
--- a/modules/platforms/php/src/Apache/Ignite/Data/Timestamp.php
+++ b/modules/platforms/php/src/Apache/Ignite/Data/Timestamp.php
@@ -49,7 +49,9 @@ class Timestamp extends Date
      */
     public static function fromDateTime(DateTime $dateTime)
     {
-        return new Timestamp($dateTime->getTimestamp() * 1000, 0);
+        $micros = $dateTime->format('u');
+        $millis = intval($micros / 1000);
+        return new Timestamp($dateTime->getTimestamp() * 1000 + $millis, ($micros % 1000) * 1000);
     }
     
     /**