encodeRevision.php
Table of Contents
Functions
- encodeRevision() : string
- Encodes a date into an ArangoDB `_rev` (revision) string.
Functions
encodeRevision()
Encodes a date into an ArangoDB `_rev` (revision) string.
encodeRevision(string $date[, int|null $count = null ][, bool $throwable = false ]) : string
This function is the inverse of decodeRevision(). It generates a 10–11 character _rev
string from a given date and an optional counter (count). The _rev string encodes
a 64-bit integer composed of:
- A 44-bit timestamp in milliseconds since epoch (UTC).
- A 20-bit counter (
count) to ensure uniqueness for multiple revisions at the same millisecond.
If $count is null, the function automatically increments the counter for multiple
calls within the same millisecond, mimicking ArangoDB's internal behavior.
Parameters
- $date : string
-
The date to encode, in any format accepted by
DateTimeImmutable. Must be UTC or will be converted to UTC. - $count : int|null = null
-
Optional counter for revisions within the same millisecond. If null, automatically incremented for multiple calls in the same millisecond. Must be between 0 and 1048575 (2^20 - 1).
- $throwable : bool = false
-
If true, throws exceptions on error; if false, returns an empty string.
Tags
Return values
string —Returns the encoded _rev string (10–11 characters).
Returns an empty string on error if $throwable is false.