Skip to content

Commit

Permalink
feat(time): Convert Date into DateValue for intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
aholstenson committed Oct 25, 2018
1 parent 78cbdca commit bee75e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/time/fromDate.js
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 3 additions & 2 deletions src/time/interval-value.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down

0 comments on commit bee75e6

Please sign in to comment.