Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/common/src/__tests__/test-time.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava';

import Long from 'long';
import { msToTs } from '../time';
import { msOptionalToTs, msToTs } from '../time';

test('msToTs converts to Timestamp', (t) => {
t.deepEqual({ seconds: Long.fromInt(600), nanos: 0 }, msToTs('10 minutes'));
Expand All @@ -10,3 +10,7 @@ test('msToTs converts to Timestamp', (t) => {
test('msToTs converts number to Timestamp', (t) => {
t.deepEqual({ seconds: Long.fromInt(42), nanos: 0 }, msToTs(42000));
});

test('msOptionalToTs converts zero duration to Timestamp', (t) => {
t.deepEqual({ seconds: Long.fromInt(0), nanos: 0 }, msOptionalToTs(0));
});
2 changes: 1 addition & 1 deletion packages/common/src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function msToTs(str: Duration): Timestamp {
}

export function msOptionalToTs(str: Duration | undefined | null): Timestamp | undefined {
return str ? msToTs(str) : undefined;
return str != null ? msToTs(str) : undefined;
}

export function msOptionalToNumber(val: Duration | undefined): number | undefined {
Expand Down