Skip to content
Open
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
20 changes: 8 additions & 12 deletions apps/meteor/client/lib/convertTimeUnit.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
const MS_PER_DAY = 86400000;
const MS_PER_HOUR = 3600000;
const MS_PER_MINUTE = 60000;
export enum TIMEUNIT {
days = 'days',
hours = 'hours',
minutes = 'minutes',
}

export const isValidTimespan = (timespan: number): boolean => {
if (Number.isNaN(timespan)) {
return false;
}

if (!Number.isFinite(timespan)) {
return false;
}

if (timespan < 0) {
// Number.isFinite returns false for NaN, so we can skip the separate NaN check
if (!Number.isFinite(timespan) || timespan < 0) {
return false;
}

Expand Down Expand Up @@ -47,11 +43,11 @@ export const msToTimeUnit = (unit: TIMEUNIT, timespan: number) => {

switch (unit) {
case TIMEUNIT.days:
return timespan / 24 / 60 / 60 / 1000;
return timespan / MS_PER_DAY;
case TIMEUNIT.hours:
return timespan / 60 / 60 / 1000;
return timespan / MS_PER_HOUR;
case TIMEUNIT.minutes:
return timespan / 60 / 1000;
return timespan / MS_PER_MINUTE;
default:
throw new Error('msToTimeUnit - invalid time unit');
}
Expand Down