Skip to content

Commit

Permalink
feat: adds hourStart, hourEnd, minuteStart, and minuteEnd
Browse files Browse the repository at this point in the history
* feat: add hour & minute start/end

* docs: add hour & minute start/end

* test: adjusts test hours

---------

Co-authored-by: Gerard Wilkinson <[email protected]>
  • Loading branch information
justin-schroeder and GerryWilko authored Feb 14, 2024
1 parent d860cfe commit 8731b1e
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 4 deletions.
45 changes: 42 additions & 3 deletions docs/components/content/Modify.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>tzDate</code> 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",
Expand All @@ -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: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/dayEnd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/hourEnd.spec.ts
Original file line number Diff line number Diff line change
@@ -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"
)
})
})
11 changes: 11 additions & 0 deletions src/__tests__/hourStart.spec.ts
Original file line number Diff line number Diff line change
@@ -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"
)
})
})
11 changes: 11 additions & 0 deletions src/__tests__/minuteEnd.spec.ts
Original file line number Diff line number Diff line change
@@ -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"
)
})
})
11 changes: 11 additions & 0 deletions src/__tests__/minuteStart.spec.ts
Original file line number Diff line number Diff line change
@@ -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"
)
})
})
12 changes: 12 additions & 0 deletions src/hourEnd.ts
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions src/hourStart.ts
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions src/minuteEnd.ts
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions src/minuteStart.ts
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 8731b1e

Please sign in to comment.