Skip to content

Commit 65fbaff

Browse files
committed
Change to supporting \DateTimeInterface for better handling of immutable source data
1 parent 5a95d05 commit 65fbaff

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

src/GDS/Gateway/ProtoBuf.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ protected function configureObjectValueParamForQuery($obj_val, $mix_value)
413413
$obj_key_value = $obj_val->mutableKeyValue();
414414
$this->createMapper()->configureGoogleKey($obj_key_value, $mix_value);
415415
$this->applyNamespace($obj_key_value);
416-
} elseif ($mix_value instanceof \DateTime) {
416+
} elseif ($mix_value instanceof \DateTimeInterface) {
417417
$obj_val->setTimestampMicrosecondsValue($mix_value->format(Mapper::DATETIME_FORMAT_UU));
418418
} elseif (method_exists($mix_value, '__toString')) {
419419
$obj_val->setStringValue($mix_value->__toString());

src/GDS/Gateway/RESTv1.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ protected function configureObjectValueParamForQuery($obj_val, $mix_value)
428428
if($mix_value instanceof Entity) {
429429
/** @var Entity $mix_value */
430430
$obj_val->keyValue = $this->applyPartition((object)['path' => $this->createMapper()->buildKeyPath($mix_value)]);
431-
} elseif ($mix_value instanceof \DateTime) {
431+
} elseif ($mix_value instanceof \DateTimeInterface) {
432432
$obj_val->timestampValue = $mix_value->format(\GDS\Mapper\RESTv1::DATETIME_FORMAT);
433433
} elseif (method_exists($mix_value, '__toString')) {
434434
$obj_val->stringValue = $mix_value->__toString();

src/GDS/Mapper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function determineDynamicType($mix_value)
8585
break;
8686

8787
case 'object':
88-
if($mix_value instanceof \DateTime) {
88+
if($mix_value instanceof \DateTimeInterface) {
8989
$int_dynamic_type = Schema::PROPERTY_DATETIME;
9090
break;
9191
}

src/GDS/Mapper/ProtoBuf.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ private function configureGooglePropertyValue(Value $obj_val, array $arr_field_d
210210
break;
211211

212212
case Schema::PROPERTY_DATETIME:
213-
if($mix_value instanceof \DateTime) {
213+
if($mix_value instanceof \DateTimeInterface) {
214214
$obj_dtm = $mix_value;
215215
} else {
216-
$obj_dtm = new \DateTime($mix_value);
216+
$obj_dtm = new \DateTimeImmutable($mix_value);
217217
}
218218
$obj_val->setTimestampMicrosecondsValue($obj_dtm->format(self::DATETIME_FORMAT_UU));
219219
break;

src/GDS/Mapper/RESTv1.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ protected function createPropertyValue(array $arr_field_def, $mix_value)
393393
break;
394394

395395
case Schema::PROPERTY_DATETIME:
396-
if($mix_value instanceof \DateTime) {
396+
if($mix_value instanceof \DateTimeInterface) {
397397
$obj_dtm = $mix_value;
398398
} else {
399-
$obj_dtm = new \DateTime($mix_value);
399+
$obj_dtm = new \DateTimeImmutable($mix_value);
400400
}
401401
// A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".
402402
$obj_property_value->timestampValue = $obj_dtm->format(self::DATETIME_FORMAT);

0 commit comments

Comments
 (0)