Compare commits

...

3 Commits

Author SHA1 Message Date
caf5bd9664 - Fixed some missing operators in Having query 2026-07-17 10:10:37 -04:00
9062a73ee6 - WIP on package manager 2026-07-16 14:21:04 -04:00
Dave Mc Nicoll
e5a842a812 - Splitted Datetime and added Immutable versions too 2026-07-14 18:21:05 +00:00
7 changed files with 99 additions and 66 deletions

View File

@ -10,12 +10,12 @@
}
],
"require": {
"mcnd/notes": "dev-master"
"mcnd/notes": "^2.1.1"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/mcNdave/notes.git"
"type": "composer",
"url": "https://git.mcnd.ca/api/packages/mcndave/composer"
}
],
"autoload": {

View File

@ -0,0 +1,8 @@
<?php
namespace Ulmus\Entity\Field;
class Date extends DatetimeImmutable {
public string $format = "Y-m-d";
}

View File

@ -5,66 +5,6 @@ namespace Ulmus\Entity\Field;
use Ulmus\Entity\EntityObjectInterface;
class Datetime extends \DateTime implements EntityObjectInterface, \JsonSerializable {
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);
use DatetimeTrait;
}
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;
}
}

View File

@ -0,0 +1,9 @@
<?php
namespace Ulmus\Entity\Field;
use Ulmus\Entity\EntityObjectInterface;
class DatetimeImmutable extends \DateTimeImmutable implements EntityObjectInterface {
use DatetimeTrait;
}

View File

@ -0,0 +1,68 @@
<?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;
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace Ulmus\Entity\Field;
class Time extends DatetimeImmutable {
public string $format = "H:i:s";
}

View File

@ -106,7 +106,7 @@ class Having extends Fragment {
}
# whitelisting operators
return in_array(strtoupper($this->operator), [ '=', '!=', '<>', 'LIKE' ]) ? $this->operator : "=";
return in_array(strtoupper($this->operator), [ '=', '!=', '>', '>=', '<', '<=', '<>', 'LIKE', 'IS', 'IS NOT', 'REGEXP', 'IN' ]) ? $this->operator : "=";
}
protected function value()