Skip to content

Commit

Permalink
Simplify intervals.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Feb 4, 2019
1 parent d8b70e8 commit 3576d62
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/hour.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import interval from "./interval";
import {durationHour, durationMinute} from "./duration";
import {durationHour, durationMinute, durationSecond} from "./duration";

var hour = interval(function(date) {
var offset = date.getTimezoneOffset() * durationMinute % durationHour;
if (offset < 0) offset += durationHour;
date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
}, function(date, step) {
date.setTime(+date + step * durationHour);
}, function(start, end) {
Expand Down
4 changes: 2 additions & 2 deletions src/minute.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import interval from "./interval";
import {durationMinute} from "./duration";
import {durationMinute, durationSecond} from "./duration";

var minute = interval(function(date) {
date.setTime(Math.floor(date / durationMinute) * durationMinute);
date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
}, function(date, step) {
date.setTime(+date + step * durationMinute);
}, function(start, end) {
Expand Down
2 changes: 1 addition & 1 deletion src/second.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import interval from "./interval";
import {durationSecond} from "./duration";

var second = interval(function(date) {
date.setTime(Math.floor(date / durationSecond) * durationSecond);
date.setTime(date - date.getMilliseconds());
}, function(date, step) {
date.setTime(+date + step * durationSecond);
}, function(start, end) {
Expand Down

0 comments on commit 3576d62

Please sign in to comment.