Skip to content

Commit

Permalink
Merge pull request #245 from podio-community/244-null-with-datetime
Browse files Browse the repository at this point in the history
fix: correct handling of null values for date/datetime fields
  • Loading branch information
daniel-sc authored Nov 21, 2023
2 parents 7c2e187 + 781516d commit 64468c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
10 changes: 9 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
[7.0.0](#v7.0.0) / [unreleased]
[7.0.2](#v7.0.2) / [UNRELEASED]
==================
* Bugfix: Correct handling of `null` values for date/datetime fields. #244

[7.0.1](#v7.0.1) / [2023-11-07]
==================
* Bugfix: Require guzzlehttp/psr7 >= 1.7.0 for Util class by @toby-griffiths in #243.

[7.0.0](#v7.0.0) / [2023-08-22]
==================
* BREAKING: Replace static `Podio` client with instantiable `PodioClient` class. #228
* BREAKING: Replace `save` (and `completed`/`incompleted`/`destroy` on `PodioTask`) methods on instances with static methods #234
Expand Down
2 changes: 1 addition & 1 deletion lib/PodioObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function __get($name)
}
if ($this->has_attribute($name)) {
// Create DateTime object if necessary
if ($this->has_property($name) && ($this->__properties[$name]['type'] == 'datetime' || $this->__properties[$name]['type'] == 'date')) {
if ($this->has_property($name) && ($this->__properties[$name]['type'] == 'datetime' || $this->__properties[$name]['type'] == 'date') && !empty($this->__attributes[$name])) {
$tz = new DateTimeZone('UTC');
return DateTime::createFromFormat($this->date_format_for_property($name), $this->__attributes[$name], $tz);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/PodioObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,15 @@ public function test_can_add_child_relationship(): void
$this->assertSame($instance, $relationship['instance']);
$this->assertSame('fields', $relationship['property']);
}

public function test_null_with_datetime(): void
{
$object = new PodioObject();
$object->property('datetime_property', 'datetime');
$object->datetime_property = null;

$this->assertNull($object->datetime_property);
// expect no (php deprecation) warning:
$this->expectOutputRegex('/^\s*$/');
}
}

0 comments on commit 64468c9

Please sign in to comment.