Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/sync/editor/generic/util.ts
5710 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Patch } from "./types";
7
import { cmp_array } from "@cocalc/util/misc";
8
export * from "@cocalc/util/dmp";
9
import { type CompressedPatch } from "@cocalc/util/dmp";
10
export { type CompressedPatch };
11
12
export function patch_cmp(a: Patch, b: Patch): number {
13
return cmp_array(
14
[a.time, a.version, a.user_id],
15
[b.time, b.version, b.user_id],
16
);
17
}
18
19
export function time_cmp(a: Date, b: Date): number {
20
const t = a.valueOf() - b.valueOf();
21
if (t < 0) {
22
return -1;
23
} else if (t > 0) {
24
return 1;
25
} else {
26
return 0;
27
}
28
}
29
30
export function isTestClient(client: any) {
31
return !!client?.isTestClient?.();
32
}
33
34