diff --git a/docs/components/content/Modify.vue b/docs/components/content/Modify.vue index 1761758..4a5f0f4 100644 --- a/docs/components/content/Modify.vue +++ b/docs/components/content/Modify.vue @@ -151,6 +151,16 @@ const fns: Record< example: "date", tip: 'To produce a date in a given timezone either include the offset in the date string (ex: "2021-01-01T00:00:00-0800") or use the tzDate function.', }, + dayEnd: { + description: `Returns a new Date object with the time set to 23:59:59.999 (local time).`, + return: "Date", + arguments: [ + { + name: "date", + type: "string | Date", + }, + ], + }, dayStart: { description: `Returns a new Date object with the time set to 00:00:00.000 (local time).`, return: "Date", @@ -160,10 +170,39 @@ const fns: Record< type: "string | Date", }, ], - example: "dayStart", }, - dayEnd: { - description: `Returns a new Date object with the time set to 23:59:59 (local).`, + hourEnd: { + description: `Returns a new Date object with the minutes part of the time set to 59:59.999 (local time).`, + return: "Date", + arguments: [ + { + name: "date", + type: "string | Date", + }, + ], + }, + hourStart: { + description: `Returns a new Date object with the minutes part of the time set to 00:00.000 (local time).`, + return: "Date", + arguments: [ + { + name: "date", + type: "string | Date", + }, + ], + }, + minuteEnd: { + description: `Returns a new Date object with the seconds part of the time set to 59.999 (local time).`, + return: "Date", + arguments: [ + { + name: "date", + type: "string | Date", + }, + ], + }, + minuteStart: { + description: `Returns a new Date object with the seconds part of the time set to 00.000 (local time).`, return: "Date", arguments: [ { diff --git a/src/__tests__/dayEnd.spec.ts b/src/__tests__/dayEnd.spec.ts index a1f9c34..fc4fe65 100644 --- a/src/__tests__/dayEnd.spec.ts +++ b/src/__tests__/dayEnd.spec.ts @@ -3,7 +3,7 @@ import { dayEnd } from "../dayEnd" process.env.TZ = "America/New_York" describe("dayEnd", () => { - it("can become the start of the day", () => { + it("can become the end of the day", () => { expect(dayEnd("2023-02-22T12:00:00Z").toISOString()).toBe( "2023-02-23T04:59:59.999Z" ) diff --git a/src/__tests__/hourEnd.spec.ts b/src/__tests__/hourEnd.spec.ts new file mode 100644 index 0000000..d1d1812 --- /dev/null +++ b/src/__tests__/hourEnd.spec.ts @@ -0,0 +1,11 @@ +import { describe, it, expect } from "vitest" +import { hourEnd } from "../hourEnd" +process.env.TZ = "America/New_York" + +describe("hourEnd", () => { + it("can become the end of the hour", () => { + expect(hourEnd("2023-02-22T12:30:00Z").toISOString()).toBe( + "2023-02-22T12:59:59.999Z" + ) + }) +}) diff --git a/src/__tests__/hourStart.spec.ts b/src/__tests__/hourStart.spec.ts new file mode 100644 index 0000000..b297dd2 --- /dev/null +++ b/src/__tests__/hourStart.spec.ts @@ -0,0 +1,11 @@ +import { describe, it, expect } from "vitest" +import { hourStart } from "../hourStart" +process.env.TZ = "America/New_York" + +describe("hourStart", () => { + it("can become the start of the hour", () => { + expect(hourStart("2023-02-22T12:30:00Z").toISOString()).toBe( + "2023-02-22T12:00:00.000Z" + ) + }) +}) diff --git a/src/__tests__/minuteEnd.spec.ts b/src/__tests__/minuteEnd.spec.ts new file mode 100644 index 0000000..0e74b96 --- /dev/null +++ b/src/__tests__/minuteEnd.spec.ts @@ -0,0 +1,11 @@ +import { describe, it, expect } from "vitest" +import { minuteEnd } from "../minuteEnd" +process.env.TZ = "America/New_York" + +describe("minuteEnd", () => { + it("can become the end of the hour", () => { + expect(minuteEnd("2023-02-22T12:30:30Z").toISOString()).toBe( + "2023-02-22T12:30:59.999Z" + ) + }) +}) diff --git a/src/__tests__/minuteStart.spec.ts b/src/__tests__/minuteStart.spec.ts new file mode 100644 index 0000000..7856617 --- /dev/null +++ b/src/__tests__/minuteStart.spec.ts @@ -0,0 +1,11 @@ +import { describe, it, expect } from "vitest" +import { minuteStart } from "../minuteStart" +process.env.TZ = "America/New_York" + +describe("minuteStart", () => { + it("can become the start of the minute", () => { + expect(minuteStart("2023-02-22T12:30:30Z").toISOString()).toBe( + "2023-02-22T12:30:00.000Z" + ) + }) +}) diff --git a/src/hourEnd.ts b/src/hourEnd.ts new file mode 100644 index 0000000..6086560 --- /dev/null +++ b/src/hourEnd.ts @@ -0,0 +1,12 @@ +import { date } from "./date" +import type { DateInput } from "./types" + +/** + * Returns a Date object for end of the given hour. + * @param inputDate - A string or Date object + */ +export function hourEnd(inputDate: DateInput): Date { + const d = date(inputDate) + d.setMinutes(59, 59, 999) + return d +} diff --git a/src/hourStart.ts b/src/hourStart.ts new file mode 100644 index 0000000..0f81b14 --- /dev/null +++ b/src/hourStart.ts @@ -0,0 +1,12 @@ +import { date } from "./date" +import type { DateInput } from "./types" + +/** + * Returns a Date object for start of the given hour. + * @param inputDate - A string or Date object + */ +export function hourStart(inputDate: DateInput): Date { + const d = date(inputDate) + d.setMinutes(0, 0) + return d +} diff --git a/src/minuteEnd.ts b/src/minuteEnd.ts new file mode 100644 index 0000000..f8668db --- /dev/null +++ b/src/minuteEnd.ts @@ -0,0 +1,12 @@ +import { date } from "./date" +import type { DateInput } from "./types" + +/** + * Returns a Date object for end of the given minute. + * @param inputDate - A string or Date object + */ +export function minuteEnd(inputDate: DateInput): Date { + const d = date(inputDate) + d.setSeconds(59, 999) + return d +} diff --git a/src/minuteStart.ts b/src/minuteStart.ts new file mode 100644 index 0000000..eeaf241 --- /dev/null +++ b/src/minuteStart.ts @@ -0,0 +1,12 @@ +import { date } from "./date" +import type { DateInput } from "./types" + +/** + * Returns a Date object for start of the given minute. + * @param inputDate - A string or Date object + */ +export function minuteStart(inputDate: DateInput): Date { + const d = date(inputDate) + d.setSeconds(0) + return d +}