+ Tempo includes a number of (tree-shakable) helper functions to assist you
+ in your date workarounds. These functions all accept either an ISO
+ 8601 string or a Date object and return a boolean.
+
+
+
{{ fn }}
+
+
+
+
+
+
+
+
+
diff --git a/docs/examples/isAfter.ts b/docs/examples/isAfter.ts
new file mode 100644
index 0000000..d6bc1e8
--- /dev/null
+++ b/docs/examples/isAfter.ts
@@ -0,0 +1,7 @@
+import { isAfter } from "@formkit/tempo"
+
+// Compare when the first date is before the second
+isAfter("2013-03-15", "2013-03-16")
+
+// Compare when the first date is after the second
+isAfter("2013-03-17", "2013-03-16")
diff --git a/docs/examples/isBefore.ts b/docs/examples/isBefore.ts
new file mode 100644
index 0000000..2cf5609
--- /dev/null
+++ b/docs/examples/isBefore.ts
@@ -0,0 +1,7 @@
+import { isBefore } from "@formkit/tempo"
+
+// Compare when the first date is before the second
+isBefore("2013-03-15", "2013-03-16")
+
+// Compare when the first date is after the second
+isBefore("2013-03-17", "2013-03-16")
diff --git a/docs/examples/isEqual.ts b/docs/examples/isEqual.ts
new file mode 100644
index 0000000..0a7ae2e
--- /dev/null
+++ b/docs/examples/isEqual.ts
@@ -0,0 +1,7 @@
+import { isEqual } from "@formkit/tempo"
+
+// Compare when the first date is before the second
+isEqual("2013-03-15", "2013-03-16")
+
+// Compare when the first date is equal with the second
+isEqual("2013-03-16", "2013-03-16")
diff --git a/docs/pages/index.vue b/docs/pages/index.vue
index 8c32492..2b8f9ab 100644
--- a/docs/pages/index.vue
+++ b/docs/pages/index.vue
@@ -13,6 +13,7 @@ definePageMeta({
+
diff --git a/package.json b/package.json
index 92fa499..8c97eb4 100644
--- a/package.json
+++ b/package.json
@@ -25,17 +25,8 @@
"publint": "publint",
"release": "pnpm build && bumpp && pnpm publish"
},
- "files": [
- "dist",
- "docs/public/read-the-docs.png",
- "docs/public/tempo.png"
- ],
- "keywords": [
- "date",
- "time",
- "internationalization",
- "date format"
- ],
+ "files": ["dist", "docs/public/read-the-docs.png", "docs/public/tempo.png"],
+ "keywords": ["date", "time", "internationalization", "date format"],
"author": "Justin Schroeder ",
"license": "MIT",
"devDependencies": {
diff --git a/src/__tests__/isAfter.spec.ts b/src/__tests__/isAfter.spec.ts
new file mode 100644
index 0000000..c021c4d
--- /dev/null
+++ b/src/__tests__/isAfter.spec.ts
@@ -0,0 +1,17 @@
+import { describe, it, expect } from "vitest"
+import { isAfter } from "../isAfter"
+process.env.TZ = "America/New_York"
+
+describe("isAfter", () => {
+ it("returns true if first date is after second", () => {
+ expect(isAfter("2022-01-02", "2022-01-01")).toBe(true)
+ })
+ it("returns true if first date is before second", () => {
+ expect(isAfter("2022-01-01", "2022-01-02")).toBe(false)
+ })
+ it("returns error if date is not valid", () => {
+ expect(() => isAfter("invalid", "2022-01-01")).toThrowError(
+ "Non ISO 8601 compliant date",
+ )
+ })
+})
diff --git a/src/__tests__/isBefore.spec.ts b/src/__tests__/isBefore.spec.ts
new file mode 100644
index 0000000..2bc5968
--- /dev/null
+++ b/src/__tests__/isBefore.spec.ts
@@ -0,0 +1,17 @@
+import { describe, it, expect } from "vitest"
+import { isBefore } from "../isBefore"
+process.env.TZ = "America/New_York"
+
+describe("isBefore", () => {
+ it("returns true if first date is before second", () => {
+ expect(isBefore("2022-01-01", "2022-01-02")).toBe(true)
+ })
+ it("returns false if first date is after second", () => {
+ expect(isBefore("2022-01-02", "2022-01-01")).toBe(false)
+ })
+ it("returns error if date is not valid", () => {
+ expect(() => isBefore("invalid", "2022-01-01")).toThrowError(
+ "Non ISO 8601 compliant date",
+ )
+ })
+})
diff --git a/src/__tests__/isEqual.spec.ts b/src/__tests__/isEqual.spec.ts
new file mode 100644
index 0000000..3330098
--- /dev/null
+++ b/src/__tests__/isEqual.spec.ts
@@ -0,0 +1,17 @@
+import { describe, it, expect } from "vitest"
+import { isEqual } from "../isEqual"
+process.env.TZ = "America/New_York"
+
+describe("isEqual", () => {
+ it("returns false if the given dates are not equal", () => {
+ expect(isEqual("2022-01-01", "2022-01-02")).toBe(false)
+ })
+ it("returns true if the given dates are equal", () => {
+ expect(isEqual("2022-01-01", "2022-01-01")).toBe(true)
+ })
+ it("returns error if date is not valid", () => {
+ expect(() => isEqual("invalid", "2022-01-01")).toThrowError(
+ "Non ISO 8601 compliant date",
+ )
+ })
+})
diff --git a/src/index.ts b/src/index.ts
index 652125d..742ce88 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -33,4 +33,7 @@ export { sameDay } from "./sameDay"
export { weekEnd } from "./weekEnd"
export { weekStart } from "./weekStart"
export { yearDays } from "./yearDays"
+export { isBefore } from "./isBefore"
+export { isAfter } from "./isAfter"
+export { isEqual } from "./isEqual"
export * from "./types"
diff --git a/src/isAfter.ts b/src/isAfter.ts
new file mode 100644
index 0000000..214399f
--- /dev/null
+++ b/src/isAfter.ts
@@ -0,0 +1,22 @@
+import { date } from "./date"
+import type { DateInput } from "./types"
+
+/**
+ * @name isAfter
+ * @category Common Helpers
+ * @summary Is the first date after the second one?
+ *
+ * @description
+ * Is the first date after the second one?
+ *
+ * @param inputDate - The date that should be after the other one to return true
+ * @param dateToCompare - The date to compare with
+ *
+ * @returns The first date is after the second date.
+ */
+export function isAfter(inputDate: DateInput, dateToCompare: DateInput) {
+ const _date = date(inputDate)
+ const _dateToCompare = date(dateToCompare)
+
+ return +_date > +_dateToCompare
+}
diff --git a/src/isBefore.ts b/src/isBefore.ts
new file mode 100644
index 0000000..e2f4763
--- /dev/null
+++ b/src/isBefore.ts
@@ -0,0 +1,17 @@
+import { date } from "./date"
+import type { DateInput } from "./types"
+
+/**
+ * Is the first date before the second one?
+ *
+ * @param inputDate - The date that should be before the other one to return true
+ * @param dateToCompare - The date to compare with
+ *
+ * @returns The first date is before the second date.
+ */
+export function isBefore(inputDate: DateInput, dateToCompare: DateInput) {
+ const _date = date(inputDate)
+ const _dateToCompare = date(dateToCompare)
+
+ return +_date < +_dateToCompare
+}
diff --git a/src/isEqual.ts b/src/isEqual.ts
new file mode 100644
index 0000000..db01b4f
--- /dev/null
+++ b/src/isEqual.ts
@@ -0,0 +1,17 @@
+import { date } from "./date"
+import type { DateInput } from "./types"
+
+/**
+ * Are the given dates equal?
+ *
+ * @param dateLeft - The first date to compare
+ * @param dateRight - The second date to compare
+ *
+ * @returns The dates are equal.
+ */
+export function isEqual(dateLeft: DateInput, dateRight: DateInput) {
+ const _dateLeft = date(dateLeft)
+ const _dateRight = date(dateRight)
+
+ return +_dateLeft === +_dateRight
+}