From 3633d6e27fd19e8e8151650280f4913b38eda494 Mon Sep 17 00:00:00 2001 From: Joe Harvey Date: Tue, 24 Jan 2017 15:55:35 +0000 Subject: [PATCH] Updating all setter methods on DBDate to return an instance of themselves --- src/ORM/FieldType/DBDate.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ORM/FieldType/DBDate.php b/src/ORM/FieldType/DBDate.php index 9ec054988..f336d63e4 100644 --- a/src/ORM/FieldType/DBDate.php +++ b/src/ORM/FieldType/DBDate.php @@ -33,6 +33,7 @@ class DBDate extends DBField * @config * @see DBDateTime::nice_format * @see DBTime::nice_format + * @return $this */ private static $nice_format = 'd/m/Y'; @@ -42,18 +43,19 @@ class DBDate extends DBField // don't try to evaluate empty values with strtotime() below, as it returns "1970-01-01" when it should be // saved as NULL in database $this->value = null; - return; + return $this; } // @todo This needs tidy up (what if you only specify a month and a year, for example?) if (is_array($value)) { if (!empty($value['Day']) && !empty($value['Month']) && !empty($value['Year'])) { $this->value = $value['Year'] . '-' . $value['Month'] . '-' . $value['Day']; - return; - } else { - // return nothing (so checks below don't fail on an empty array) - return null; } + /* + * return $this whether successfully set values from array based + * input or not (so checks below don't fail on an empty array) + */ + return $this; } // Default to NZ date format - strtotime expects a US date @@ -67,12 +69,11 @@ class DBDate extends DBField try { $date = new DateTime($value); $this->value = $date->format('Y-m-d'); - return; } catch (Exception $e) { $this->value = null; - return; } } + return $this; } /**