summaryrefslogtreecommitdiff
path: root/vendor/google/protobuf/src/Google/Protobuf/Internal/TimestampBase.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/google/protobuf/src/Google/Protobuf/Internal/TimestampBase.php')
-rw-r--r--vendor/google/protobuf/src/Google/Protobuf/Internal/TimestampBase.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/vendor/google/protobuf/src/Google/Protobuf/Internal/TimestampBase.php b/vendor/google/protobuf/src/Google/Protobuf/Internal/TimestampBase.php
new file mode 100644
index 000000000..653d1e99d
--- /dev/null
+++ b/vendor/google/protobuf/src/Google/Protobuf/Internal/TimestampBase.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace Google\Protobuf\Internal;
+
+/**
+ * Base class for Google\Protobuf\Timestamp, this contains hand-written
+ * convenience methods.
+ */
+class TimestampBase extends \Google\Protobuf\Internal\Message
+{
+ /*
+ * Converts PHP DateTime to Timestamp.
+ *
+ * @param \DateTime $datetime
+ */
+ public function fromDateTime(\DateTime $datetime)
+ {
+ $this->seconds = $datetime->getTimestamp();
+ $this->nanos = 1000 * $datetime->format('u');
+ }
+
+ /**
+ * Converts Timestamp to PHP DateTime.
+ *
+ * @return \DateTime $datetime
+ */
+ public function toDateTime()
+ {
+ $time = sprintf('%s.%06d', $this->seconds, $this->nanos / 1000);
+ return \DateTime::createFromFormat('U.u', $time);
+ }
+}