@getmicdrop/svelte-components 5.3.12 → 5.3.13
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/calendar/AboutShow/AboutShow.svelte +172 -172
- package/dist/calendar/Calendar/MiniMonthCalendar.svelte +782 -782
- package/dist/calendar/FAQs/FAQs.svelte +75 -75
- package/dist/calendar/MonthSwitcher/MonthSwitcher.svelte +126 -126
- package/dist/calendar/OrderSummary/OrderSummary.svelte +367 -367
- package/dist/calendar/PublicCard/PublicCard.svelte +145 -145
- package/dist/calendar/ShowCard/ShowCard.svelte +157 -157
- package/dist/calendar/ShowTimeCard/ShowTimeCard.svelte +61 -61
- package/dist/components/Layout/Grid.svelte +109 -109
- package/dist/components/Layout/Section.svelte +80 -80
- package/dist/components/Layout/Sidebar.svelte +108 -108
- package/dist/components/Layout/Stack.svelte +90 -90
- package/dist/constants/formOptions.js +26 -26
- package/dist/constants/validation.js +91 -91
- package/dist/constants/validation.spec.js +64 -64
- package/dist/datetime/__tests__/format.test.d.ts +2 -0
- package/dist/datetime/__tests__/format.test.d.ts.map +1 -0
- package/dist/datetime/__tests__/format.test.js +268 -0
- package/dist/datetime/__tests__/integration.test.d.ts +2 -0
- package/dist/datetime/__tests__/integration.test.d.ts.map +1 -0
- package/dist/datetime/__tests__/integration.test.js +243 -0
- package/dist/datetime/__tests__/parse.test.d.ts +2 -0
- package/dist/datetime/__tests__/parse.test.d.ts.map +1 -0
- package/dist/datetime/__tests__/parse.test.js +261 -0
- package/dist/datetime/__tests__/timezone.test.d.ts +2 -0
- package/dist/datetime/__tests__/timezone.test.d.ts.map +1 -0
- package/dist/datetime/__tests__/timezone.test.js +214 -0
- package/dist/datetime/constants.d.ts +133 -0
- package/dist/datetime/constants.d.ts.map +1 -0
- package/dist/datetime/constants.js +112 -0
- package/dist/datetime/format.d.ts +158 -0
- package/dist/datetime/format.d.ts.map +1 -0
- package/dist/datetime/format.js +315 -0
- package/dist/datetime/index.d.ts +42 -0
- package/dist/datetime/index.d.ts.map +1 -0
- package/dist/datetime/index.js +44 -0
- package/dist/datetime/parse.d.ts +149 -0
- package/dist/datetime/parse.d.ts.map +1 -0
- package/dist/datetime/parse.js +276 -0
- package/dist/datetime/timezone.d.ts +95 -0
- package/dist/datetime/timezone.d.ts.map +1 -0
- package/dist/datetime/timezone.js +241 -0
- package/dist/datetime/types.d.ts +105 -0
- package/dist/datetime/types.d.ts.map +1 -0
- package/dist/datetime/types.js +31 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +232 -218
- package/dist/patterns/data/DataGrid.svelte +45 -45
- package/dist/patterns/data/DataList.svelte +24 -24
- package/dist/patterns/data/DataTable.svelte +40 -40
- package/dist/patterns/forms/FormActions.spec.js +88 -88
- package/dist/patterns/forms/FormActions.stories.svelte +97 -97
- package/dist/patterns/forms/FormActions.svelte +46 -46
- package/dist/patterns/forms/FormGrid.svelte +33 -33
- package/dist/patterns/forms/FormSection.svelte +32 -32
- package/dist/patterns/forms/FormValidationSummary.spec.js +203 -203
- package/dist/patterns/forms/FormValidationSummary.stories.svelte +97 -97
- package/dist/patterns/forms/FormValidationSummary.svelte +67 -67
- package/dist/patterns/layout/Grid.svelte +35 -35
- package/dist/patterns/layout/Sidebar.svelte +39 -39
- package/dist/patterns/layout/Stack.svelte +45 -45
- package/dist/patterns/navigation/BottomNav.spec.js +130 -130
- package/dist/patterns/navigation/BottomNav.stories.svelte +117 -117
- package/dist/patterns/navigation/BottomNav.svelte +54 -54
- package/dist/patterns/navigation/Header.spec.js +203 -203
- package/dist/patterns/navigation/Header.stories.svelte +77 -77
- package/dist/patterns/navigation/Header.svelte +240 -240
- package/dist/patterns/page/PageHeader.svelte +36 -36
- package/dist/patterns/page/PageLayout.svelte +40 -40
- package/dist/patterns/page/PageLoader.spec.js +54 -54
- package/dist/patterns/page/PageLoader.stories.svelte +137 -137
- package/dist/patterns/page/PageLoader.svelte +41 -41
- package/dist/patterns/page/SectionHeader.svelte +41 -41
- package/dist/presets/badges.js +112 -112
- package/dist/presets/buttons.js +76 -76
- package/dist/presets/index.js +9 -9
- package/dist/primitives/Accordion/Accordion.stories.svelte +75 -75
- package/dist/primitives/Accordion/Accordion.svelte +61 -61
- package/dist/primitives/Accordion/AccordionItem.svelte +95 -95
- package/dist/primitives/Alert/Alert.spec.js +170 -170
- package/dist/primitives/Alert/Alert.stories.svelte +88 -88
- package/dist/primitives/Alert/Alert.svelte +65 -65
- package/dist/primitives/Avatar/Avatar.stories.svelte +94 -94
- package/dist/primitives/Avatar/Avatar.svelte +66 -66
- package/dist/primitives/Badges/Badge.spec.js +103 -103
- package/dist/primitives/Badges/Badge.stories.svelte +86 -86
- package/dist/primitives/Badges/Badge.svelte +142 -142
- package/dist/primitives/BottomSheet/BottomSheet.spec.js +127 -127
- package/dist/primitives/BottomSheet/BottomSheet.stories.svelte +83 -83
- package/dist/primitives/BottomSheet/BottomSheet.svelte +100 -100
- package/dist/primitives/Breadcrumb/Breadcrumb.spec.js +120 -120
- package/dist/primitives/Breadcrumb/Breadcrumb.stories.svelte +23 -23
- package/dist/primitives/Breadcrumb/Breadcrumb.svelte +89 -89
- package/dist/primitives/Button/Button.spec.js +211 -211
- package/dist/primitives/Button/Button.stories.svelte +76 -76
- package/dist/primitives/Button/Button.svelte +301 -301
- package/dist/primitives/Button/ButtonSaveDemo.spec.js +48 -48
- package/dist/primitives/Button/ButtonSaveDemo.svelte +25 -25
- package/dist/primitives/Button/ButtonVariantShowcase.svelte +129 -129
- package/dist/primitives/Card.spec.js +49 -49
- package/dist/primitives/Card.stories.svelte +22 -22
- package/dist/primitives/Card.svelte +28 -28
- package/dist/primitives/Checkbox/Checkbox.stories.svelte +84 -84
- package/dist/primitives/Checkbox/Checkbox.svelte +88 -88
- package/dist/primitives/DarkModeToggle.spec.js +357 -357
- package/dist/primitives/DarkModeToggle.stories.svelte +57 -57
- package/dist/primitives/DarkModeToggle.svelte +136 -136
- package/dist/primitives/Drawer/Drawer.stories.svelte +100 -100
- package/dist/primitives/Drawer/Drawer.svelte +214 -214
- package/dist/primitives/Dropdown/Dropdown.stories.svelte +137 -137
- package/dist/primitives/Dropdown/Dropdown.svelte +148 -148
- package/dist/primitives/Dropdown/DropdownItem.svelte +80 -80
- package/dist/primitives/Icons/ArrowLeft.svelte +20 -20
- package/dist/primitives/Icons/ArrowRight.svelte +20 -20
- package/dist/primitives/Icons/Availability.svelte +26 -26
- package/dist/primitives/Icons/Back.svelte +26 -26
- package/dist/primitives/Icons/CheckCircle.svelte +18 -18
- package/dist/primitives/Icons/CheckCircleOutline.svelte +27 -27
- package/dist/primitives/Icons/ChevronLeft.svelte +16 -16
- package/dist/primitives/Icons/ChevronRight.svelte +16 -16
- package/dist/primitives/Icons/Copy.svelte +27 -27
- package/dist/primitives/Icons/Cross.svelte +17 -17
- package/dist/primitives/Icons/DownArrow.svelte +20 -20
- package/dist/primitives/Icons/ErrorCircle.svelte +18 -18
- package/dist/primitives/Icons/FacebookIcon.svelte +13 -13
- package/dist/primitives/Icons/Home.svelte +27 -27
- package/dist/primitives/Icons/Icon.spec.js +175 -175
- package/dist/primitives/Icons/Icon.stories.svelte +100 -100
- package/dist/primitives/Icons/Icon.svelte +63 -63
- package/dist/primitives/Icons/IconGallery.stories.svelte +235 -235
- package/dist/primitives/Icons/ImageOutline.svelte +19 -19
- package/dist/primitives/Icons/Info.svelte +19 -19
- package/dist/primitives/Icons/InstagramIcon.svelte +19 -19
- package/dist/primitives/Icons/LogoInstagram.svelte +15 -15
- package/dist/primitives/Icons/Message.svelte +27 -27
- package/dist/primitives/Icons/MoonIcon.svelte +16 -16
- package/dist/primitives/Icons/More.svelte +33 -33
- package/dist/primitives/Icons/MoreHori.spec.js +67 -67
- package/dist/primitives/Icons/MoreHori.svelte +34 -34
- package/dist/primitives/Icons/Notification.svelte +26 -26
- package/dist/primitives/Icons/Payment.svelte +26 -26
- package/dist/primitives/Icons/Profile.svelte +33 -33
- package/dist/primitives/Icons/Reload.svelte +41 -41
- package/dist/primitives/Icons/Shows.svelte +33 -33
- package/dist/primitives/Icons/Signout.svelte +33 -33
- package/dist/primitives/Icons/SunIcon.svelte +19 -19
- package/dist/primitives/Icons/TiktokIcon.svelte +13 -13
- package/dist/primitives/Icons/TrashBinOutline.svelte +19 -19
- package/dist/primitives/Icons/TwitterIcon.svelte +13 -13
- package/dist/primitives/Icons/WarningIcon.spec.js +30 -30
- package/dist/primitives/Icons/WarningIcon.svelte +24 -24
- package/dist/primitives/Input/Input.spec.js +573 -573
- package/dist/primitives/Input/Input.stories.svelte +139 -139
- package/dist/primitives/Input/Input.svelte +444 -444
- package/dist/primitives/Input/Select.spec.js +218 -218
- package/dist/primitives/Input/Select.stories.svelte +112 -112
- package/dist/primitives/Input/Select.svelte +232 -232
- package/dist/primitives/Input/Textarea.stories.svelte +137 -137
- package/dist/primitives/Input/Textarea.svelte +79 -79
- package/dist/primitives/Label/Label.svelte +37 -37
- package/dist/primitives/Modal/Modal.spec.js +95 -95
- package/dist/primitives/Modal/Modal.stories.svelte +86 -86
- package/dist/primitives/Modal/Modal.svelte +158 -158
- package/dist/primitives/Pagination/Pagination.stories.svelte +76 -76
- package/dist/primitives/Pagination/Pagination.svelte +261 -261
- package/dist/primitives/Radio/Radio.stories.svelte +80 -80
- package/dist/primitives/Radio/Radio.svelte +67 -67
- package/dist/primitives/Skeleton/CardPlaceholder.svelte +87 -87
- package/dist/primitives/Skeleton/ImagePlaceholder.svelte +59 -59
- package/dist/primitives/Skeleton/ListPlaceholder.svelte +76 -76
- package/dist/primitives/Skeleton/Skeleton.stories.svelte +151 -151
- package/dist/primitives/Skeleton/Skeleton.svelte +52 -52
- package/dist/primitives/Spinner/Spinner.spec.js +75 -75
- package/dist/primitives/Spinner/Spinner.stories.svelte +29 -29
- package/dist/primitives/Spinner/Spinner.svelte +57 -57
- package/dist/primitives/Tabs/TabItem.svelte +51 -51
- package/dist/primitives/Tabs/Tabs.stories.svelte +112 -112
- package/dist/primitives/Tabs/Tabs.svelte +128 -128
- package/dist/primitives/Toggle.spec.js +127 -127
- package/dist/primitives/Toggle.stories.svelte +92 -92
- package/dist/primitives/Toggle.svelte +71 -71
- package/dist/primitives/Typography/Typography.svelte +53 -53
- package/dist/primitives/ValidationError.spec.js +103 -103
- package/dist/primitives/ValidationError.stories.svelte +111 -111
- package/dist/primitives/ValidationError.svelte +29 -29
- package/dist/recipes/CropImage/CropImage.spec.js +216 -216
- package/dist/recipes/CropImage/CropImage.stories.svelte +104 -104
- package/dist/recipes/CropImage/CropImage.svelte +238 -238
- package/dist/recipes/ImageUploader/ImageUploader.stories.svelte +125 -125
- package/dist/recipes/ImageUploader/ImageUploader.svelte +980 -980
- package/dist/recipes/Toaster/Toaster.stories.svelte +62 -62
- package/dist/recipes/feedback/EmptyState/EmptyState.svelte +47 -47
- package/dist/recipes/feedback/ErrorDisplay.spec.js +69 -69
- package/dist/recipes/feedback/ErrorDisplay.stories.svelte +112 -112
- package/dist/recipes/feedback/ErrorDisplay.svelte +38 -38
- package/dist/recipes/feedback/StatusIndicator/StatusIndicator.spec.js +129 -129
- package/dist/recipes/feedback/StatusIndicator/StatusIndicator.svelte +167 -167
- package/dist/recipes/fields/CheckboxField.svelte +85 -85
- package/dist/recipes/fields/FormField.svelte +58 -58
- package/dist/recipes/fields/RadioGroup.svelte +95 -95
- package/dist/recipes/fields/SelectField.svelte +82 -82
- package/dist/recipes/fields/TextareaField.svelte +101 -101
- package/dist/recipes/fields/ToggleField.svelte +60 -60
- package/dist/recipes/fields/index.js +7 -7
- package/dist/recipes/inputs/MultiSelect.spec.js +257 -257
- package/dist/recipes/inputs/MultiSelect.stories.svelte +133 -133
- package/dist/recipes/inputs/MultiSelect.svelte +244 -244
- package/dist/recipes/inputs/OTPInput.spec.js +238 -238
- package/dist/recipes/inputs/OTPInput.stories.svelte +162 -162
- package/dist/recipes/inputs/OTPInput.svelte +102 -102
- package/dist/recipes/inputs/PasswordInput.svelte +100 -100
- package/dist/recipes/inputs/PasswordStrengthIndicator/PasswordStrengthIndicator.spec.js +173 -173
- package/dist/recipes/inputs/PasswordStrengthIndicator/PasswordStrengthIndicator.svelte +108 -108
- package/dist/recipes/inputs/PlaceAutocomplete/PlaceAutocomplete.spec.js +300 -300
- package/dist/recipes/inputs/PlaceAutocomplete/PlaceAutocomplete.stories.svelte +165 -165
- package/dist/recipes/inputs/PlaceAutocomplete/PlaceAutocomplete.svelte +337 -337
- package/dist/recipes/inputs/Search.svelte +85 -85
- package/dist/recipes/inputs/SelectDropdown.svelte +161 -161
- package/dist/recipes/modals/AlertModal.svelte +130 -130
- package/dist/recipes/modals/ConfirmationModal.spec.js +191 -191
- package/dist/recipes/modals/ConfirmationModal.stories.svelte +119 -119
- package/dist/recipes/modals/ConfirmationModal.svelte +152 -152
- package/dist/recipes/modals/InputModal.svelte +182 -182
- package/dist/recipes/modals/ModalStateManager.spec.js +100 -100
- package/dist/recipes/modals/ModalStateManager.svelte +77 -77
- package/dist/recipes/modals/ModalTestWrapper.svelte +65 -65
- package/dist/recipes/modals/StatusModal.svelte +206 -206
- package/dist/services/EventService.js +75 -75
- package/dist/services/EventService.spec.js +217 -217
- package/dist/services/ShowService.spec.js +342 -342
- package/dist/stores/auth.js +93 -6
- package/dist/stores/auth.spec.js +310 -2
- package/dist/stores/toaster.js +13 -13
- package/dist/stories/ButtonAuditReview.stories.svelte +14 -14
- package/dist/stories/ButtonAuditReview.svelte +427 -427
- package/dist/stories/PatternsGallery.stories.svelte +19 -19
- package/dist/stories/PatternsGallery.svelte +388 -388
- package/dist/stories/PrimitivesGallery.stories.svelte +19 -19
- package/dist/stories/PrimitivesGallery.svelte +752 -752
- package/dist/stories/RecipesGallery.stories.svelte +19 -19
- package/dist/stories/RecipesGallery.svelte +441 -441
- package/dist/stories/button-audit-manifest.json +11186 -11186
- package/dist/tailwind/preset.cjs +82 -82
- package/dist/telemetry.js +357 -357
- package/dist/tokens/tokens.css +87 -87
- package/dist/utils/apiConfig.js +49 -49
- package/dist/utils/utils.js +9 -1
- package/package.json +233 -191
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timezone Utilities
|
|
3
|
+
*
|
|
4
|
+
* Functions for working with IANA timezones.
|
|
5
|
+
* All timezone operations require explicit timezone IDs - no defaults.
|
|
6
|
+
*
|
|
7
|
+
* @module datetime/timezone
|
|
8
|
+
*/
|
|
9
|
+
import { DateTimeError, DateTimeErrorCode } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Cache for timezone validation results to avoid repeated Intl calls.
|
|
12
|
+
*/
|
|
13
|
+
const timezoneValidationCache = new Map();
|
|
14
|
+
/**
|
|
15
|
+
* Common timezone abbreviations that should NOT be considered valid IANA timezones.
|
|
16
|
+
* These are handled separately by normalizeTimezone().
|
|
17
|
+
*/
|
|
18
|
+
const TIMEZONE_ABBREVIATIONS = new Set([
|
|
19
|
+
'PST',
|
|
20
|
+
'PDT',
|
|
21
|
+
'PT',
|
|
22
|
+
'MST',
|
|
23
|
+
'MDT',
|
|
24
|
+
'MT',
|
|
25
|
+
'CST',
|
|
26
|
+
'CDT',
|
|
27
|
+
'CT',
|
|
28
|
+
'EST',
|
|
29
|
+
'EDT',
|
|
30
|
+
'ET',
|
|
31
|
+
'GMT',
|
|
32
|
+
'BST',
|
|
33
|
+
'CET',
|
|
34
|
+
'CEST',
|
|
35
|
+
'JST',
|
|
36
|
+
'AEST',
|
|
37
|
+
'AEDT',
|
|
38
|
+
]);
|
|
39
|
+
/**
|
|
40
|
+
* Validates whether a string is a valid IANA timezone identifier.
|
|
41
|
+
* Rejects common abbreviations like PST, EST, etc. even if the runtime accepts them.
|
|
42
|
+
*
|
|
43
|
+
* @param timezone - The timezone string to validate
|
|
44
|
+
* @returns true if valid IANA timezone, false otherwise
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* isValidTimezone('America/Los_Angeles') // true
|
|
48
|
+
* isValidTimezone('PST') // false (abbreviations not valid)
|
|
49
|
+
* isValidTimezone('Invalid/Zone') // false
|
|
50
|
+
*/
|
|
51
|
+
export function isValidTimezone(timezone) {
|
|
52
|
+
if (!timezone || typeof timezone !== 'string') {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
// Reject known abbreviations - they're not proper IANA identifiers
|
|
56
|
+
if (TIMEZONE_ABBREVIATIONS.has(timezone.toUpperCase())) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
// Check cache first
|
|
60
|
+
const cached = timezoneValidationCache.get(timezone);
|
|
61
|
+
if (cached !== undefined) {
|
|
62
|
+
return cached;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
// Attempt to create a DateTimeFormat with the timezone
|
|
66
|
+
// This throws for invalid timezones
|
|
67
|
+
Intl.DateTimeFormat(undefined, { timeZone: timezone });
|
|
68
|
+
timezoneValidationCache.set(timezone, true);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
timezoneValidationCache.set(timezone, false);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Extracts the timezone from a venue object.
|
|
78
|
+
* Throws if the venue doesn't have a valid timezone.
|
|
79
|
+
*
|
|
80
|
+
* @param venue - Venue object with optional timezone property
|
|
81
|
+
* @returns The venue's timezone ID
|
|
82
|
+
* @throws {DateTimeError} If venue timezone is missing or invalid
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* const tz = getVenueTimezone({ timezone: 'America/Los_Angeles' });
|
|
86
|
+
* // tz === 'America/Los_Angeles'
|
|
87
|
+
*
|
|
88
|
+
* getVenueTimezone({}) // throws DateTimeError
|
|
89
|
+
*/
|
|
90
|
+
export function getVenueTimezone(venue) {
|
|
91
|
+
const timezone = venue?.timezone;
|
|
92
|
+
if (!timezone || typeof timezone !== 'string' || timezone.trim() === '') {
|
|
93
|
+
throw new DateTimeError('Venue timezone is required', DateTimeErrorCode.MISSING_TIMEZONE, { venue });
|
|
94
|
+
}
|
|
95
|
+
if (!isValidTimezone(timezone)) {
|
|
96
|
+
throw new DateTimeError(`Invalid venue timezone: ${timezone}`, DateTimeErrorCode.INVALID_TIMEZONE, { venue, timezone });
|
|
97
|
+
}
|
|
98
|
+
return timezone;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets the user's browser/system timezone.
|
|
102
|
+
*
|
|
103
|
+
* @returns The user's IANA timezone ID
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* const userTz = getUserTimezone();
|
|
107
|
+
* // e.g., 'America/Los_Angeles'
|
|
108
|
+
*/
|
|
109
|
+
export function getUserTimezone() {
|
|
110
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Gets a human-readable timezone offset string.
|
|
114
|
+
*
|
|
115
|
+
* @param timezone - IANA timezone ID
|
|
116
|
+
* @param date - Optional date for DST-aware offset (defaults to now)
|
|
117
|
+
* @returns Formatted offset string (e.g., "PST (UTC-8)" or "PDT (UTC-7)")
|
|
118
|
+
* @throws {DateTimeError} If timezone is invalid
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* getTimezoneOffset('America/Los_Angeles')
|
|
122
|
+
* // "PST (UTC-8)" in winter, "PDT (UTC-7)" in summer
|
|
123
|
+
*/
|
|
124
|
+
export function getTimezoneOffset(timezone, date = new Date()) {
|
|
125
|
+
if (!isValidTimezone(timezone)) {
|
|
126
|
+
throw new DateTimeError(`Invalid timezone: ${timezone}`, DateTimeErrorCode.INVALID_TIMEZONE, { timezone });
|
|
127
|
+
}
|
|
128
|
+
// Get the timezone abbreviation
|
|
129
|
+
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
130
|
+
timeZone: timezone,
|
|
131
|
+
timeZoneName: 'short',
|
|
132
|
+
});
|
|
133
|
+
const parts = formatter.formatToParts(date);
|
|
134
|
+
const tzPart = parts.find(p => p.type === 'timeZoneName');
|
|
135
|
+
const abbr = tzPart?.value || timezone;
|
|
136
|
+
// Calculate offset in hours
|
|
137
|
+
const utcDate = new Date(date.toLocaleString('en-US', { timeZone: 'UTC' }));
|
|
138
|
+
const tzDate = new Date(date.toLocaleString('en-US', { timeZone: timezone }));
|
|
139
|
+
const offsetMs = tzDate.getTime() - utcDate.getTime();
|
|
140
|
+
const offsetHours = Math.round(offsetMs / (60 * 60 * 1000));
|
|
141
|
+
const sign = offsetHours >= 0 ? '+' : '';
|
|
142
|
+
return `${abbr} (UTC${sign}${offsetHours})`;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Gets the display name for a timezone.
|
|
146
|
+
*
|
|
147
|
+
* @param timezone - IANA timezone ID
|
|
148
|
+
* @returns Human-readable timezone name
|
|
149
|
+
* @throws {DateTimeError} If timezone is invalid
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* getTimezoneDisplayName('America/Los_Angeles')
|
|
153
|
+
* // "Pacific Time"
|
|
154
|
+
*/
|
|
155
|
+
export function getTimezoneDisplayName(timezone) {
|
|
156
|
+
if (!isValidTimezone(timezone)) {
|
|
157
|
+
throw new DateTimeError(`Invalid timezone: ${timezone}`, DateTimeErrorCode.INVALID_TIMEZONE, { timezone });
|
|
158
|
+
}
|
|
159
|
+
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
160
|
+
timeZone: timezone,
|
|
161
|
+
timeZoneName: 'long',
|
|
162
|
+
});
|
|
163
|
+
const parts = formatter.formatToParts(new Date());
|
|
164
|
+
const tzPart = parts.find(p => p.type === 'timeZoneName');
|
|
165
|
+
return tzPart?.value || timezone;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Normalizes legacy or non-standard timezone strings to valid IANA IDs.
|
|
169
|
+
* This is useful for handling user input or legacy data.
|
|
170
|
+
*
|
|
171
|
+
* @param timezone - Timezone string that may be non-standard
|
|
172
|
+
* @returns Valid IANA timezone ID
|
|
173
|
+
* @throws {DateTimeError} If timezone cannot be normalized
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* normalizeTimezone('PST') // might return 'America/Los_Angeles'
|
|
177
|
+
* normalizeTimezone('Eastern') // might return 'America/New_York'
|
|
178
|
+
*/
|
|
179
|
+
export function normalizeTimezone(timezone) {
|
|
180
|
+
if (!timezone || typeof timezone !== 'string') {
|
|
181
|
+
throw new DateTimeError('Timezone is required', DateTimeErrorCode.MISSING_TIMEZONE);
|
|
182
|
+
}
|
|
183
|
+
const trimmed = timezone.trim();
|
|
184
|
+
// If already valid, return as-is
|
|
185
|
+
if (isValidTimezone(trimmed)) {
|
|
186
|
+
return trimmed;
|
|
187
|
+
}
|
|
188
|
+
// Common abbreviation mappings (US-focused for MicDrop)
|
|
189
|
+
const abbreviationMap = {
|
|
190
|
+
PST: 'America/Los_Angeles',
|
|
191
|
+
PDT: 'America/Los_Angeles',
|
|
192
|
+
PT: 'America/Los_Angeles',
|
|
193
|
+
PACIFIC: 'America/Los_Angeles',
|
|
194
|
+
MST: 'America/Denver',
|
|
195
|
+
MDT: 'America/Denver',
|
|
196
|
+
MT: 'America/Denver',
|
|
197
|
+
MOUNTAIN: 'America/Denver',
|
|
198
|
+
CST: 'America/Chicago',
|
|
199
|
+
CDT: 'America/Chicago',
|
|
200
|
+
CT: 'America/Chicago',
|
|
201
|
+
CENTRAL: 'America/Chicago',
|
|
202
|
+
EST: 'America/New_York',
|
|
203
|
+
EDT: 'America/New_York',
|
|
204
|
+
ET: 'America/New_York',
|
|
205
|
+
EASTERN: 'America/New_York',
|
|
206
|
+
UTC: 'UTC',
|
|
207
|
+
GMT: 'UTC',
|
|
208
|
+
};
|
|
209
|
+
const normalized = abbreviationMap[trimmed.toUpperCase()];
|
|
210
|
+
if (normalized) {
|
|
211
|
+
return normalized;
|
|
212
|
+
}
|
|
213
|
+
throw new DateTimeError(`Cannot normalize timezone: ${timezone}`, DateTimeErrorCode.INVALID_TIMEZONE, { timezone });
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Checks if a timezone is currently observing Daylight Saving Time.
|
|
217
|
+
*
|
|
218
|
+
* @param timezone - IANA timezone ID
|
|
219
|
+
* @param date - Date to check (defaults to now)
|
|
220
|
+
* @returns true if DST is in effect
|
|
221
|
+
* @throws {DateTimeError} If timezone is invalid
|
|
222
|
+
*/
|
|
223
|
+
export function isDST(timezone, date = new Date()) {
|
|
224
|
+
if (!isValidTimezone(timezone)) {
|
|
225
|
+
throw new DateTimeError(`Invalid timezone: ${timezone}`, DateTimeErrorCode.INVALID_TIMEZONE, { timezone });
|
|
226
|
+
}
|
|
227
|
+
// Compare January and July offsets - if different, DST exists
|
|
228
|
+
const jan = new Date(date.getFullYear(), 0, 1);
|
|
229
|
+
const jul = new Date(date.getFullYear(), 6, 1);
|
|
230
|
+
const getOffset = (d) => {
|
|
231
|
+
const utc = new Date(d.toLocaleString('en-US', { timeZone: 'UTC' }));
|
|
232
|
+
const tz = new Date(d.toLocaleString('en-US', { timeZone: timezone }));
|
|
233
|
+
return tz.getTime() - utc.getTime();
|
|
234
|
+
};
|
|
235
|
+
const janOffset = getOffset(jan);
|
|
236
|
+
const julOffset = getOffset(jul);
|
|
237
|
+
const currentOffset = getOffset(date);
|
|
238
|
+
// DST is the one with the larger offset (more hours ahead)
|
|
239
|
+
const dstOffset = Math.max(janOffset, julOffset);
|
|
240
|
+
return currentOffset === dstOffset && janOffset !== julOffset;
|
|
241
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DateTime Module Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* This module provides type-safe date/time handling for the MicDrop platform.
|
|
5
|
+
* All datetime operations should use these types to ensure consistency.
|
|
6
|
+
*
|
|
7
|
+
* @module datetime/types
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* IANA timezone identifier (e.g., 'America/Los_Angeles', 'Europe/London')
|
|
11
|
+
* Must be a valid IANA timezone string, not abbreviations like 'PST' or 'EST'.
|
|
12
|
+
*/
|
|
13
|
+
export type TimezoneId = string;
|
|
14
|
+
/**
|
|
15
|
+
* ISO 8601 date string in UTC format (e.g., '2023-12-25T20:00:00Z')
|
|
16
|
+
* The 'Z' suffix indicates UTC timezone.
|
|
17
|
+
*/
|
|
18
|
+
export type ISODateString = string;
|
|
19
|
+
/**
|
|
20
|
+
* Local date string without timezone (e.g., '2023-12-25')
|
|
21
|
+
* Used for date-only inputs where time is not relevant.
|
|
22
|
+
*/
|
|
23
|
+
export type LocalDateString = string;
|
|
24
|
+
/**
|
|
25
|
+
* Local time string in 24-hour format (e.g., '19:00', '23:30')
|
|
26
|
+
* Used for time-only inputs.
|
|
27
|
+
*/
|
|
28
|
+
export type LocalTimeString = string;
|
|
29
|
+
/**
|
|
30
|
+
* Local datetime string without timezone (e.g., '2023-12-25T19:00:00')
|
|
31
|
+
* Used for form inputs before timezone conversion.
|
|
32
|
+
*/
|
|
33
|
+
export type LocalDateTimeString = string;
|
|
34
|
+
/**
|
|
35
|
+
* Extracted date parts from a datetime, formatted for display.
|
|
36
|
+
*/
|
|
37
|
+
export interface DateParts {
|
|
38
|
+
/** Short day name (e.g., "Mon", "Tue") */
|
|
39
|
+
day: string;
|
|
40
|
+
/** Short month name (e.g., "Dec", "Jan") */
|
|
41
|
+
month: string;
|
|
42
|
+
/** Day of month (1-31) */
|
|
43
|
+
date: number;
|
|
44
|
+
/** Full year (e.g., 2025) */
|
|
45
|
+
year: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A time range with start and end times in UTC.
|
|
49
|
+
*/
|
|
50
|
+
export interface TimeRange {
|
|
51
|
+
/** Start time as UTC ISO string */
|
|
52
|
+
start: ISODateString;
|
|
53
|
+
/** End time as UTC ISO string */
|
|
54
|
+
end: ISODateString;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Formatted time range for display purposes.
|
|
58
|
+
*/
|
|
59
|
+
export interface FormattedTimeRange {
|
|
60
|
+
/** Formatted time display (e.g., "7:00 PM - 10:00 PM") */
|
|
61
|
+
display: string;
|
|
62
|
+
/** Formatted date (e.g., "Dec 20, 2025") */
|
|
63
|
+
date: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Options for formatting datetime values.
|
|
67
|
+
*/
|
|
68
|
+
export interface FormatOptions {
|
|
69
|
+
/** Include seconds in time display (default: false) */
|
|
70
|
+
includeSeconds?: boolean;
|
|
71
|
+
/** Use 24-hour format (default: false, uses 12-hour with AM/PM) */
|
|
72
|
+
use24Hour?: boolean;
|
|
73
|
+
/** Include year in date display (default: true) */
|
|
74
|
+
includeYear?: boolean;
|
|
75
|
+
/** Use short month names (default: true) */
|
|
76
|
+
shortMonth?: boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Venue object with timezone information.
|
|
80
|
+
* Used by getVenueTimezone to extract timezone.
|
|
81
|
+
*/
|
|
82
|
+
export interface VenueWithTimezone {
|
|
83
|
+
timezone?: string;
|
|
84
|
+
[key: string]: unknown;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Error thrown when datetime operations fail.
|
|
88
|
+
*/
|
|
89
|
+
export declare class DateTimeError extends Error {
|
|
90
|
+
readonly code: DateTimeErrorCode;
|
|
91
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
92
|
+
constructor(message: string, code: DateTimeErrorCode, details?: Record<string, unknown> | undefined);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Error codes for datetime operations.
|
|
96
|
+
*/
|
|
97
|
+
export declare enum DateTimeErrorCode {
|
|
98
|
+
INVALID_TIMEZONE = "INVALID_TIMEZONE",
|
|
99
|
+
INVALID_ISO_STRING = "INVALID_ISO_STRING",
|
|
100
|
+
INVALID_DATE = "INVALID_DATE",
|
|
101
|
+
INVALID_TIME = "INVALID_TIME",
|
|
102
|
+
MISSING_TIMEZONE = "MISSING_TIMEZONE",
|
|
103
|
+
PARSE_ERROR = "PARSE_ERROR"
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/datetime/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,0CAA0C;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,mCAAmC;IACnC,KAAK,EAAE,aAAa,CAAC;IACrB,iCAAiC;IACjC,GAAG,EAAE,aAAa,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,uDAAuD;IACvD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mEAAmE;IACnE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mDAAmD;IACnD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;aAGpB,IAAI,EAAE,iBAAiB;aACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAFjD,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,iBAAiB,EACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKpD;AAED;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,gBAAgB,qBAAqB;IACrC,kBAAkB,uBAAuB;IACzC,YAAY,iBAAiB;IAC7B,YAAY,iBAAiB;IAC7B,gBAAgB,qBAAqB;IACrC,WAAW,gBAAgB;CAC5B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DateTime Module Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* This module provides type-safe date/time handling for the MicDrop platform.
|
|
5
|
+
* All datetime operations should use these types to ensure consistency.
|
|
6
|
+
*
|
|
7
|
+
* @module datetime/types
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown when datetime operations fail.
|
|
11
|
+
*/
|
|
12
|
+
export class DateTimeError extends Error {
|
|
13
|
+
constructor(message, code, details) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.details = details;
|
|
17
|
+
this.name = 'DateTimeError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Error codes for datetime operations.
|
|
22
|
+
*/
|
|
23
|
+
export var DateTimeErrorCode;
|
|
24
|
+
(function (DateTimeErrorCode) {
|
|
25
|
+
DateTimeErrorCode["INVALID_TIMEZONE"] = "INVALID_TIMEZONE";
|
|
26
|
+
DateTimeErrorCode["INVALID_ISO_STRING"] = "INVALID_ISO_STRING";
|
|
27
|
+
DateTimeErrorCode["INVALID_DATE"] = "INVALID_DATE";
|
|
28
|
+
DateTimeErrorCode["INVALID_TIME"] = "INVALID_TIME";
|
|
29
|
+
DateTimeErrorCode["MISSING_TIMEZONE"] = "MISSING_TIMEZONE";
|
|
30
|
+
DateTimeErrorCode["PARSE_ERROR"] = "PARSE_ERROR";
|
|
31
|
+
})(DateTimeErrorCode || (DateTimeErrorCode = {}));
|
package/dist/index.d.ts
CHANGED
|
@@ -112,6 +112,16 @@ export { default as ShowTimeCard } from "./calendar/ShowTimeCard/ShowTimeCard.sv
|
|
|
112
112
|
export * from "./constants/formOptions.js";
|
|
113
113
|
export * from "./constants/validation.js";
|
|
114
114
|
export * from "./presets/index.js";
|
|
115
|
+
export * from "./utils/utils.js";
|
|
116
|
+
export * from "./utils/utils/utils.js";
|
|
117
|
+
export * from "./utils/greetings.js";
|
|
118
|
+
export * from "./utils/imageValidation.js";
|
|
119
|
+
export * from "./utils/apiConfig.js";
|
|
120
|
+
export * from "./stores/toaster.js";
|
|
121
|
+
export * from "./stores/navigation.js";
|
|
122
|
+
export * from "./stores/auth.js";
|
|
123
|
+
export * from "./config.js";
|
|
124
|
+
export * from "./telemetry.js";
|
|
115
125
|
export { portal } from "./utils/portal.js";
|
|
116
126
|
export { typography } from "./tokens/typography.js";
|
|
117
127
|
export { default as MiniMonthCalendar, default as Calendar } from "./calendar/Calendar/MiniMonthCalendar.svelte";
|