chore: Rename @calcom/lib/date-fns to @calcom/lib/dayjs (#19870)
* chore: Rename date-fns to dayjs * Fixed types
This commit is contained in:
1 parent
398ad22868
commit
df55dec553
25 files changed
+39
-31
No files matched your search
@@ -1,50 +0,0 @@
|
||||
import { describe, expect, it, beforeAll, vi } from "vitest";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { stringToDayjs } from "@calcom/prisma/zod-utils";
|
||||
|
||||
beforeAll(() => {
|
||||
vi.setSystemTime(dayjs.utc("2021-06-20T11:59:59Z").toDate());
|
||||
});
|
||||
|
||||
describe("Tests the parsing logic", () => {
|
||||
it("when supplied with no timezone data", async () => {
|
||||
const date = stringToDayjs("2024-02-27T17:00:00");
|
||||
expect(date.toISOString()).toBe("2024-02-27T17:00:00.000Z");
|
||||
});
|
||||
|
||||
it("when supplied with UTC", async () => {
|
||||
const date = stringToDayjs("2024-02-27T17:00:00Z");
|
||||
expect(date.year()).toBe(2024);
|
||||
expect(date.month()).toBe(1);
|
||||
expect(date.date()).toBe(27);
|
||||
expect(date.hour()).toBe(17);
|
||||
expect(date.minute()).toBe(0);
|
||||
expect(date.second()).toBe(0);
|
||||
expect(date.utcOffset()).toBe(0);
|
||||
});
|
||||
|
||||
it("when supplied with UTC- timezone", async () => {
|
||||
const date = stringToDayjs("2024-02-27T17:00:00-05:00");
|
||||
expect(date.year()).toBe(2024);
|
||||
expect(date.month()).toBe(1);
|
||||
expect(date.date()).toBe(27);
|
||||
expect(date.hour()).toBe(17);
|
||||
expect(date.minute()).toBe(0);
|
||||
expect(date.second()).toBe(0);
|
||||
expect(date.utcOffset()).toBe(-300);
|
||||
expect(date.toISOString()).toBe("2024-02-27T22:00:00.000Z");
|
||||
});
|
||||
|
||||
it("when supplied with UTC+ timezone", async () => {
|
||||
const date = stringToDayjs("2024-02-27T17:00:00+05:00");
|
||||
expect(date.year()).toBe(2024);
|
||||
expect(date.month()).toBe(1);
|
||||
expect(date.date()).toBe(27);
|
||||
expect(date.hour()).toBe(17);
|
||||
expect(date.minute()).toBe(0);
|
||||
expect(date.second()).toBe(0);
|
||||
expect(date.utcOffset()).toBe(300);
|
||||
expect(date.toISOString()).toBe("2024-02-27T12:00:00.000Z");
|
||||
});
|
||||
});
|
||||
@@ -17,6 +17,7 @@ import dayjs from "@calcom/dayjs";
|
||||
import { isPasswordValid } from "@calcom/features/auth/lib/isPasswordValid";
|
||||
import type { FieldType as FormBuilderFieldType } from "@calcom/features/form-builder/schema";
|
||||
import { fieldsSchema as formBuilderFieldsSchema } from "@calcom/features/form-builder/schema";
|
||||
import { isSupportedTimeZone } from "@calcom/lib/dayjs";
|
||||
import { emailSchema as emailRegexSchema, emailRegex } from "@calcom/lib/emailSchema";
|
||||
import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSchema";
|
||||
import { zodAttributesQueryValue } from "@calcom/lib/raqb/zod";
|
||||
@@ -247,14 +248,6 @@ export const stringOrNumber = z.union([
|
||||
z.number().int(),
|
||||
]);
|
||||
|
||||
export const stringToDayjs = (val: string) => {
|
||||
const matches = val.match(/([+-]\d{2}:\d{2})$/);
|
||||
const timezone = matches ? matches[1] : "+00:00";
|
||||
return dayjs(val).utcOffset(timezone);
|
||||
};
|
||||
|
||||
export const stringToDayjsZod = z.string().transform(stringToDayjs);
|
||||
|
||||
export const requiredCustomInputSchema = z.union([
|
||||
// string must be given & nonempty
|
||||
z.string().trim().min(1),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// `responses` is merged with it during handleNewBooking call because `responses` schema is dynamic and depends on eventType
|
||||
import z, { ZodNullable, ZodObject, ZodOptional } from "zod";
|
||||
import { isSupportedTimeZone } from "@calcom/lib/date-fns";
|
||||
import { isSupportedTimeZone } from "@calcom/lib/dayjs";
|
||||
// TODO: Move this out of here. Importing from app-store is a circular package dependency.
|
||||
import { routingFormResponseInDbSchema } from "@calcom/app-store/routing-forms/zod";
|
||||
|
||||
|
||||
Reference in new issue
Block a user