Implement Seconds.add()
This commit is contained in:
parent
6170796433
commit
be5b9a5146
|
|
@ -1,3 +1,7 @@
|
|||
export class Seconds {
|
||||
constructor(readonly value: number) {}
|
||||
|
||||
add(other: Seconds): Seconds {
|
||||
return new Seconds(this.value + other.value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ const countRepetitions = (reference: Interval[], intervals: Interval[], startInd
|
|||
|
||||
const offsetComments = (interval: Interval, baseOffset: Seconds): Comment[] => {
|
||||
return interval.comments.map(({ offset, ...rest }) => ({
|
||||
offset: new Seconds(baseOffset.value + offset.value),
|
||||
offset: baseOffset.add(offset),
|
||||
...rest,
|
||||
}));
|
||||
};
|
||||
|
|
@ -44,7 +44,7 @@ const collectComments = (intervals: Interval[]): Comment[] => {
|
|||
return flatten(
|
||||
intervals.map((interval) => {
|
||||
const comments = offsetComments(interval, previousIntervalsDuration);
|
||||
previousIntervalsDuration = new Seconds(previousIntervalsDuration.value + interval.duration.value);
|
||||
previousIntervalsDuration = previousIntervalsDuration.add(interval.duration);
|
||||
return comments;
|
||||
}),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { map, sum } from "ramda";
|
||||
import { Interval } from "../ast";
|
||||
import { Seconds } from "../Seconds";
|
||||
|
||||
export const totalDuration = (intervals: Interval[]): Seconds =>
|
||||
new Seconds(sum(map((interval) => interval.duration.value, intervals)));
|
||||
intervals.reduce((total, interval) => total.add(interval.duration), new Seconds(0));
|
||||
|
|
|
|||
Loading…
Reference in New Issue