Skip to content

Commit

Permalink
add utcMonthDay, timeMonthDay
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jun 25, 2023
1 parent 9e8dc94 commit c11a843
Show file tree
Hide file tree
Showing 10 changed files with 387 additions and 363 deletions.
50 changes: 26 additions & 24 deletions src/day.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
import {timeInterval} from "./interval.js";
import {durationDay, durationMinute} from "./duration.js";

export const timeDay = timeInterval(
date => date.setHours(0, 0, 0, 0),
export const timeMonthDay = timeInterval(
(date) => date.setHours(0, 0, 0, 0),
(date, step) => date.setDate(date.getDate() + step),
(start, end) => (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay,
date => date.getDate() - 1
(date) => date.getDate() - 1
);

export const timeMonthDays = timeMonthDay.range;

export const utcMonthDay = timeInterval(
(date) => date.setUTCHours(0, 0, 0, 0),
(date, step) => date.setUTCDate(date.getUTCDate() + step),
(start, end) => (end - start) / durationDay,
(date) => date.getUTCDate() - 1
);

export const utcMonthDays = utcMonthDay.range;

export const timeDay = timeInterval(
(date) => date.setHours(0, 0, 0, 0),
(date, step) => date.setDate(date.getDate() + step),
(start, end) => (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay
);

export const timeDays = timeDay.range;

export const utcDay = timeInterval((date) => {
date.setUTCHours(0, 0, 0, 0);
}, (date, step) => {
date.setUTCDate(date.getUTCDate() + step);
}, (start, end) => {
return (end - start) / durationDay;
}, (date) => {
return date.getUTCDate() - 1;
});
export const utcDay = timeInterval(
(date) => date.setUTCHours(0, 0, 0, 0),
(date, step) => date.setUTCDate(date.getUTCDate() + step),
(start, end) => (end - start) / durationDay,
(date) => Math.floor(date / durationDay)
);

export const utcDays = utcDay.range;

export const unixDay = timeInterval((date) => {
date.setUTCHours(0, 0, 0, 0);
}, (date, step) => {
date.setUTCDate(date.getUTCDate() + step);
}, (start, end) => {
return (end - start) / durationDay;
}, (date) => {
return Math.floor(date / durationDay);
});

export const unixDays = unixDay.range;
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ export {
export {
timeDay,
timeDays,
timeMonthDay,
timeMonthDays,
utcDay,
utcDays,
unixDay,
unixDays
utcMonthDay,
utcMonthDays
} from "./day.js";

export {
Expand Down
4 changes: 2 additions & 2 deletions src/ticks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {millisecond} from "./millisecond.js";
import {second} from "./second.js";
import {timeMinute, utcMinute} from "./minute.js";
import {timeHour, utcHour} from "./hour.js";
import {timeDay, unixDay} from "./day.js";
import {timeDay, utcDay} from "./day.js";
import {timeSunday, utcSunday} from "./week.js";
import {timeMonth, utcMonth} from "./month.js";
import {timeYear, utcYear} from "./year.js";
Expand Down Expand Up @@ -52,7 +52,7 @@ function ticker(year, month, week, day, hour, minute) {
return [ticks, tickInterval];
}

const [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, unixDay, utcHour, utcMinute);
const [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute);
const [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute);

export {utcTicks, utcTickInterval, timeTicks, timeTickInterval};
215 changes: 0 additions & 215 deletions test/day-test.js

This file was deleted.

0 comments on commit c11a843

Please sign in to comment.