Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

refactor(packages): share nullable date and snowflake ordering

Hampus9e64398ab700
diff --git a/packages/date_utils/src/DateSerialization.ts b/packages/date_utils/src/DateSerialization.ts
new file mode 100644
index 000000000..bab37354d
--- /dev/null
+++ b/packages/date_utils/src/DateSerialization.ts
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+export function toIsoOrNull(value: Date | null | undefined): string | null {
+ return value ? value.toISOString() : null;
+}
diff --git a/packages/snowflake/src/SnowflakeComparison.ts b/packages/snowflake/src/SnowflakeComparison.ts
new file mode 100644
index 000000000..d0d2227cd
--- /dev/null
+++ b/packages/snowflake/src/SnowflakeComparison.ts
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+export function compareSnowflakes(left: bigint, right: bigint): number {
+ if (left < right) {
+ return -1;
+ }
+ if (left > right) {
+ return 1;
+ }
+ return 0;
+}