Skip to content

Commit f004595

Browse files
committed
Add string based time
1 parent b0ac6de commit f004595

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

is-first-older/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ import { Meta } from '../index.js'
1717
* @param secondMeta Other action’s metadata.
1818
*/
1919
export function isFirstOlder(
20-
firstMeta: Meta | undefined,
21-
secondMeta: Meta | undefined
20+
firstMeta: Meta | string | undefined,
21+
secondMeta: Meta | string | undefined
2222
): boolean

is-first-older/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ export function isFirstOlder(firstMeta, secondMeta) {
55
return true
66
}
77

8+
if (typeof firstMeta === 'string') {
9+
firstMeta = { id: firstMeta, time: parseInt(firstMeta) }
10+
}
11+
if (typeof secondMeta === 'string') {
12+
secondMeta = { id: secondMeta, time: parseInt(secondMeta) }
13+
}
14+
815
if (firstMeta.time > secondMeta.time) {
916
return false
1017
} else if (firstMeta.time < secondMeta.time) {

is-first-older/index.test.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ function createMeta(id: string, time: number): Meta {
88
}
99

1010
test('compares entries by time', () => {
11-
let a = createMeta('2 a 0', 2)
11+
let a = createMeta('10 a 0', 2)
1212
let b = createMeta('1 a 0', 1)
1313
is(isFirstOlder(a, b), false)
1414
is(isFirstOlder(b, a), true)
15+
is(isFirstOlder('10 a 0', '1 a 0'), false)
16+
is(isFirstOlder('1 a 0', '10 a 0'), true)
1517
})
1618

1719
test('compares entries by real time', () => {
@@ -26,13 +28,17 @@ test('compares entries by other ID parts', () => {
2628
let b = createMeta('1 a 10', 1)
2729
is(isFirstOlder(a, b), true)
2830
is(isFirstOlder(b, a), false)
31+
is(isFirstOlder('1 a 9', '1 a 10'), true)
32+
is(isFirstOlder('1 a 10', '1 a 9'), false)
2933
})
3034

3135
test('compares entries by other ID parts with priority', () => {
3236
let a = createMeta('1 b 1', 1)
3337
let b = createMeta('1 a 2', 1)
3438
is(isFirstOlder(a, b), false)
3539
is(isFirstOlder(b, a), true)
40+
is(isFirstOlder('1 b 1', '1 a 1'), false)
41+
is(isFirstOlder('1 a 1', '1 b 1'), true)
3642
})
3743

3844
test('compares entries with same time', () => {

0 commit comments

Comments
 (0)