Skip to content

Commit

Permalink
feat: adds dayStart, dayEnd to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-schroeder committed Feb 7, 2024
1 parent 0275358 commit 3ddc85b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/__tests__/tempo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
addMinute,
addSecond,
addHour,
dayStart,
dayEnd,
format,
formatStr,
sameDay,
Expand Down Expand Up @@ -1252,3 +1254,19 @@ describe("nearestDay", () => {
)
})
})

describe("dayStart", () => {
it("can become the start of the day", () => {
expect(dayStart("2023-02-22T12:00:00Z").toISOString()).toBe(
"2023-02-22T05:00:00.000Z"
)
})
})

describe("dayEnd", () => {
it("can become the start of the day", () => {
expect(dayEnd("2023-02-22T12:00:00Z").toISOString()).toBe(
"2023-02-23T04:59:59.999Z"
)
})
})
11 changes: 11 additions & 0 deletions src/dayEnd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { date } from "./date"

/**
* Returns a Date object for end of the given day.
* @param inputDate - A string or Date object
*/
export function dayEnd(inputDate: DateInput): Date {
const d = date(inputDate)
d.setHours(23, 59, 59, 999)
return d
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { ap } from "./ap"
export { applyOffset } from "./applyOffset"
export { date } from "./date"
export { dayOfYear } from "./dayOfYear"
export { dayEnd } from "./dayEnd"
export { dayStart } from "./dayStart"
export { format } from "./format"
export { formatStr } from "./formatStr"
Expand Down

0 comments on commit 3ddc85b

Please sign in to comment.