diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-03-22 16:55:06 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-03-26 17:42:01 +0100 |
commit | 633076d7c9275b33b722d9a7989e63839f8c38d2 (patch) | |
tree | b1ca9757d512da3669d6419b653cdc7a1d5c5bd0 /app/class/Item.php | |
parent | cfd04f2ecedf57f01cbb3c47a3ee0578d07ccec4 (diff) | |
download | wcms-633076d7c9275b33b722d9a7989e63839f8c38d2.tar.gz wcms-633076d7c9275b33b722d9a7989e63839f8c38d2.zip |
media date display
Diffstat (limited to 'app/class/Item.php')
-rw-r--r-- | app/class/Item.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/app/class/Item.php b/app/class/Item.php index 526e630..8bd62d1 100644 --- a/app/class/Item.php +++ b/app/class/Item.php @@ -2,6 +2,10 @@ namespace Wcms; +use DateTime; +use DateTimeImmutable; +use DateTimeZone; + abstract class Item { @@ -42,6 +46,37 @@ abstract class Item $array[$var] = $this->$var; } return $array; + } + + + /** + * Tool for accessing different view of the same DateTimeImmutable var + * + * @param string $property DateTimeImmutable var to access + * @param string $option + * + * @return mixed string or false if propriety does not exist + */ + protected function datetransform(string $property, string $option = 'date') + { + if(property_exists($this, $property)) { + if ($option == 'string') { + return $this->$property->format(DateTime::ISO8601); + } elseif ($option == 'date' || $option == 'sort') { + return $this->$property; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->$property->diff($now)); + } elseif ($option == 'pdate') { + return $this->$property->format('Y-m-d'); + } elseif ($option == 'ptime') { + return $this->$property->format('H:i'); + } elseif ($option = 'dmy') { + return $this->$property->format('d/m/Y'); + } + } else { + return false; + } } } |