Skip to content

Commit 5d68a77

Browse files
committed
Add docs for orderTimestampBytes and timestampToDateIso
1 parent 09f132f commit 5d68a77

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

packages/common/src/local-first/Timestamp.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,21 @@ export const timestampBytesToTimestamp = (
336336
return { millis: Number(millis), counter, nodeId } as Timestamp;
337337
};
338338

339+
/**
340+
* An {@link Order} for {@link TimestampBytes}.
341+
*
342+
* This `Order` uses lexicographic byte order to compare serialized
343+
* {@link TimestampBytes} produced by {@link timestampToTimestampBytes}. See
344+
* {@link orderUint8Array} for the underlying implementation.
345+
*/
339346
export const orderTimestampBytes: Order<TimestampBytes> = orderUint8Array;
340347

348+
/**
349+
* Convert a {@link Timestamp} to an ISO 8601 {@link DateIso} string.
350+
*
351+
* The conversion uses the timestamp's `millis` (a {@link Millis} value) and
352+
* `Date.prototype.toISOString()` to produce a `DateIso`.
353+
*/
341354
export const timestampToDateIso = (timestamp: Timestamp): DateIso =>
342-
// `as DateIso` is safe because the timestamp is always valid
355+
// `as DateIso` is safe because Timestamp guarantees a valid `millis`
343356
new Date(timestamp.millis).toISOString() as DateIso;

0 commit comments

Comments
 (0)