Skip to content

Commit

Permalink
fix(duration): support weeks as final duration grain
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Jul 21, 2024
1 parent 6aa792f commit f99d8ce
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/domain/UniDateTime.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { UnexpectedCodePathError } from '@ehmpathy/error-fns';
import { format, parseISO } from 'date-fns';
import { AsOfGlossary } from 'domain-glossaries';
import { PickOne, withAssure } from 'type-fns';

/**
* a universally unambiguous datetime serialized as a string; yyyy-MM-ddThh:mm:ssZ
Expand Down
3 changes: 3 additions & 0 deletions src/domain/UniDuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PickOne, isPresent } from 'type-fns';

export type UniDuration = AsOfGlossary<
PickOne<{
weeks: number;
days: number;
hours: number;
minutes: number;
Expand All @@ -15,6 +16,8 @@ export type UniDuration = AsOfGlossary<
>;

export const toMilliseconds = (duration: UniDuration): number => {
if (isPresent(duration.weeks))
return duration.weeks * 7 * 24 * 60 * 60 * 1000;
if (isPresent(duration.days)) return duration.days * 24 * 60 * 60 * 1000;
if (isPresent(duration.hours)) return duration.hours * 60 * 60 * 1000;
if (isPresent(duration.minutes)) return duration.minutes * 60 * 1000;
Expand Down

0 comments on commit f99d8ce

Please sign in to comment.