Compare commits
No commits in common. "75f4b1d5f845f6b7356d21495d3997c0507c724c" and "a18b7dba6c0e8af53813f00115caf4bdefd1472c" have entirely different histories.
75f4b1d5f8
...
a18b7dba6c
@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Ulmus\Entity\Field;
|
|
||||||
|
|
||||||
class Date extends DatetimeImmutable {
|
|
||||||
|
|
||||||
public string $format = "Y-m-d";
|
|
||||||
}
|
|
||||||
@ -5,6 +5,66 @@ namespace Ulmus\Entity\Field;
|
|||||||
use Ulmus\Entity\EntityObjectInterface;
|
use Ulmus\Entity\EntityObjectInterface;
|
||||||
|
|
||||||
class Datetime extends \DateTime implements EntityObjectInterface, \JsonSerializable {
|
class Datetime extends \DateTime implements EntityObjectInterface, \JsonSerializable {
|
||||||
use DatetimeTrait;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public string $format = "Y-m-d H:i:s";
|
||||||
|
|
||||||
|
public function load(mixed ...$arguments)
|
||||||
|
{
|
||||||
|
$value = $arguments[0];
|
||||||
|
|
||||||
|
try {
|
||||||
|
# From Timestamp
|
||||||
|
if ( is_numeric($value) ) {
|
||||||
|
$obj = new static("@$value");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$obj = new static($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(\Throwable $ex) {
|
||||||
|
throw new \Exception(sprintf("An error occured trying to instanciate from '%s'. %s", $value, $ex->getMessage()), $ex->getCode(), $ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTime($hour, $minute, $second = 0, $microsecond = 0) : \DateTime
|
||||||
|
{
|
||||||
|
$fromParent = parent::setTime($hour, $minute, $second, $microsecond);
|
||||||
|
|
||||||
|
return new static($fromParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
return $this->__toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->format($this->format);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[\Deprecated]
|
||||||
|
public function formatLocale(string $format) : string
|
||||||
|
{
|
||||||
|
return strftime($format, $this->getTimestamp());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function formatLocaleIntl(int $dateFormatter = \IntlDateFormatter::LONG, int $timeFormatter = \IntlDateFormatter::NONE, ? string $pattern = null) : string
|
||||||
|
{
|
||||||
|
$formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormatter, $timeFormatter, \date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, $pattern);
|
||||||
|
|
||||||
|
return $formatter->format($this->getTimestamp());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ageAt(null|\DateTime $dateTime) : int
|
||||||
|
{
|
||||||
|
return (int) ( (int) ($dateTime ?: new DateTime())->format('Ymd') - (int) $this->format('Ymd') ) / 10000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jsonSerialize(): mixed
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Ulmus\Entity\Field;
|
|
||||||
|
|
||||||
use Ulmus\Entity\EntityObjectInterface;
|
|
||||||
|
|
||||||
class DatetimeImmutable extends \DateTimeImmutable implements EntityObjectInterface {
|
|
||||||
use DatetimeTrait;
|
|
||||||
}
|
|
||||||
@ -1,68 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Ulmus\Entity\Field;
|
|
||||||
|
|
||||||
trait DatetimeTrait
|
|
||||||
{
|
|
||||||
public string $format = "Y-m-d H:i:s";
|
|
||||||
|
|
||||||
public function load(mixed ...$arguments)
|
|
||||||
{
|
|
||||||
$value = $arguments[0];
|
|
||||||
|
|
||||||
try {
|
|
||||||
# From Timestamp
|
|
||||||
if ( is_numeric($value) ) {
|
|
||||||
$obj = new static("@$value");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$obj = new static($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(\Throwable $ex) {
|
|
||||||
throw new \Exception(sprintf("An error occured trying to instanciate from '%s'. %s", $value, $ex->getMessage()), $ex->getCode(), $ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTime($hour, $minute, $second = 0, $microsecond = 0) : \DateTimeInterface
|
|
||||||
{
|
|
||||||
$fromParent = parent::setTime($hour, $minute, $second, $microsecond);
|
|
||||||
|
|
||||||
return new static($fromParent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function save()
|
|
||||||
{
|
|
||||||
return $this->__toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return $this->format($this->format);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[\Deprecated]
|
|
||||||
public function formatLocale(string $format) : string
|
|
||||||
{
|
|
||||||
return strftime($format, $this->getTimestamp());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function formatLocaleIntl(int $dateFormatter = \IntlDateFormatter::LONG, int $timeFormatter = \IntlDateFormatter::NONE, ? string $pattern = null) : string
|
|
||||||
{
|
|
||||||
$formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormatter, $timeFormatter, \date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, $pattern);
|
|
||||||
|
|
||||||
return $formatter->format($this->getTimestamp());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ageAt(null|\DateTime $dateTime) : int
|
|
||||||
{
|
|
||||||
return (int) ( (int) ($dateTime ?: new DateTime())->format('Ymd') - (int) $this->format('Ymd') ) / 10000;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function jsonSerialize(): mixed
|
|
||||||
{
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Ulmus\Entity\Field;
|
|
||||||
|
|
||||||
class Time extends DatetimeImmutable {
|
|
||||||
|
|
||||||
public string $format = "H:i:s";
|
|
||||||
}
|
|
||||||
@ -106,7 +106,7 @@ class Having extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# whitelisting operators
|
# whitelisting operators
|
||||||
return in_array(strtoupper($this->operator), [ '=', '!=', '>', '>=', '<', '<=', '<>', 'LIKE', 'IS', 'IS NOT', 'REGEXP', 'IN' ]) ? $this->operator : "=";
|
return in_array(strtoupper($this->operator), [ '=', '!=', '<>', 'LIKE' ]) ? $this->operator : "=";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function value()
|
protected function value()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user