diff --git a/src/time/fromDate.js b/src/time/fromDate.js new file mode 100644 index 0000000..41c5e51 --- /dev/null +++ b/src/time/fromDate.js @@ -0,0 +1,15 @@ +import DateValue from './date-value'; + +/** + * Convert a date into an object usable in the exported values. + */ +export default function fromDate(date) { + const result = new DateValue(); + result.year = date.getFullYear(); + result.month = date.getMonth(); + result.day = date.getDate(); + result.hour = date.getHours(); + result.minute = date.getMinutes(); + result.second = date.getSeconds(); + return result; +} diff --git a/src/time/interval-value.js b/src/time/interval-value.js index ee79c77..093324f 100644 --- a/src/time/interval-value.js +++ b/src/time/interval-value.js @@ -1,9 +1,10 @@ import { toStart, toEnd } from './intervals'; +import fromDate from './fromDate'; export default class IntervalValue { constructor(start, end) { - this.start = start; - this.end = end; + this.start = start instanceof Date ? fromDate(start) : start; + this.end = end instanceof Date ? fromDate(end) : end; } toStartDate() {