aboutsummaryrefslogtreecommitdiff
path: root/src/duration.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/duration.ts')
-rw-r--r--src/duration.ts38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/duration.ts b/src/duration.ts
index b42b53b..34ccb91 100644
--- a/src/duration.ts
+++ b/src/duration.ts
@@ -2,6 +2,11 @@ import moment from 'moment';
export type TimeUnit = moment.unitOfTime.DurationConstructor;
+export type DurationFlat = {
+ value: number,
+ unit: string
+};
+
export class Duration {
value: number;
unit: TimeUnit;
@@ -22,11 +27,36 @@ export class Duration {
static months(n: number) { return new Duration(n, 'months'); }
deflate() { return { value: this.value, unit: this.unit }; }
- static inflate = (obj: { value: number, unit: TimeUnit }) => new Duration(obj.value, obj.unit);
+ static inflate = (obj: DurationFlat) => new Duration(obj.value, obj.unit as TimeUnit);
}
-export type TrackPeriod = {
+
+export type TrackPeriodFlat = {
name: string,
- start: Duration,
- end: Duration
+ start: DurationFlat,
+ end: DurationFlat
};
+
+export class TrackPeriod {
+ name: string;
+ start: Duration;
+ end: Duration;
+
+ constructor(name: string, start: Duration, end: Duration) {
+ this.name = name;
+ this.start = start;
+ this.end = end;
+ }
+
+ deflate() {
+ return {
+ name: this.name,
+ start: this.start.deflate(),
+ end: this.end.deflate()
+ };
+ }
+
+ static inflate = (obj: TrackPeriodFlat) => (
+ new TrackPeriod(obj.name, Duration.inflate(obj.start), Duration.inflate(obj.end))
+ );
+}