Skip to content

Commit

Permalink
front: introduce Duration type
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Ser <[email protected]>
References: #8816
  • Loading branch information
emersion committed Dec 23, 2024
1 parent 05f2923 commit 0c40b37
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions front/src/utils/duration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import dayjs from 'dayjs';

// eslint-disable-next-line import/prefer-default-export
export class Duration {
readonly ms: number;

constructor(ms: number) {
this.ms = ms;
}

static zero = new Duration(0);

static parse(str: string) {
return new Duration(dayjs.duration(str).asMilliseconds());
}

static subtractDate(a: Date, b: Date) {
return new Duration(a.getTime() - b.getTime());
}

valueOf() {
return this.ms;
}

toString() {
return dayjs.duration(this.ms).toISOString();
}
}

0 comments on commit 0c40b37

Please sign in to comment.