Skip to content

Commit 967a51e

Browse files
committed
Fixed work with empty Date/Time values
1 parent d5a2a15 commit 967a51e

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/AbraFlexi/Date.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ class Date extends \DateTime {
2525
/**
2626
* AbraFlexi date to PHP DateTime conversion
2727
*
28-
* @param string $flexidate 2017-05-26 or 2017-05-26Z or 2017-05-26+02:00
28+
* @param string $flexidate 2017-05-26 or 2017-05-26Z or 2017-05-26+02:00 or "NOW"
2929
*
3030
* @return \DateTime | false
3131
*/
3232
public function __construct(string $flexidate = 'NOW') {
33-
$this->isNull = is_null($flexidate);
33+
$this->isNull = empty($flexidate);
3434
$format = '';
3535
if (strstr($flexidate, '+')) {
3636
$format = RO::$DateFormat . 'O';
3737
} elseif (strstr($flexidate, 'Z')) {
3838
$format = RO::$DateFormat . 'Z';
39-
} elseif ($flexidate != 'NOW') {
39+
} elseif ( !empty ($flexidate) && ($flexidate != 'NOW')) {
4040
$format = RO::$DateFormat;
4141
}
4242
parent::__construct(empty($format) ? null : \DateTime::createFromFormat($format, $flexidate)->setTime(0, 0)->format(\DateTimeInterface::ATOM));

src/AbraFlexi/DateTime.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@
1616
*/
1717
class DateTime extends \DateTime {
1818

19+
/**
20+
* Support for Null values
21+
* @var bool
22+
*/
23+
public bool $isNull = false;
24+
1925
/**
2026
* AbraFlexi dateTime to PHP DateTime conversion
2127
*
2228
* @param string $flexidatetime 2017-09-26T10:00:53.755+02:00 or older 2017-05-19T00:00:00+02:00
2329
*
2430
* @return \DateTime | false
2531
*/
26-
public function __construct(string $flexidatetime) {
32+
public function __construct(string $flexidatetime = 'NOW') {
33+
$this->isNull = empty($flexidatetime);
34+
$format = '';
2735
if (strchr($flexidatetime, '.')) { //NewFormat
2836
$format = RO::$DateTimeFormat;
29-
} else { // Old format
37+
} elseif ($flexidatetime != 'NOW') { // Old format
3038
$format = 'Y-m-d\TH:i:s+P';
3139
}
32-
parent::__construct(\DateTime::createFromFormat($format, $flexidatetime)->format(\DateTimeInterface::ATOM));
40+
parent::__construct(empty($format) ? null : \DateTime::createFromFormat($format, $flexidatetime)->format(\DateTimeInterface::ATOM));
3341
}
3442

3543
/**
@@ -38,7 +46,7 @@ public function __construct(string $flexidatetime) {
3846
* @return string
3947
*/
4048
public function __toString() {
41-
return $this->format(RO::$DateTimeFormat);
49+
return $this->isNull ? null : $this->format(RO::$DateTimeFormat);
4250
}
4351

4452
}

src/AbraFlexi/RO.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,10 +1036,10 @@ public function fixRecordTypes(array $record, $evidence = null) {
10361036
$record[$column] = floatval($value);
10371037
break;
10381038
case 'datetime':
1039-
$record[$column] = empty($value) ? "" : new DateTime($value);
1039+
$record[$column] = new DateTime($value);
10401040
break;
10411041
case 'date':
1042-
$record[$column] = empty($value) ? "" : new Date($value);
1042+
$record[$column] = new Date($value);
10431043
break;
10441044
case 'blob':
10451045
break;

0 commit comments

Comments
 (0)