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;
use KTXF\Utile\Timestamp;
use KTXF\People\Collection\CollectionMutableAbstract;
use KTXF\Resource\Identifier\CollectionIdentifier;
@@ -73,8 +74,8 @@ class CollectionResource extends CollectionMutableAbstract {
'rank' => $properties->getRank(),
'visibility' => $properties->getVisibility(),
'color' => $properties->getColor(),
'createdOn' => $this->data[self::PROPERTY_CREATED] ?? null,
'modifiedOn' => $this->data[self::PROPERTY_MODIFIED] ?? null,
'createdOn' => Timestamp::normalize($this->data[self::PROPERTY_CREATED] ?? null),
'modifiedOn' => Timestamp::normalize($this->data[self::PROPERTY_MODIFIED] ?? null),
'signature' => $this->data[self::PROPERTY_SIGNATURE] ?? null,
'enabled' => $this->collectionEnabled,
], static fn($value) => $value !== null);
+2 -2
View File
@@ -47,8 +47,8 @@ class EntityResource extends EntityMutableAbstract {
'uid' => $this->userId,
'cid' => $this->collection(),
'eid' => $this->identifier(),
'createdOn' => $this->data[self::PROPERTY_CREATED] ?? date('c'),
'modifiedOn' => date('c'),
'createdOn' => Timestamp::normalize($this->data[self::PROPERTY_CREATED] ?? null),
'modifiedOn' => Timestamp::normalize($this->data[self::PROPERTY_MODIFIED] ?? null),
], static fn($value) => $value !== null);
$document = array_merge($document, $this->getProperties()->toStore());
+8 -7
View File
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace KTXM\ProviderLocalPeople\Store\Personal;
use KTXF\Utile\Timestamp;
use KTXC\Db\DataStore;
use KTXF\Resource\Filter\Filter;
use KTXF\Resource\Filter\FilterComparisonOperator;
@@ -252,7 +253,7 @@ class Store {
$data['uid'] = $userId;
$data['cid'] = UUID::v4();
$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'];
// create entry
$result = $this->_store->selectCollection($this->_CollectionTable)->insertOne($data);
@@ -280,7 +281,7 @@ class Store {
if ($cid === null) {
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']);
// modify entry
$this->_store->selectCollection($this->_CollectionTable)->updateOne(
@@ -370,8 +371,8 @@ class Store {
/** @var \KTXF\Resource\Range\IRangeDate $rangeDate */
$rangeDate = $range;
$query['data.startsOn'] = [
'\$gte' => $rangeDate->getStart()->format('c'),
'\$lte' => $rangeDate->getEnd()->format('c')
'\$gte' => Timestamp::toIso8601($rangeDate->getStart()) ?? throw new \InvalidArgumentException('Invalid epoch millisecond range boundary'),
'\$lte' => Timestamp::toIso8601($rangeDate->getEnd()) ?? throw new \InvalidArgumentException('Invalid epoch millisecond range boundary')
];
}
}
@@ -486,7 +487,7 @@ class Store {
$data['uid'] = $userId;
$data['cid'] = $collectionId;
$data['eid'] = UUID::v4();
$data['createdOn'] = date('c');
$data['createdOn'] = Timestamp::now();
$data['createdBy'] = $userId;
$data['modifiedOn'] = $data['createdOn'];
$data['modifiedBy'] = $data['createdBy'];
@@ -518,7 +519,7 @@ class Store {
public function entityModify(string $tenantId, string $userId, string $collectionId, string $identifier, EntityResource $entity): EntityResource {
// convert entity to store format
$data = $entity->toStore();
$data['modifiedOn'] = date('c');
$data['modifiedOn'] = Timestamp::now();
$data['modifiedBy'] = $userId;
// Remove identifiers from update data (they shouldn't change)
unset($data['_id'], $data['tid'], $data['uid'], $data['cid'], $data['eid']);
@@ -632,7 +633,7 @@ class Store {
'eid' => $eid,
'operation' => $operation,
'signature' => $signature,
'mutatedOn' => time(),
'mutatedOn' => Timestamp::now(),
]);
// update signature as normalized numeric value