-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds
hourStart
, hourEnd
, minuteStart
, and minuteEnd
* 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
1 parent
d860cfe
commit 8731b1e
Showing
10 changed files
with
135 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |