refactor: use epoch timestamp

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-07-04 18:38:38 -04:00
parent 858582a4ce
commit 6bf4706556
3 changed files with 13 additions and 11 deletions
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace KTXM\ProviderLocalPeople\Providers\Personal; namespace KTXM\ProviderLocalPeople\Providers\Personal;
use KTXF\Utile\Timestamp;
use KTXF\People\Collection\CollectionMutableAbstract; use KTXF\People\Collection\CollectionMutableAbstract;
use KTXF\Resource\Identifier\CollectionIdentifier; use KTXF\Resource\Identifier\CollectionIdentifier;
@@ -73,8 +74,8 @@ class CollectionResource extends CollectionMutableAbstract {
'rank' => $properties->getRank(), 'rank' => $properties->getRank(),
'visibility' => $properties->getVisibility(), 'visibility' => $properties->getVisibility(),
'color' => $properties->getColor(), 'color' => $properties->getColor(),
'createdOn' => $this->data[self::PROPERTY_CREATED] ?? null, 'createdOn' => Timestamp::normalize($this->data[self::PROPERTY_CREATED] ?? null),
'modifiedOn' => $this->data[self::PROPERTY_MODIFIED] ?? null, 'modifiedOn' => Timestamp::normalize($this->data[self::PROPERTY_MODIFIED] ?? null),
'signature' => $this->data[self::PROPERTY_SIGNATURE] ?? null, 'signature' => $this->data[self::PROPERTY_SIGNATURE] ?? null,
'enabled' => $this->collectionEnabled, 'enabled' => $this->collectionEnabled,
], static fn($value) => $value !== null); ], static fn($value) => $value !== null);
+2 -2
View File
@@ -47,8 +47,8 @@ class EntityResource extends EntityMutableAbstract {
'uid' => $this->userId, 'uid' => $this->userId,
'cid' => $this->collection(), 'cid' => $this->collection(),
'eid' => $this->identifier(), 'eid' => $this->identifier(),
'createdOn' => $this->data[self::PROPERTY_CREATED] ?? date('c'), 'createdOn' => Timestamp::normalize($this->data[self::PROPERTY_CREATED] ?? null),
'modifiedOn' => date('c'), 'modifiedOn' => Timestamp::normalize($this->data[self::PROPERTY_MODIFIED] ?? null),
], static fn($value) => $value !== null); ], static fn($value) => $value !== null);
$document = array_merge($document, $this->getProperties()->toStore()); $document = array_merge($document, $this->getProperties()->toStore());
+8 -7
View File
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace KTXM\ProviderLocalPeople\Store\Personal; namespace KTXM\ProviderLocalPeople\Store\Personal;
use KTXF\Utile\Timestamp;
use KTXC\Db\DataStore; use KTXC\Db\DataStore;
use KTXF\Resource\Filter\Filter; use KTXF\Resource\Filter\Filter;
use KTXF\Resource\Filter\FilterComparisonOperator; use KTXF\Resource\Filter\FilterComparisonOperator;
@@ -252,7 +253,7 @@ class Store {
$data['uid'] = $userId; $data['uid'] = $userId;
$data['cid'] = UUID::v4(); $data['cid'] = UUID::v4();
$data['signature'] = isset($data['signature']) && is_numeric($data['signature']) ? (int)$data['signature'] : 0; $data['signature'] = isset($data['signature']) && is_numeric($data['signature']) ? (int)$data['signature'] : 0;
$data['createdOn'] = date('c'); $data['createdOn'] = Timestamp::now();
$data['modifiedOn'] = $data['createdOn']; $data['modifiedOn'] = $data['createdOn'];
// create entry // create entry
$result = $this->_store->selectCollection($this->_CollectionTable)->insertOne($data); $result = $this->_store->selectCollection($this->_CollectionTable)->insertOne($data);
@@ -280,7 +281,7 @@ class Store {
if ($cid === null) { if ($cid === null) {
throw new \InvalidArgumentException('Collection identifier is required for modification'); throw new \InvalidArgumentException('Collection identifier is required for modification');
} }
$data['modifiedOn'] = date('c'); $data['modifiedOn'] = Timestamp::now();
unset($data['_id'], $data['tid'], $data['uid'], $data['cid']); unset($data['_id'], $data['tid'], $data['uid'], $data['cid']);
// modify entry // modify entry
$this->_store->selectCollection($this->_CollectionTable)->updateOne( $this->_store->selectCollection($this->_CollectionTable)->updateOne(
@@ -370,8 +371,8 @@ class Store {
/** @var \KTXF\Resource\Range\IRangeDate $rangeDate */ /** @var \KTXF\Resource\Range\IRangeDate $rangeDate */
$rangeDate = $range; $rangeDate = $range;
$query['data.startsOn'] = [ $query['data.startsOn'] = [
'\$gte' => $rangeDate->getStart()->format('c'), '\$gte' => Timestamp::toIso8601($rangeDate->getStart()) ?? throw new \InvalidArgumentException('Invalid epoch millisecond range boundary'),
'\$lte' => $rangeDate->getEnd()->format('c') '\$lte' => Timestamp::toIso8601($rangeDate->getEnd()) ?? throw new \InvalidArgumentException('Invalid epoch millisecond range boundary')
]; ];
} }
} }
@@ -486,7 +487,7 @@ class Store {
$data['uid'] = $userId; $data['uid'] = $userId;
$data['cid'] = $collectionId; $data['cid'] = $collectionId;
$data['eid'] = UUID::v4(); $data['eid'] = UUID::v4();
$data['createdOn'] = date('c'); $data['createdOn'] = Timestamp::now();
$data['createdBy'] = $userId; $data['createdBy'] = $userId;
$data['modifiedOn'] = $data['createdOn']; $data['modifiedOn'] = $data['createdOn'];
$data['modifiedBy'] = $data['createdBy']; $data['modifiedBy'] = $data['createdBy'];
@@ -518,7 +519,7 @@ class Store {
public function entityModify(string $tenantId, string $userId, string $collectionId, string $identifier, EntityResource $entity): EntityResource { public function entityModify(string $tenantId, string $userId, string $collectionId, string $identifier, EntityResource $entity): EntityResource {
// convert entity to store format // convert entity to store format
$data = $entity->toStore(); $data = $entity->toStore();
$data['modifiedOn'] = date('c'); $data['modifiedOn'] = Timestamp::now();
$data['modifiedBy'] = $userId; $data['modifiedBy'] = $userId;
// Remove identifiers from update data (they shouldn't change) // Remove identifiers from update data (they shouldn't change)
unset($data['_id'], $data['tid'], $data['uid'], $data['cid'], $data['eid']); unset($data['_id'], $data['tid'], $data['uid'], $data['cid'], $data['eid']);
@@ -632,7 +633,7 @@ class Store {
'eid' => $eid, 'eid' => $eid,
'operation' => $operation, 'operation' => $operation,
'signature' => $signature, 'signature' => $signature,
'mutatedOn' => time(), 'mutatedOn' => Timestamp::now(),
]); ]);
// update signature as normalized numeric value // update signature as normalized numeric value