@heliosgraphics/epoque 0.0.1-alpha.2 → 0.0.1-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/sync.ts +17 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heliosgraphics/epoque",
3
- "version": "0.0.1-alpha.2",
3
+ "version": "0.0.1-alpha.3",
4
4
  "author": "Chris Puska <chris@puska.org>",
5
5
  "description": "sync a local folder",
6
6
  "type": "module",
package/src/sync.ts CHANGED
@@ -35,10 +35,25 @@ const EMPTY_SUMMARY: SyncSummary = {
35
35
  const isUuid = (value: string): boolean =>
36
36
  /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)
37
37
 
38
+ const TIMEZONE_PATTERN: RegExp = /[zZ]|[+-]\d{2}:?\d{2}$/
39
+ const TIME_PATTERN: RegExp = /T|\d{2}:\d{2}/
40
+
41
+ const parseRemoteTime = (value: string | null | undefined): number | null => {
42
+ const trimmed = value?.trim()
43
+ if (!trimmed) return null
44
+
45
+ const normalized = TIME_PATTERN.test(trimmed) ? trimmed.replace(" ", "T") : `${trimmed}T00:00:00`
46
+ const withTimezone = TIMEZONE_PATTERN.test(normalized) ? normalized : `${normalized}Z`
47
+ const parsed = Date.parse(withTimezone)
48
+
49
+ return Number.isNaN(parsed) ? null : parsed
50
+ }
51
+
38
52
  const isAfter = (left: string | null | undefined, right: string | null | undefined): boolean => {
39
- if (!left || !right) return false
53
+ const leftTime = parseRemoteTime(left)
54
+ const rightTime = parseRemoteTime(right)
40
55
 
41
- return new Date(left).getTime() > new Date(right).getTime()
56
+ return leftTime !== null && rightTime !== null && leftTime > rightTime
42
57
  }
43
58
 
44
59
  const getCollectionSearchTerms = (input: string): Array<string> => {