@bash-app/bash-common 30.449.0 → 30.451.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/eventTimezoneIana.test.js +35 -5
- package/dist/__tests__/eventTimezoneIana.test.js.map +1 -1
- package/dist/bashEventWizardSave.d.ts +38 -0
- package/dist/bashEventWizardSave.d.ts.map +1 -0
- package/dist/bashEventWizardSave.js +80 -0
- package/dist/bashEventWizardSave.js.map +1 -0
- package/dist/definitions.d.ts +2 -0
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js.map +1 -1
- package/dist/extendedSchemas.d.ts +4 -0
- package/dist/extendedSchemas.d.ts.map +1 -1
- package/dist/extendedSchemas.js +4 -0
- package/dist/extendedSchemas.js.map +1 -1
- package/dist/hostCrmCrowdPulse.d.ts +5 -0
- package/dist/hostCrmCrowdPulse.d.ts.map +1 -1
- package/dist/hostCrmCrowdPulse.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/serviceWizardSave.d.ts +23 -0
- package/dist/serviceWizardSave.d.ts.map +1 -0
- package/dist/serviceWizardSave.js +68 -0
- package/dist/serviceWizardSave.js.map +1 -0
- package/dist/utils/__tests__/eventTimezoneIana.test.js +5 -7
- package/dist/utils/__tests__/eventTimezoneIana.test.js.map +1 -1
- package/dist/utils/__tests__/recurrenceUtils.dst.test.d.ts +2 -0
- package/dist/utils/__tests__/recurrenceUtils.dst.test.d.ts.map +1 -0
- package/dist/utils/__tests__/recurrenceUtils.dst.test.js +60 -0
- package/dist/utils/__tests__/recurrenceUtils.dst.test.js.map +1 -0
- package/dist/utils/eventTimezoneIana.d.ts +24 -5
- package/dist/utils/eventTimezoneIana.d.ts.map +1 -1
- package/dist/utils/eventTimezoneIana.js +101 -6
- package/dist/utils/eventTimezoneIana.js.map +1 -1
- package/dist/utils/recurrenceUtils.d.ts.map +1 -1
- package/dist/utils/recurrenceUtils.js +15 -3
- package/dist/utils/recurrenceUtils.js.map +1 -1
- package/package.json +1 -1
- package/prisma/schema.prisma +46 -0
- package/src/__tests__/eventTimezoneIana.test.ts +47 -4
- package/src/bashEventWizardSave.ts +126 -0
- package/src/definitions.ts +2 -0
- package/src/extendedSchemas.ts +4 -0
- package/src/hostCrmCrowdPulse.ts +5 -0
- package/src/index.ts +6 -0
- package/src/serviceWizardSave.ts +104 -0
- package/src/utils/__tests__/eventTimezoneIana.test.ts +5 -7
- package/src/utils/__tests__/recurrenceUtils.dst.test.ts +94 -0
- package/src/utils/eventTimezoneIana.ts +124 -7
- package/src/utils/recurrenceUtils.ts +17 -5
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { BashStatus } from "@prisma/client";
|
|
2
|
+
|
|
3
|
+
import type { BashEventExt } from "./extendedSchemas.js";
|
|
4
|
+
import type { DeepPartial } from "./utils/typeUtils.js";
|
|
5
|
+
|
|
6
|
+
/** Drafts and ideas autosave; live bashes use explicit Save changes. */
|
|
7
|
+
export function bashEventWizardUsesExplicitSave(
|
|
8
|
+
status: BashStatus | null | undefined
|
|
9
|
+
): boolean {
|
|
10
|
+
if (status == null) return false;
|
|
11
|
+
return status !== BashStatus.Draft && status !== BashStatus.Idea;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const BASH_EVENT_PENDING_EDIT_TTL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
15
|
+
|
|
16
|
+
export type BashEventPendingEditWire = {
|
|
17
|
+
bashEventId: string;
|
|
18
|
+
userId: string;
|
|
19
|
+
baseVersion: number;
|
|
20
|
+
baseSnapshot: Record<string, unknown>;
|
|
21
|
+
changes: DeepPartial<BashEventExt>;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Recent co-editors on a published bash wizard (presence poll). */
|
|
27
|
+
export type BashEventWizardEditorWire = {
|
|
28
|
+
userId: string;
|
|
29
|
+
displayName: string;
|
|
30
|
+
updatedAt: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** Editors with pending activity within this window appear in presence UI. */
|
|
34
|
+
export const BASH_EVENT_WIZARD_EDITOR_ACTIVE_MS = 2 * 60 * 1000;
|
|
35
|
+
|
|
36
|
+
export type BashEventApplyPendingResult = {
|
|
37
|
+
applied: DeepPartial<BashEventExt>;
|
|
38
|
+
conflicts: string[];
|
|
39
|
+
editVersion: number;
|
|
40
|
+
bashEvent: BashEventExt;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** Top-level keys hosts usually edit in the wizard (conflict + snapshot scope). */
|
|
44
|
+
export const BASH_EVENT_PENDING_EDIT_SNAPSHOT_KEYS = [
|
|
45
|
+
"title",
|
|
46
|
+
"subtitle",
|
|
47
|
+
"description",
|
|
48
|
+
"startDateTime",
|
|
49
|
+
"endDateTime",
|
|
50
|
+
"timezone",
|
|
51
|
+
"location",
|
|
52
|
+
"street",
|
|
53
|
+
"city",
|
|
54
|
+
"state",
|
|
55
|
+
"zipCode",
|
|
56
|
+
"country",
|
|
57
|
+
"coordinates",
|
|
58
|
+
"capacity",
|
|
59
|
+
"privacy",
|
|
60
|
+
"coverPhoto",
|
|
61
|
+
"videoLink",
|
|
62
|
+
"ticketTiers",
|
|
63
|
+
"competitions",
|
|
64
|
+
"sideQuests",
|
|
65
|
+
"recurrence",
|
|
66
|
+
] as const;
|
|
67
|
+
|
|
68
|
+
export function buildBashEventPendingBaseSnapshot(
|
|
69
|
+
bash: BashEventExt
|
|
70
|
+
): Record<string, unknown> {
|
|
71
|
+
const snap: Record<string, unknown> = {};
|
|
72
|
+
for (const key of BASH_EVENT_PENDING_EDIT_SNAPSHOT_KEYS) {
|
|
73
|
+
if (key in bash) {
|
|
74
|
+
snap[key] = (bash as Record<string, unknown>)[key];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return snap;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function countBashEventPendingTopLevelChanges(
|
|
81
|
+
changes: DeepPartial<BashEventExt>
|
|
82
|
+
): number {
|
|
83
|
+
return Object.keys(changes).filter((k) => k !== "id" && k !== "creatorId")
|
|
84
|
+
.length;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const BASH_EVENT_HIGH_IMPACT_SAVE_KEYS = [
|
|
88
|
+
"startDateTime",
|
|
89
|
+
"endDateTime",
|
|
90
|
+
"timezone",
|
|
91
|
+
"location",
|
|
92
|
+
"street",
|
|
93
|
+
"city",
|
|
94
|
+
"state",
|
|
95
|
+
"zipCode",
|
|
96
|
+
"country",
|
|
97
|
+
"coordinates",
|
|
98
|
+
"capacity",
|
|
99
|
+
"ticketTiers",
|
|
100
|
+
] as const;
|
|
101
|
+
|
|
102
|
+
export function bashEventPendingHasHighImpactChanges(
|
|
103
|
+
changes: DeepPartial<BashEventExt>
|
|
104
|
+
): boolean {
|
|
105
|
+
return BASH_EVENT_HIGH_IMPACT_SAVE_KEYS.some((key) => key in changes);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function pendingEditLocalStorageKey(
|
|
109
|
+
bashEventId: string,
|
|
110
|
+
userId: string
|
|
111
|
+
): string {
|
|
112
|
+
return `bashPendingEdit:${bashEventId}:${userId}`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function valuesEqualForPendingConflict(
|
|
116
|
+
a: unknown,
|
|
117
|
+
b: unknown
|
|
118
|
+
): boolean {
|
|
119
|
+
if (a === b) return true;
|
|
120
|
+
if (a == null && b == null) return true;
|
|
121
|
+
try {
|
|
122
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
123
|
+
} catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
package/src/definitions.ts
CHANGED
|
@@ -390,6 +390,8 @@ export type DoorConfigPublic = {
|
|
|
390
390
|
squareLocationReady: boolean;
|
|
391
391
|
/** How this viewer may use the door app. Omitted on older API. */
|
|
392
392
|
viewerDoorAccess?: "none" | "pin" | "staff";
|
|
393
|
+
eventTitle?: string | null;
|
|
394
|
+
eventWhenLabel?: string | null;
|
|
393
395
|
};
|
|
394
396
|
|
|
395
397
|
/** Door scanner: ticket QR verification result. */
|
package/src/extendedSchemas.ts
CHANGED
|
@@ -277,6 +277,10 @@ export type PublicTeaserUser = Prisma.UserGetPayload<{
|
|
|
277
277
|
|
|
278
278
|
export const PRIVATE_USER_ACCOUNT_TO_SELECT = {
|
|
279
279
|
...FRONT_END_USER_DATA_TO_SELECT,
|
|
280
|
+
/** Self-only payment destinations; never include these in public profiles. */
|
|
281
|
+
venmoUsername: true,
|
|
282
|
+
zelleEmail: true,
|
|
283
|
+
zellePhone: true,
|
|
280
284
|
/** Self session only. Preferred payment rail (Stripe vs Square). */
|
|
281
285
|
paymentProvider: true,
|
|
282
286
|
// Self-only sensitive demographics. Re-added so /me can populate edit forms.
|
package/src/hostCrmCrowdPulse.ts
CHANGED
|
@@ -68,6 +68,11 @@ export type HostCrmCrowdPulseBash = {
|
|
|
68
68
|
title: string;
|
|
69
69
|
startDateTime: string | null;
|
|
70
70
|
endDateTime: string | null;
|
|
71
|
+
timezone?: string | null;
|
|
72
|
+
city?: string | null;
|
|
73
|
+
state?: string | null;
|
|
74
|
+
country?: string | null;
|
|
75
|
+
location?: string | null;
|
|
71
76
|
horizon: HostCrmCrowdPulseHorizon;
|
|
72
77
|
/** Distinct people with Going + Approved RSVP. */
|
|
73
78
|
goingCount: number;
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,8 @@ export * from "./sms/smsTemplates.js";
|
|
|
7
7
|
export * from "./legalTemplates.js";
|
|
8
8
|
export * from "./vendorBookingAgreement.js";
|
|
9
9
|
export * from "./partnerBookingAgreement.js";
|
|
10
|
+
export * from "./bashEventWizardSave.js";
|
|
11
|
+
export * from "./serviceWizardSave.js";
|
|
10
12
|
export * from "./utmAttribution.js";
|
|
11
13
|
export * from "./venueLoyaltyRedemption.js";
|
|
12
14
|
export * from "./stripeListingSubscriptionMessages.js";
|
|
@@ -389,6 +391,10 @@ export {
|
|
|
389
391
|
getIanaTimezoneFromCoordinates,
|
|
390
392
|
getIanaTimezoneFromLocationStringHints,
|
|
391
393
|
inferEventTimezoneIana,
|
|
394
|
+
defaultEventTimezoneIana,
|
|
395
|
+
formatEventTimezoneAbbrev,
|
|
396
|
+
EVENT_TIMEZONE_PICKER_ZONES,
|
|
397
|
+
formatBashEventWhenLabel,
|
|
392
398
|
resolveEventTimezoneIanaForDisplay,
|
|
393
399
|
} from "./utils/eventTimezoneIana.js";
|
|
394
400
|
export type {
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ServiceCondition } from "@prisma/client";
|
|
2
|
+
|
|
3
|
+
import type { ServiceExt } from "./extendedSchemas.js";
|
|
4
|
+
import type { DeepPartial } from "./utils/typeUtils.js";
|
|
5
|
+
import { BASH_EVENT_PENDING_EDIT_TTL_MS } from "./bashEventWizardSave.js";
|
|
6
|
+
|
|
7
|
+
/** Draft / pending listings autosave; published profiles use explicit Save changes. */
|
|
8
|
+
export function serviceWizardUsesExplicitSave(
|
|
9
|
+
serviceCondition: ServiceCondition | null | undefined
|
|
10
|
+
): boolean {
|
|
11
|
+
return serviceCondition === ServiceCondition.Published;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ServicePendingEditWire = {
|
|
15
|
+
serviceId: string;
|
|
16
|
+
userId: string;
|
|
17
|
+
baseVersion: number;
|
|
18
|
+
baseSnapshot: Record<string, unknown>;
|
|
19
|
+
changes: DeepPartial<ServiceExt>;
|
|
20
|
+
updatedAt: string;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const SERVICE_PENDING_EDIT_SNAPSHOT_KEYS = [
|
|
25
|
+
"serviceName",
|
|
26
|
+
"tagline",
|
|
27
|
+
"description",
|
|
28
|
+
"place",
|
|
29
|
+
"googlePlaceId",
|
|
30
|
+
"street",
|
|
31
|
+
"city",
|
|
32
|
+
"state",
|
|
33
|
+
"zipCode",
|
|
34
|
+
"country",
|
|
35
|
+
"latitude",
|
|
36
|
+
"longitude",
|
|
37
|
+
"coverPhoto",
|
|
38
|
+
"backgroundImage",
|
|
39
|
+
"availableHours",
|
|
40
|
+
"mission",
|
|
41
|
+
"communityInvolvement",
|
|
42
|
+
"contactDetails",
|
|
43
|
+
"cancellationPolicy",
|
|
44
|
+
"allowsInstantBooking",
|
|
45
|
+
"showAvailabilityOnProfile",
|
|
46
|
+
"bookingIntent",
|
|
47
|
+
"visibility",
|
|
48
|
+
"serviceRatesAssociation",
|
|
49
|
+
"media",
|
|
50
|
+
] as const;
|
|
51
|
+
|
|
52
|
+
type ServicePendingSnapshotKey = Extract<
|
|
53
|
+
(typeof SERVICE_PENDING_EDIT_SNAPSHOT_KEYS)[number],
|
|
54
|
+
keyof ServiceExt
|
|
55
|
+
>;
|
|
56
|
+
|
|
57
|
+
export function buildServicePendingBaseSnapshot(
|
|
58
|
+
service: ServiceExt
|
|
59
|
+
): Record<string, unknown> {
|
|
60
|
+
const snap: Record<string, unknown> = {};
|
|
61
|
+
for (const key of SERVICE_PENDING_EDIT_SNAPSHOT_KEYS) {
|
|
62
|
+
if (key in service) {
|
|
63
|
+
snap[key] = service[key as ServicePendingSnapshotKey];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return snap;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function countServicePendingTopLevelChanges(
|
|
70
|
+
changes: DeepPartial<ServiceExt>
|
|
71
|
+
): number {
|
|
72
|
+
return Object.keys(changes).filter((k) => k !== "id" && k !== "ownerId")
|
|
73
|
+
.length;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const SERVICE_HIGH_IMPACT_SAVE_KEYS = [
|
|
77
|
+
"serviceName",
|
|
78
|
+
"place",
|
|
79
|
+
"street",
|
|
80
|
+
"city",
|
|
81
|
+
"state",
|
|
82
|
+
"zipCode",
|
|
83
|
+
"country",
|
|
84
|
+
"latitude",
|
|
85
|
+
"longitude",
|
|
86
|
+
"availableHours",
|
|
87
|
+
"serviceRatesAssociation",
|
|
88
|
+
"cancellationPolicy",
|
|
89
|
+
] as const;
|
|
90
|
+
|
|
91
|
+
export function servicePendingHasHighImpactChanges(
|
|
92
|
+
changes: DeepPartial<ServiceExt>
|
|
93
|
+
): boolean {
|
|
94
|
+
return SERVICE_HIGH_IMPACT_SAVE_KEYS.some((key) => key in changes);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function servicePendingEditLocalStorageKey(
|
|
98
|
+
serviceId: string,
|
|
99
|
+
userId: string
|
|
100
|
+
): string {
|
|
101
|
+
return `servicePendingEdit:${serviceId}:${userId}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { BASH_EVENT_PENDING_EDIT_TTL_MS as SERVICE_PENDING_EDIT_TTL_MS };
|
|
@@ -68,17 +68,14 @@ describe("eventTimezoneIana", () => {
|
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
describe("resolveEventTimezoneIanaForDisplay", () => {
|
|
71
|
-
it("prefers
|
|
72
|
-
// Regression: an event in Utah (state: UT) had timezone: "America/New_York"
|
|
73
|
-
// stored incorrectly, causing the BashCard to show EDT instead of MDT.
|
|
74
|
-
// Geographic data should win when it has an opinion.
|
|
71
|
+
it("prefers stored timezone when the host chose a zone", () => {
|
|
75
72
|
expect(
|
|
76
73
|
resolveEventTimezoneIanaForDisplay({
|
|
77
74
|
timezone: "America/New_York",
|
|
78
75
|
state: "UT",
|
|
79
76
|
country: "USA",
|
|
80
77
|
})
|
|
81
|
-
).toBe("America/
|
|
78
|
+
).toBe("America/New_York");
|
|
82
79
|
});
|
|
83
80
|
|
|
84
81
|
it("falls back to stored timezone when no geographic clues exist", () => {
|
|
@@ -90,15 +87,16 @@ describe("eventTimezoneIana", () => {
|
|
|
90
87
|
).toBe("America/Los_Angeles");
|
|
91
88
|
});
|
|
92
89
|
|
|
93
|
-
it("
|
|
90
|
+
it("uses host profile zone before inferring from address when timezone is missing", () => {
|
|
94
91
|
expect(
|
|
95
92
|
resolveEventTimezoneIanaForDisplay({
|
|
96
93
|
timezone: null,
|
|
97
94
|
city: "Ogden",
|
|
98
95
|
state: "UT",
|
|
99
96
|
country: "United States",
|
|
97
|
+
hostTimeZone: "America/Los_Angeles",
|
|
100
98
|
})
|
|
101
|
-
).toBe("America/
|
|
99
|
+
).toBe("America/Los_Angeles");
|
|
102
100
|
});
|
|
103
101
|
|
|
104
102
|
it("returns stored timezone for a Park City UT event that also has correct stored timezone", () => {
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { DateTime } from "luxon";
|
|
2
|
+
import {
|
|
3
|
+
DayOfWeek,
|
|
4
|
+
RecurrenceEndsType,
|
|
5
|
+
RecurringFrequency,
|
|
6
|
+
type Recurrence,
|
|
7
|
+
} from "@prisma/client";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
getRecurringBashEventPossibleLuxonTimes,
|
|
11
|
+
} from "../recurrenceUtils.js";
|
|
12
|
+
|
|
13
|
+
function buildWeeklyRecurrence(repeatOnDays: DayOfWeek[]): Recurrence {
|
|
14
|
+
return {
|
|
15
|
+
id: "rec-dst",
|
|
16
|
+
bashEventId: "evt-dst",
|
|
17
|
+
interval: 1,
|
|
18
|
+
frequency: RecurringFrequency.Weekly,
|
|
19
|
+
ends: null,
|
|
20
|
+
repeatCount: 0,
|
|
21
|
+
endsType: RecurrenceEndsType.NEVER,
|
|
22
|
+
repeatOnDays,
|
|
23
|
+
repeatOnDayOfMonth: null,
|
|
24
|
+
repeatYearlyDate: null,
|
|
25
|
+
createdAt: new Date(),
|
|
26
|
+
updatedAt: new Date(),
|
|
27
|
+
occurrenceOverrides: null,
|
|
28
|
+
excludedDates: [],
|
|
29
|
+
} as Recurrence;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe("weekly recurrence wall clock in event timezone (DST)", () => {
|
|
33
|
+
const zone = "America/New_York";
|
|
34
|
+
|
|
35
|
+
it("keeps 7 PM local across US spring forward (March 2024)", () => {
|
|
36
|
+
// Thursday March 7, 2024 7:00 PM ET — before DST; series continues through spring forward.
|
|
37
|
+
const startLocal = DateTime.fromObject(
|
|
38
|
+
{ year: 2024, month: 3, day: 7, hour: 19, minute: 0 },
|
|
39
|
+
{ zone }
|
|
40
|
+
);
|
|
41
|
+
const startUtc = startLocal.toUTC().toJSDate();
|
|
42
|
+
const recurrence = buildWeeklyRecurrence([DayOfWeek.Thursday]);
|
|
43
|
+
|
|
44
|
+
const occ = getRecurringBashEventPossibleLuxonTimes(
|
|
45
|
+
startUtc,
|
|
46
|
+
recurrence,
|
|
47
|
+
zone
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(occ.length).toBeGreaterThanOrEqual(4);
|
|
51
|
+
|
|
52
|
+
const aroundDst = occ.filter((dt) => {
|
|
53
|
+
const local = dt.setZone(zone);
|
|
54
|
+
return local.month === 3 && local.day >= 7 && local.day <= 28;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(aroundDst.length).toBeGreaterThanOrEqual(3);
|
|
58
|
+
for (const dt of aroundDst) {
|
|
59
|
+
const local = dt.setZone(zone);
|
|
60
|
+
expect(local.hour).toBe(19);
|
|
61
|
+
expect(local.minute).toBe(0);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("keeps 7 PM local across US fall back (November 2024)", () => {
|
|
66
|
+
const startLocal = DateTime.fromObject(
|
|
67
|
+
{ year: 2024, month: 10, day: 31, hour: 19, minute: 0 },
|
|
68
|
+
{ zone }
|
|
69
|
+
);
|
|
70
|
+
const startUtc = startLocal.toUTC().toJSDate();
|
|
71
|
+
const recurrence = buildWeeklyRecurrence([DayOfWeek.Thursday]);
|
|
72
|
+
|
|
73
|
+
const occ = getRecurringBashEventPossibleLuxonTimes(
|
|
74
|
+
startUtc,
|
|
75
|
+
recurrence,
|
|
76
|
+
zone
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const aroundFallback = occ.filter((dt) => {
|
|
80
|
+
const local = dt.setZone(zone);
|
|
81
|
+
return (
|
|
82
|
+
(local.month === 10 && local.day >= 31) ||
|
|
83
|
+
(local.month === 11 && local.day <= 14)
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(aroundFallback.length).toBeGreaterThanOrEqual(2);
|
|
88
|
+
for (const dt of aroundFallback) {
|
|
89
|
+
const local = dt.setZone(zone);
|
|
90
|
+
expect(local.hour).toBe(19);
|
|
91
|
+
expect(local.minute).toBe(0);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DateTime } from "luxon";
|
|
2
|
+
|
|
1
3
|
/** Primary IANA zone for each US state + DC (contiguous conventions; AZ/HI/AK use canonical zones). */
|
|
2
4
|
const US_STATE_CODE_TO_IANA: Record<string, string> = {
|
|
3
5
|
AL: "America/Chicago",
|
|
@@ -328,23 +330,138 @@ export function inferEventTimezoneIana(args: InferEventTimezoneArgs): string {
|
|
|
328
330
|
|
|
329
331
|
export type ResolveEventTimezoneForDisplayArgs = InferEventTimezoneArgs & {
|
|
330
332
|
timezone?: string | null;
|
|
333
|
+
/** Host profile zone — used for legacy rows with null `timezone`. */
|
|
334
|
+
hostTimeZone?: string | null;
|
|
331
335
|
};
|
|
332
336
|
|
|
337
|
+
function eventHasLocationHint(args: InferEventTimezoneArgs): boolean {
|
|
338
|
+
return !!(
|
|
339
|
+
args.location?.trim() ||
|
|
340
|
+
args.city?.trim() ||
|
|
341
|
+
(args.latitude != null && args.longitude != null)
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
333
345
|
/**
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
* been set by AI or defaulted incorrectly. Falls back to the stored IANA only when
|
|
337
|
-
* geographic inference produces no opinion (returns UTC). Never uses the viewer's
|
|
338
|
-
* device timezone.
|
|
346
|
+
* Default zone while editing: venue/location inference when a place is set,
|
|
347
|
+
* otherwise the host profile zone.
|
|
339
348
|
*/
|
|
340
|
-
export function
|
|
341
|
-
args:
|
|
349
|
+
export function defaultEventTimezoneIana(
|
|
350
|
+
args: InferEventTimezoneArgs & { hostTimeZone?: string | null }
|
|
342
351
|
): string {
|
|
352
|
+
if (eventHasLocationHint(args)) {
|
|
353
|
+
const fromPlace = inferEventTimezoneIana(args);
|
|
354
|
+
if (fromPlace !== "UTC") return fromPlace;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const host = args.hostTimeZone?.trim();
|
|
358
|
+
if (host && isValidIanaTimezone(host)) return host;
|
|
359
|
+
|
|
343
360
|
const inferred = inferEventTimezoneIana(args);
|
|
344
361
|
if (inferred !== "UTC") return inferred;
|
|
345
362
|
|
|
363
|
+
return host && isValidIanaTimezone(host) ? host : "UTC";
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Short zone label for UI (e.g. ET, MDT). Uses the event instant when provided
|
|
368
|
+
* so labels follow DST.
|
|
369
|
+
*/
|
|
370
|
+
export function formatEventTimezoneAbbrev(
|
|
371
|
+
iana: string | null | undefined,
|
|
372
|
+
at?: Date | DateTime
|
|
373
|
+
): string {
|
|
374
|
+
const zone = iana?.trim();
|
|
375
|
+
if (!zone || !isValidIanaTimezone(zone)) return "";
|
|
376
|
+
|
|
377
|
+
const dt =
|
|
378
|
+
at instanceof DateTime
|
|
379
|
+
? at
|
|
380
|
+
: at instanceof Date
|
|
381
|
+
? DateTime.fromJSDate(at, { zone: "utc" })
|
|
382
|
+
: DateTime.now();
|
|
383
|
+
|
|
384
|
+
const zoned = dt.setZone(zone);
|
|
385
|
+
if (!zoned.isValid) return "";
|
|
386
|
+
|
|
387
|
+
const short = zoned.toFormat("z");
|
|
388
|
+
if (short && short !== "GMT" && short !== "UTC") return short;
|
|
389
|
+
|
|
390
|
+
return (
|
|
391
|
+
new Intl.DateTimeFormat("en-US", {
|
|
392
|
+
timeZone: zone,
|
|
393
|
+
timeZoneName: "short",
|
|
394
|
+
})
|
|
395
|
+
.formatToParts(zoned.toJSDate())
|
|
396
|
+
.find((part) => part.type === "timeZoneName")?.value ?? short
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** Curated list for the event wizard timezone picker (full IANA set is huge). */
|
|
401
|
+
export const EVENT_TIMEZONE_PICKER_ZONES: readonly string[] = [
|
|
402
|
+
"Pacific/Honolulu",
|
|
403
|
+
"America/Anchorage",
|
|
404
|
+
"America/Los_Angeles",
|
|
405
|
+
"America/Phoenix",
|
|
406
|
+
"America/Denver",
|
|
407
|
+
"America/Chicago",
|
|
408
|
+
"America/New_York",
|
|
409
|
+
"America/Puerto_Rico",
|
|
410
|
+
"America/Toronto",
|
|
411
|
+
"America/Vancouver",
|
|
412
|
+
"America/Mexico_City",
|
|
413
|
+
"America/Sao_Paulo",
|
|
414
|
+
"Europe/London",
|
|
415
|
+
"Europe/Paris",
|
|
416
|
+
"Europe/Berlin",
|
|
417
|
+
"Asia/Tokyo",
|
|
418
|
+
"Asia/Shanghai",
|
|
419
|
+
"Asia/Singapore",
|
|
420
|
+
"Australia/Sydney",
|
|
421
|
+
"UTC",
|
|
422
|
+
];
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* For public surfaces: use the stored IANA on the event. Legacy rows with null
|
|
426
|
+
* `timezone` fall back to the host profile zone, then geographic inference.
|
|
427
|
+
* Never uses the viewer's device timezone.
|
|
428
|
+
*/
|
|
429
|
+
export function resolveEventTimezoneIanaForDisplay(
|
|
430
|
+
args: ResolveEventTimezoneForDisplayArgs
|
|
431
|
+
): string {
|
|
346
432
|
const stored = args.timezone?.trim();
|
|
347
433
|
if (stored && isValidIanaTimezone(stored)) return stored;
|
|
348
434
|
|
|
435
|
+
const host = args.hostTimeZone?.trim();
|
|
436
|
+
if (host && isValidIanaTimezone(host)) return host;
|
|
437
|
+
|
|
438
|
+
const inferred = inferEventTimezoneIana(args);
|
|
439
|
+
if (inferred !== "UTC") return inferred;
|
|
440
|
+
|
|
349
441
|
return "UTC";
|
|
350
442
|
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Formats a bash start time in the event zone with a short zone label (e.g. ET).
|
|
446
|
+
*/
|
|
447
|
+
export function formatBashEventWhenLabel(
|
|
448
|
+
startDateTime: string | Date | null | undefined,
|
|
449
|
+
args: ResolveEventTimezoneForDisplayArgs
|
|
450
|
+
): string {
|
|
451
|
+
if (startDateTime == null) return "Date TBD";
|
|
452
|
+
const parsed =
|
|
453
|
+
startDateTime instanceof Date ? startDateTime : new Date(startDateTime);
|
|
454
|
+
if (Number.isNaN(parsed.getTime())) return "Date TBD";
|
|
455
|
+
|
|
456
|
+
const zone = resolveEventTimezoneIanaForDisplay(args);
|
|
457
|
+
const time = new Intl.DateTimeFormat("en-US", {
|
|
458
|
+
timeZone: zone,
|
|
459
|
+
weekday: "short",
|
|
460
|
+
month: "short",
|
|
461
|
+
day: "numeric",
|
|
462
|
+
hour: "numeric",
|
|
463
|
+
minute: "2-digit",
|
|
464
|
+
}).format(parsed);
|
|
465
|
+
const abbrev = formatEventTimezoneAbbrev(zone, parsed);
|
|
466
|
+
return abbrev ? `${time} ${abbrev}` : time;
|
|
467
|
+
}
|
|
@@ -146,15 +146,24 @@ function getRecurringBashEventPossibleDatesTimesInternal(
|
|
|
146
146
|
|
|
147
147
|
// For Monthly and Yearly, start from the event's actual date, not "today"
|
|
148
148
|
// This ensures we generate dates relative to the event's schedule
|
|
149
|
-
const shouldUseEventDate =
|
|
150
|
-
recurrence.frequency === RecurringFrequency.Monthly ||
|
|
151
|
-
recurrence.frequency === RecurringFrequency.Yearly
|
|
149
|
+
const shouldUseEventDate =
|
|
150
|
+
recurrence.frequency === RecurringFrequency.Monthly ||
|
|
151
|
+
recurrence.frequency === RecurringFrequency.Yearly ||
|
|
152
|
+
(Boolean(timezone) && Boolean(startDateTime));
|
|
152
153
|
|
|
153
154
|
const unzonedBeginningDate = shouldUseEventDate
|
|
154
|
-
? (startDateTime
|
|
155
|
+
? (startDateTime
|
|
156
|
+
? timezone
|
|
157
|
+
? (dateTimeFromDate(startDateTime, timezone) as DateTime)
|
|
158
|
+
: (dateTimeFromDate(startDateTime) as DateTime)
|
|
159
|
+
: DateTime.local())
|
|
155
160
|
: findEarliestPossibleBashEventDate(startDateTime) as DateTime;
|
|
156
161
|
|
|
157
|
-
const beginningDate = timezone
|
|
162
|
+
const beginningDate = timezone
|
|
163
|
+
? shouldUseEventDate
|
|
164
|
+
? unzonedBeginningDate
|
|
165
|
+
: unzonedBeginningDate.setZone(timezone)
|
|
166
|
+
: unzonedBeginningDate;
|
|
158
167
|
|
|
159
168
|
switch (recurrence.frequency) {
|
|
160
169
|
case RecurringFrequency.Daily:
|
|
@@ -320,6 +329,9 @@ function getWeeklyRecurringDates(
|
|
|
320
329
|
}
|
|
321
330
|
// Set the time on the date so that it matches the time when the event starts
|
|
322
331
|
weekday = dateTimeSetTime(weekday, beginningDateTime);
|
|
332
|
+
if (beginningDateTime.zoneName) {
|
|
333
|
+
weekday = weekday.setZone(beginningDateTime.zoneName);
|
|
334
|
+
}
|
|
323
335
|
recurrenceDates.push(weekday);
|
|
324
336
|
}
|
|
325
337
|
if (weekday) {
|