diff options
author | redmatrix <mike@macgirvin.com> | 2016-09-26 18:17:38 -0700 |
---|---|---|
committer | redmatrix <mike@macgirvin.com> | 2016-09-26 18:17:38 -0700 |
commit | 4663278f52fd11c1014d13151af2bc6ef1392c7d (patch) | |
tree | 5ea36ed7db723a1d0abfd99c5e7d21f9e72cf12a /include/datetime.php | |
parent | 5716556766eb4e329f0c6c1bc899a7621cbcd5a5 (diff) | |
parent | cacdac16aa104eb1308f69f24fef31f682934fca (diff) | |
download | volse-hubzilla-4663278f52fd11c1014d13151af2bc6ef1392c7d.tar.gz volse-hubzilla-4663278f52fd11c1014d13151af2bc6ef1392c7d.tar.bz2 volse-hubzilla-4663278f52fd11c1014d13151af2bc6ef1392c7d.zip |
Merge branch 'nulldate' into dev
Diffstat (limited to 'include/datetime.php')
-rw-r--r-- | include/datetime.php | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/include/datetime.php b/include/datetime.php index 76bd6b8d6..cd08ab367 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -24,6 +24,13 @@ function timezone_cmp($a, $b) { return ( t($a) < t($b)) ? -1 : 1; } +function is_null_date($s) { + if($s === '0000-00-00 00:00:00' || $s === '0001-01-01 00:00:00') + return true; + return false; +} + + /** * @brief Return timezones grouped (primarily) by continent. * @@ -78,15 +85,20 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d if( ($s === '') || (! is_string($s)) ) $s = 'now'; + if(is_null_date($s)) { + $d = new DateTime('0001-01-01 00:00:00', new DateTimeZone('UTC')); + return $d->format($fmt); + } + // Slight hackish adjustment so that 'zero' datetime actually returns what is intended // otherwise we end up with -0001-11-30 ... // add 32 days so that we at least get year 00, and then hack around the fact that // months and days always start with 1. - if(substr($s,0,10) == '0000-00-00') { - $d = new DateTime($s . ' + 32 days', new DateTimeZone('UTC')); - return str_replace('1', '0', $d->format($fmt)); - } +// if(substr($s,0,10) == '0000-00-00') { +// $d = new DateTime($s . ' + 32 days', new DateTimeZone('UTC')); +// return str_replace('1', '0', $d->format($fmt)); +// } try { $from_obj = new DateTimeZone($from); @@ -268,7 +280,7 @@ function relative_date($posted_date, $format = null) { $abs = strtotime($localtime); - if (is_null($posted_date) || $posted_date === NULL_DATE || $abs === false) { + if (is_null($posted_date) || is_null_date($posted_date) || $abs === false) { return t('never'); } |