Skip to content

Commit

Permalink
Change to supporting \DateTimeInterface for better handling of immu…
Browse files Browse the repository at this point in the history
…table source data
  • Loading branch information
tomwalder committed Aug 23, 2018
1 parent 5a95d05 commit 65fbaff
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/GDS/Gateway/ProtoBuf.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ protected function configureObjectValueParamForQuery($obj_val, $mix_value)
$obj_key_value = $obj_val->mutableKeyValue();
$this->createMapper()->configureGoogleKey($obj_key_value, $mix_value);
$this->applyNamespace($obj_key_value);
} elseif ($mix_value instanceof \DateTime) {
} elseif ($mix_value instanceof \DateTimeInterface) {
$obj_val->setTimestampMicrosecondsValue($mix_value->format(Mapper::DATETIME_FORMAT_UU));
} elseif (method_exists($mix_value, '__toString')) {
$obj_val->setStringValue($mix_value->__toString());
Expand Down
2 changes: 1 addition & 1 deletion src/GDS/Gateway/RESTv1.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ protected function configureObjectValueParamForQuery($obj_val, $mix_value)
if($mix_value instanceof Entity) {
/** @var Entity $mix_value */
$obj_val->keyValue = $this->applyPartition((object)['path' => $this->createMapper()->buildKeyPath($mix_value)]);
} elseif ($mix_value instanceof \DateTime) {
} elseif ($mix_value instanceof \DateTimeInterface) {
$obj_val->timestampValue = $mix_value->format(\GDS\Mapper\RESTv1::DATETIME_FORMAT);
} elseif (method_exists($mix_value, '__toString')) {
$obj_val->stringValue = $mix_value->__toString();
Expand Down
2 changes: 1 addition & 1 deletion src/GDS/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function determineDynamicType($mix_value)
break;

case 'object':
if($mix_value instanceof \DateTime) {
if($mix_value instanceof \DateTimeInterface) {
$int_dynamic_type = Schema::PROPERTY_DATETIME;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/GDS/Mapper/ProtoBuf.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ private function configureGooglePropertyValue(Value $obj_val, array $arr_field_d
break;

case Schema::PROPERTY_DATETIME:
if($mix_value instanceof \DateTime) {
if($mix_value instanceof \DateTimeInterface) {
$obj_dtm = $mix_value;
} else {
$obj_dtm = new \DateTime($mix_value);
$obj_dtm = new \DateTimeImmutable($mix_value);
}
$obj_val->setTimestampMicrosecondsValue($obj_dtm->format(self::DATETIME_FORMAT_UU));
break;
Expand Down
4 changes: 2 additions & 2 deletions src/GDS/Mapper/RESTv1.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,10 @@ protected function createPropertyValue(array $arr_field_def, $mix_value)
break;

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

0 comments on commit 65fbaff

Please sign in to comment.