@wix/headless-restaurants-olo 0.0.33 → 0.0.35

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.
Files changed (59) hide show
  1. package/cjs/dist/react/FulfillmentDetails.d.ts +139 -15
  2. package/cjs/dist/react/FulfillmentDetails.js +128 -24
  3. package/cjs/dist/react/ItemDetails.d.ts +4 -4
  4. package/cjs/dist/react/ItemDetails.js +5 -6
  5. package/cjs/dist/react/Settings.d.ts +8 -0
  6. package/cjs/dist/react/Settings.js +18 -25
  7. package/cjs/dist/react/core/FulfillmentDetails.d.ts +73 -7
  8. package/cjs/dist/react/core/FulfillmentDetails.js +133 -86
  9. package/cjs/dist/react/core/ItemDetails.d.ts +1 -1
  10. package/cjs/dist/react/core/ItemDetails.js +5 -16
  11. package/cjs/dist/react/core/Settings.d.ts +19 -4
  12. package/cjs/dist/react/core/Settings.js +29 -20
  13. package/cjs/dist/services/fulfillment-details-service.d.ts +127 -0
  14. package/cjs/dist/services/fulfillment-details-service.js +351 -0
  15. package/cjs/dist/services/fulfillments-service.js +67 -43
  16. package/cjs/dist/services/index.d.ts +2 -0
  17. package/cjs/dist/services/index.js +1 -0
  18. package/cjs/dist/services/item-details-service.d.ts +1 -1
  19. package/cjs/dist/services/item-details-service.js +10 -16
  20. package/cjs/dist/services/olo-settings-service.d.ts +0 -1
  21. package/cjs/dist/services/olo-settings-service.js +1 -3
  22. package/cjs/dist/services/utils.d.ts +4 -0
  23. package/cjs/dist/services/utils.js +12 -0
  24. package/cjs/dist/types/fulfillments-types.d.ts +18 -1
  25. package/cjs/dist/types/fulfillments-types.js +9 -0
  26. package/cjs/dist/utils/date-utils.d.ts +164 -0
  27. package/cjs/dist/utils/date-utils.js +297 -0
  28. package/cjs/dist/utils/fulfillments-utils.d.ts +3 -2
  29. package/cjs/dist/utils/fulfillments-utils.js +13 -57
  30. package/dist/react/FulfillmentDetails.d.ts +139 -15
  31. package/dist/react/FulfillmentDetails.js +128 -24
  32. package/dist/react/ItemDetails.d.ts +4 -4
  33. package/dist/react/ItemDetails.js +5 -6
  34. package/dist/react/Settings.d.ts +8 -0
  35. package/dist/react/Settings.js +18 -25
  36. package/dist/react/core/FulfillmentDetails.d.ts +73 -7
  37. package/dist/react/core/FulfillmentDetails.js +133 -86
  38. package/dist/react/core/ItemDetails.d.ts +1 -1
  39. package/dist/react/core/ItemDetails.js +5 -16
  40. package/dist/react/core/Settings.d.ts +19 -4
  41. package/dist/react/core/Settings.js +29 -20
  42. package/dist/services/fulfillment-details-service.d.ts +127 -0
  43. package/dist/services/fulfillment-details-service.js +351 -0
  44. package/dist/services/fulfillments-service.js +67 -43
  45. package/dist/services/index.d.ts +2 -0
  46. package/dist/services/index.js +1 -0
  47. package/dist/services/item-details-service.d.ts +1 -1
  48. package/dist/services/item-details-service.js +10 -16
  49. package/dist/services/olo-settings-service.d.ts +0 -1
  50. package/dist/services/olo-settings-service.js +1 -3
  51. package/dist/services/utils.d.ts +4 -0
  52. package/dist/services/utils.js +12 -0
  53. package/dist/types/fulfillments-types.d.ts +18 -1
  54. package/dist/types/fulfillments-types.js +9 -0
  55. package/dist/utils/date-utils.d.ts +164 -0
  56. package/dist/utils/date-utils.js +297 -0
  57. package/dist/utils/fulfillments-utils.d.ts +3 -2
  58. package/dist/utils/fulfillments-utils.js +13 -57
  59. package/package.json +3 -2
@@ -1,7 +1,7 @@
1
1
  import { defineService, implementService } from '@wix/services-definitions';
2
2
  import { SignalsServiceDefinition, } from '@wix/services-definitions/core-services/signals';
3
3
  import { AddToCartButtonState, AvailabilityStatus, } from './common-types.js';
4
- import { getAreNotEnoughModifiersOfMandatoryModifierGroupInStock, getModifiersInitState, getLineItemModifiers, getPriceVariantOptions, getSelectedModifierPrices, getSelectedVariantPrice, calculateItemPrice, checkModifiersValidation, } from './utils.js';
4
+ import { getAreNotEnoughModifiersOfMandatoryModifierGroupInStock, getModifiersInitState, getLineItemModifiers, getPriceVariantOptions, getSelectedModifierPrices, getSelectedVariantPrice, calculateItemPrice, getModifierGroupErrors, } from './utils.js';
5
5
  import { OLOSettingsServiceDefinition } from './olo-settings-service.js';
6
6
  /**
7
7
  * Service definition for the Item service.
@@ -131,6 +131,14 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
131
131
  },
132
132
  };
133
133
  });
134
+ const onHandleAddToCart = (onClick) => {
135
+ const currentSelectedModifiers = selectedModifiers.get();
136
+ const { errors, hasError } = getModifierGroupErrors(currentSelectedModifiers, modifierGroups);
137
+ modifierGroupError.set(errors);
138
+ if (hasError)
139
+ return;
140
+ onClick(lineItem.get());
141
+ };
134
142
  const updateQuantity = (_quantity) => {
135
143
  quantity.set(_quantity);
136
144
  };
@@ -164,20 +172,6 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
164
172
  }
165
173
  }
166
174
  };
167
- const doesModifierGroupHaveError = signalsService.computed(() => {
168
- const currentSelectedModifiers = selectedModifiers.get();
169
- const errors = {};
170
- modifierGroups.forEach((group) => {
171
- if (group._id) {
172
- const selectedCount = (currentSelectedModifiers[group._id] || [])
173
- .length;
174
- const isValid = checkModifiersValidation(group.rule, selectedCount);
175
- errors[group._id] = !isValid;
176
- }
177
- });
178
- modifierGroupError.set(errors);
179
- return Object.values(errors).some((error) => error);
180
- });
181
175
  const toggleModifier = (modifierGroupId, modifierId, singleSelect = false) => {
182
176
  const currentSelectedModifiers = selectedModifiers.get();
183
177
  const modifierIds = getModifierIds(modifierGroupId, modifierId, singleSelect);
@@ -206,6 +200,7 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
206
200
  error,
207
201
  specialRequest,
208
202
  lineItem,
203
+ onHandleAddToCart,
209
204
  selectedVariant,
210
205
  selectedModifiers,
211
206
  availabilityStatus,
@@ -215,7 +210,6 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
215
210
  addToCartButtonDisabled,
216
211
  price,
217
212
  futureAvailability,
218
- doesModifierGroupHaveError,
219
213
  };
220
214
  });
221
215
  /**
@@ -4,7 +4,6 @@ import { MenusServiceConfig } from '@wix/restaurants/services';
4
4
  export interface OLOSettingsServiceAPI {
5
5
  operationGroup: Signal<operationGroupsSDK.OperationGroup | undefined>;
6
6
  operation: Signal<operationsSDK.Operation | undefined>;
7
- selectedItem?: Signal<unknown>;
8
7
  isLoading: Signal<boolean>;
9
8
  error: Signal<string | null>;
10
9
  availabilityDispatchAction?: Signal<(() => void) | undefined>;
@@ -10,8 +10,7 @@ export const OLOSettingsService = implementService.withConfig()(OLOSettingsServi
10
10
  const operation = signalsService.signal(config.operation);
11
11
  const formatCurrency = config.formattedPrice ??
12
12
  ((price) => price?.toFixed(2)?.toString() ?? '');
13
- const selectedItem = signalsService.signal(null);
14
- const isLoading = signalsService.signal(false);
13
+ const isLoading = signalsService.signal(true);
15
14
  const error = signalsService.signal(null);
16
15
  const currentFulfillment = signalsService.signal('Pickup');
17
16
  const currentTimeSlot = signalsService.signal('10-14');
@@ -24,7 +23,6 @@ export const OLOSettingsService = implementService.withConfig()(OLOSettingsServi
24
23
  operation,
25
24
  isLoading,
26
25
  error,
27
- selectedItem,
28
26
  availabilityDispatchAction,
29
27
  currentFulfillment,
30
28
  currentTimeSlot,
@@ -35,6 +35,10 @@ export declare const chooseUpToX: ({ required, minSelections, maxSelections, }:
35
35
  export declare const hasToChooseBetweenXAndY: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
36
36
  export declare const getRuleTypeMapValue: (ruleTypeMap: RuleTypeMap, ruleType: RuleType, rule: EnhancedModifierGroup["rule"]) => string | undefined;
37
37
  export declare const checkModifiersValidation: (rule: EnhancedModifierGroup["rule"], selectedCount: number) => boolean;
38
+ export declare const getModifierGroupErrors: (selectedModifiers: Record<string, Array<string>>, modifierGroups: EnhancedModifierGroup[]) => {
39
+ errors: Record<string, boolean>;
40
+ hasError: boolean;
41
+ };
38
42
  export declare const getAreNotEnoughModifiersOfMandatoryModifierGroupInStock: (modifierGroups: EnhancedModifierGroup[]) => boolean;
39
43
  export declare const getLineItemModifiers: (selectedModifiers: Record<string, Array<string>>, modifierGroups: EnhancedModifierGroup[], formatCurrency: (price?: number) => string) => {
40
44
  id: string;
@@ -158,6 +158,18 @@ export const checkModifiersValidation = (rule, selectedCount) => {
158
158
  }
159
159
  return true;
160
160
  };
161
+ export const getModifierGroupErrors = (selectedModifiers, modifierGroups) => {
162
+ const errors = {};
163
+ modifierGroups.forEach((group) => {
164
+ if (group._id) {
165
+ const selectedCount = (selectedModifiers[group._id] || []).length;
166
+ const isValid = checkModifiersValidation(group.rule, selectedCount);
167
+ errors[group._id] = !isValid;
168
+ }
169
+ });
170
+ const hasError = Object.values(errors).some((error) => error);
171
+ return { errors, hasError };
172
+ };
161
173
  export const getAreNotEnoughModifiersOfMandatoryModifierGroupInStock = (modifierGroups) => modifierGroups.some((modifierGroup) => {
162
174
  const isModifierGroupMandatory = modifierGroup.rule?.required;
163
175
  const minimumRequiredModifiers = modifierGroup.rule?.minSelections ?? 0;
@@ -2,12 +2,21 @@ import * as operationsSDK from '@wix/auto_sdk_restaurants_operations';
2
2
  import { Signal } from '@wix/services-definitions/core-services/signals';
3
3
  import * as fulfillemtMethodsSDK from '@wix/auto_sdk_restaurants_fulfillment-methods';
4
4
  import { Address, DurationRange } from '@wix/auto_sdk_restaurants_operations';
5
+ import { Operation } from './operation.js';
5
6
  export declare enum DispatchType {
6
7
  /** Pickup fulfillment */
7
8
  PICKUP = "PICKUP",
8
9
  /** Delivery fulfillment */
9
10
  DELIVERY = "DELIVERY"
10
11
  }
12
+ export declare enum FulfillmentTypeEnum {
13
+ /** ASAP - Order will be fulfilled as soon as possible */
14
+ ASAP = "ASAP",
15
+ /** PREORDER - Order will be fulfilled at a scheduled time */
16
+ PREORDER = "PREORDER",
17
+ /** ASAP_AND_FUTURE - Both ASAP and future scheduling available */
18
+ ASAP_AND_FUTURE = "ASAP_AND_FUTURE"
19
+ }
11
20
  export type TimeSlot = {
12
21
  id: string;
13
22
  startTime: Date;
@@ -52,6 +61,14 @@ export interface FulfillmentsServiceAPI {
52
61
  error: Signal<string | null>;
53
62
  /** Available dispatch types */
54
63
  availableTypes: Signal<DispatchType[]>;
64
+ /** Current scheduling type (ASAP or PREORDER) based on selected time slot */
65
+ schedulingType: Signal<FulfillmentTypeEnum | undefined>;
66
+ /** Whether ASAP option is available */
67
+ hasAsapOption: Signal<boolean>;
68
+ /** Whether preorder (schedule for later) option is available */
69
+ hasPreorderOption: Signal<boolean>;
70
+ /** Whether both ASAP and future scheduling options are available */
71
+ hasAsapAndFutureOption: Signal<boolean>;
55
72
  /**
56
73
  * Dispatches info by dispatch type
57
74
  */
@@ -78,6 +95,6 @@ export interface FulfillmentsServiceAPI {
78
95
  }
79
96
  export interface FulfillmentsServiceConfig {
80
97
  firstAvailableTimeSlots?: operationsSDK.TimeSlotForOperation[];
81
- operation?: operationsSDK.Operation;
98
+ operation?: Operation;
82
99
  fulfillments?: fulfillemtMethodsSDK.FulfillmentMethod[];
83
100
  }
@@ -5,3 +5,12 @@ export var DispatchType;
5
5
  /** Delivery fulfillment */
6
6
  DispatchType["DELIVERY"] = "DELIVERY";
7
7
  })(DispatchType || (DispatchType = {}));
8
+ export var FulfillmentTypeEnum;
9
+ (function (FulfillmentTypeEnum) {
10
+ /** ASAP - Order will be fulfilled as soon as possible */
11
+ FulfillmentTypeEnum["ASAP"] = "ASAP";
12
+ /** PREORDER - Order will be fulfilled at a scheduled time */
13
+ FulfillmentTypeEnum["PREORDER"] = "PREORDER";
14
+ /** ASAP_AND_FUTURE - Both ASAP and future scheduling available */
15
+ FulfillmentTypeEnum["ASAP_AND_FUTURE"] = "ASAP_AND_FUTURE";
16
+ })(FulfillmentTypeEnum || (FulfillmentTypeEnum = {}));
@@ -0,0 +1,164 @@
1
+ import { TimeOfDay, TimeOfDayRange, EntitiesDayOfWeek as DayOfWeek } from '@wix/auto_sdk_restaurants_fulfillment-methods';
2
+ export { TimeOfDay, TimeOfDayRange, DayOfWeek };
3
+ /**
4
+ * Get the current locale
5
+ * Uses the configured locale, falls back to i18n.getLocale()
6
+ *
7
+ * @returns The current locale string
8
+ */
9
+ export declare const getLocale: () => string;
10
+ /**
11
+ * Get the current timezone
12
+ * Uses the configured timezone, falls back to undefined (browser default)
13
+ *
14
+ * @returns The current timezone string or undefined
15
+ */
16
+ export declare const getTimezone: () => string | undefined;
17
+ /**
18
+ * Mapping of day of week enum to numeric value (1-7, Monday-Sunday)
19
+ */
20
+ export declare const DAY_OF_WEEK: {
21
+ MON: number;
22
+ TUE: number;
23
+ WED: number;
24
+ THU: number;
25
+ FRI: number;
26
+ SAT: number;
27
+ SUN: number;
28
+ };
29
+ /**
30
+ * Extract date/time parts from a Date in a specific timezone
31
+ * @param date - The source Date object
32
+ * @param timezone - The target timezone (e.g., 'America/New_York'). Defaults to configured timezone.
33
+ * @param locale - The locale for formatting (e.g., 'en-US'). Defaults to configured locale.
34
+ * @param includeTime - Whether to include time parts (hour, minute, second)
35
+ * @returns Object containing the extracted date/time parts
36
+ */
37
+ export declare const getDatePartsInTimezone: (date: Date, timezone?: string, locale?: string, includeTime?: boolean) => {
38
+ year: string;
39
+ month: string;
40
+ day: string;
41
+ hour?: string;
42
+ minute?: string;
43
+ second?: string;
44
+ };
45
+ /**
46
+ * Build a Date from date/time parts
47
+ * @param year - Year string
48
+ * @param month - Month string (2-digit)
49
+ * @param day - Day string (2-digit)
50
+ * @param hour - Hour string (2-digit, optional)
51
+ * @param minute - Minute string (2-digit, optional)
52
+ * @param second - Second string (2-digit, optional)
53
+ * @returns A new Date object
54
+ */
55
+ export declare const buildDateFromParts: (year: string, month: string, day: string, hour?: string, minute?: string, second?: string) => Date;
56
+ /**
57
+ * Convert a TimeOfDay object to a Date object
58
+ * Creates a Date for today with the specified time in the target timezone.
59
+ * Equivalent to: DateTime.fromObject({ hour, minute }).setZone(timezone, { keepLocalTime: true })
60
+ *
61
+ * @param time - TimeOfDay object with hours and minutes
62
+ * @param timezone - The target timezone (e.g., 'America/New_York'). Defaults to configured timezone.
63
+ * @returns A Date object representing the time in the specified timezone
64
+ */
65
+ export declare const convertTimeOfDayToDateTime: (time: TimeOfDay, timezone?: string) => Date;
66
+ /**
67
+ * Convert a Date to a Date adjusted for a specific timezone
68
+ * This is useful when you need to display or compare dates in a specific timezone
69
+ *
70
+ * @param date - The source Date object
71
+ * @param timezone - The target timezone (e.g., 'America/New_York'). Defaults to configured timezone.
72
+ * @param locale - The locale for formatting (e.g., 'en-US'). Defaults to configured locale.
73
+ * @returns A new Date object adjusted to represent the same moment in the target timezone
74
+ */
75
+ export declare const convertDateToTimezone: (date: Date, timezone?: string, locale?: string) => Date;
76
+ /**
77
+ * Format a Date as a localized string for a specific timezone and locale
78
+ *
79
+ * @param date - The source Date object
80
+ * @param timezone - The target timezone (e.g., 'America/New_York'). Defaults to configured timezone.
81
+ * @param locale - The locale for formatting (e.g., 'en-US'). Defaults to configured locale.
82
+ * @param options - Additional Intl.DateTimeFormatOptions
83
+ * @returns A formatted date string
84
+ */
85
+ export declare const formatDateInTimezone: (date: Date, timezone?: string, locale?: string, options?: Intl.DateTimeFormatOptions) => string;
86
+ /**
87
+ * Check if a time falls within a time range
88
+ *
89
+ * @param time - The time to check
90
+ * @param range - The time range to check against
91
+ * @param timeZone - The timezone for conversion. Defaults to configured timezone.
92
+ * @param locale - The locale for formatting. Defaults to configured locale.
93
+ * @returns True if the time is within the range
94
+ */
95
+ export declare const isInTimeRange: (time: Date, range: TimeOfDayRange, timeZone?: string) => boolean;
96
+ /**
97
+ * Get the current day of week as a number (1-7, Monday-Sunday)
98
+ * JavaScript's getDay() returns 0 (Sunday) to 6 (Saturday),
99
+ * this function converts to 1 (Monday) to 7 (Sunday)
100
+ *
101
+ * @param date - The date to get the day of week from
102
+ * @returns The day of week as a number (1-7)
103
+ */
104
+ export declare const getDayOfWeekNumber: (date: Date) => number;
105
+ /**
106
+ * Format a date as time only (e.g., "10:30 AM")
107
+ * Uses configured locale and timezone
108
+ *
109
+ * @param date - The date to format
110
+ * @param options - Additional Intl.DateTimeFormatOptions (defaults to hour:numeric, minute:numeric)
111
+ * @returns A formatted time string, or empty string if date is undefined
112
+ */
113
+ export declare const formatTime: (date?: Date, options?: Intl.DateTimeFormatOptions) => string;
114
+ /**
115
+ * Format a time range as a localized string
116
+ * If start and end times are the same, returns just the time
117
+ * Otherwise returns "start - end" format
118
+ *
119
+ * @param startTime - The start time
120
+ * @param endTime - The end time
121
+ * @param options - Additional Intl.DateTimeFormatOptions (defaults to hour:numeric, minute:numeric, hour12:true)
122
+ * @returns A formatted time range string
123
+ */
124
+ export declare const formatTimeRange: (startTime: Date, endTime: Date, options?: Intl.DateTimeFormatOptions) => string;
125
+ /**
126
+ * Check if two dates are on the same calendar day
127
+ * Compares year, month, and day components
128
+ *
129
+ * @param date1 - The first date to compare
130
+ * @param date2 - The second date to compare
131
+ * @returns True if both dates are on the same calendar day
132
+ */
133
+ export declare const isSameDay: (date1: Date, date2: Date) => boolean;
134
+ /**
135
+ * Get today's date with time set to midnight (00:00:00.000)
136
+ *
137
+ * @returns A Date object representing the start of today
138
+ */
139
+ export declare const getToday: () => Date;
140
+ /**
141
+ * Get a future date with time set to 23:59:59.999
142
+ *
143
+ * @param days - The number of days to add to the current date
144
+ * @returns A Date object representing the end of the future date
145
+ */
146
+ export declare const getFutureDate: (days: number) => Date;
147
+ /**
148
+ * Create a Date object from year, month, and day numbers
149
+ * Adjusts for timezone offset to ensure the date represents the correct local date
150
+ *
151
+ * @param year - The year (e.g., 2024)
152
+ * @param month - The month (1-12, where 1 is January)
153
+ * @param day - The day of the month (1-31)
154
+ * @returns A Date object representing midnight on the specified date in local time
155
+ */
156
+ export declare const createDateFromYMD: (year: number, month: number, day: number) => Date;
157
+ /**
158
+ * Format a Date as an ISO date string (YYYY-MM-DD)
159
+ * Useful for HTML date input values and attributes
160
+ *
161
+ * @param date - The date to format
162
+ * @returns A string in YYYY-MM-DD format
163
+ */
164
+ export declare const toISODateString: (date: Date) => string;
@@ -0,0 +1,297 @@
1
+ import { EntitiesDayOfWeek as DayOfWeek, } from '@wix/auto_sdk_restaurants_fulfillment-methods';
2
+ import { i18n, settings } from '@wix/essentials';
3
+ // Re-export types for convenience
4
+ export { DayOfWeek };
5
+ const dateConfig = {
6
+ timezone: settings.getTimezone(),
7
+ locale: i18n.getLocale(),
8
+ };
9
+ /**
10
+ * Get the current locale
11
+ * Uses the configured locale, falls back to i18n.getLocale()
12
+ *
13
+ * @returns The current locale string
14
+ */
15
+ export const getLocale = () => {
16
+ return dateConfig.locale;
17
+ };
18
+ /**
19
+ * Get the current timezone
20
+ * Uses the configured timezone, falls back to undefined (browser default)
21
+ *
22
+ * @returns The current timezone string or undefined
23
+ */
24
+ export const getTimezone = () => {
25
+ return dateConfig.timezone;
26
+ };
27
+ /**
28
+ * Mapping of day of week enum to numeric value (1-7, Monday-Sunday)
29
+ */
30
+ export const DAY_OF_WEEK = {
31
+ [DayOfWeek.MON]: 1,
32
+ [DayOfWeek.TUE]: 2,
33
+ [DayOfWeek.WED]: 3,
34
+ [DayOfWeek.THU]: 4,
35
+ [DayOfWeek.FRI]: 5,
36
+ [DayOfWeek.SAT]: 6,
37
+ [DayOfWeek.SUN]: 7,
38
+ };
39
+ /**
40
+ * Extract date/time parts from a Date in a specific timezone
41
+ * @param date - The source Date object
42
+ * @param timezone - The target timezone (e.g., 'America/New_York'). Defaults to configured timezone.
43
+ * @param locale - The locale for formatting (e.g., 'en-US'). Defaults to configured locale.
44
+ * @param includeTime - Whether to include time parts (hour, minute, second)
45
+ * @returns Object containing the extracted date/time parts
46
+ */
47
+ export const getDatePartsInTimezone = (date, timezone, locale, includeTime = false) => {
48
+ const tz = timezone ?? getTimezone();
49
+ const loc = locale ?? getLocale();
50
+ const options = {
51
+ timeZone: tz,
52
+ year: 'numeric',
53
+ month: '2-digit',
54
+ day: '2-digit',
55
+ ...(includeTime && {
56
+ hour: '2-digit',
57
+ minute: '2-digit',
58
+ second: '2-digit',
59
+ hour12: false,
60
+ }),
61
+ };
62
+ const parts = new Intl.DateTimeFormat(loc, options).formatToParts(date);
63
+ return {
64
+ year: parts.find((p) => p.type === 'year')?.value ?? '1970',
65
+ month: parts.find((p) => p.type === 'month')?.value ?? '01',
66
+ day: parts.find((p) => p.type === 'day')?.value ?? '01',
67
+ ...(includeTime && {
68
+ hour: parts.find((p) => p.type === 'hour')?.value ?? '00',
69
+ minute: parts.find((p) => p.type === 'minute')?.value ?? '00',
70
+ second: parts.find((p) => p.type === 'second')?.value ?? '00',
71
+ }),
72
+ };
73
+ };
74
+ /**
75
+ * Build a Date from date/time parts
76
+ * @param year - Year string
77
+ * @param month - Month string (2-digit)
78
+ * @param day - Day string (2-digit)
79
+ * @param hour - Hour string (2-digit, optional)
80
+ * @param minute - Minute string (2-digit, optional)
81
+ * @param second - Second string (2-digit, optional)
82
+ * @returns A new Date object
83
+ */
84
+ export const buildDateFromParts = (year, month, day, hour = '00', minute = '00', second = '00') => {
85
+ const isoString = `${year}-${month}-${day}T${hour}:${minute}:${second}.000`;
86
+ return new Date(isoString);
87
+ };
88
+ /**
89
+ * Convert a TimeOfDay object to a Date object
90
+ * Creates a Date for today with the specified time in the target timezone.
91
+ * Equivalent to: DateTime.fromObject({ hour, minute }).setZone(timezone, { keepLocalTime: true })
92
+ *
93
+ * @param time - TimeOfDay object with hours and minutes
94
+ * @param timezone - The target timezone (e.g., 'America/New_York'). Defaults to configured timezone.
95
+ * @returns A Date object representing the time in the specified timezone
96
+ */
97
+ export const convertTimeOfDayToDateTime = (time, timezone) => {
98
+ console.log('timezone', timezone);
99
+ // const tz = timezone ?? getTimezone();
100
+ // Create today's date with the specified time in local timezone
101
+ // This mimics DateTime.fromObject({ hour, minute }) which uses local timezone
102
+ const localDate = new Date();
103
+ localDate.setHours(time.hours ?? 0, time.minutes ?? 0, 0, 0);
104
+ // If no timezone specified, return local time (no zone conversion)
105
+ // if (!tz) {
106
+ return localDate;
107
+ // }
108
+ // Apply setZone(timezone, { keepLocalTime: true })
109
+ // This keeps the wall clock time (e.g., "10:30") but changes the timezone
110
+ // We need to find the UTC time that, when displayed in the target timezone, shows the same wall clock time
111
+ // Get what localDate looks like in the target timezone
112
+ // const parts = getDatePartsInTimezone(localDate, tz, undefined, true);
113
+ // const inTargetTz = buildDateFromParts(
114
+ // parts.year,
115
+ // parts.month,
116
+ // parts.day,
117
+ // parts.hour!,
118
+ // parts.minute!,
119
+ // parts.second!,
120
+ // );
121
+ // The offset between localDate and its representation in target timezone
122
+ // Adding this offset gives us a Date that shows the same wall clock time in target timezone
123
+ // const offsetMs = localDate.getTime() - inTargetTz.getTime();
124
+ // return new Date(localDate.getTime() + offsetMs);
125
+ };
126
+ /**
127
+ * Convert a Date to a Date adjusted for a specific timezone
128
+ * This is useful when you need to display or compare dates in a specific timezone
129
+ *
130
+ * @param date - The source Date object
131
+ * @param timezone - The target timezone (e.g., 'America/New_York'). Defaults to configured timezone.
132
+ * @param locale - The locale for formatting (e.g., 'en-US'). Defaults to configured locale.
133
+ * @returns A new Date object adjusted to represent the same moment in the target timezone
134
+ */
135
+ export const convertDateToTimezone = (date, timezone, locale) => {
136
+ const tz = timezone ?? getTimezone();
137
+ const loc = locale ?? getLocale();
138
+ if (!tz) {
139
+ return new Date(date);
140
+ }
141
+ const { year, month, day, hour, minute, second } = getDatePartsInTimezone(date, tz, loc, true);
142
+ return buildDateFromParts(year, month, day, hour, minute, second);
143
+ };
144
+ /**
145
+ * Format a Date as a localized string for a specific timezone and locale
146
+ *
147
+ * @param date - The source Date object
148
+ * @param timezone - The target timezone (e.g., 'America/New_York'). Defaults to configured timezone.
149
+ * @param locale - The locale for formatting (e.g., 'en-US'). Defaults to configured locale.
150
+ * @param options - Additional Intl.DateTimeFormatOptions
151
+ * @returns A formatted date string
152
+ */
153
+ export const formatDateInTimezone = (date, timezone, locale, options) => {
154
+ const tz = timezone ?? getTimezone();
155
+ const loc = locale ?? getLocale();
156
+ const formatOptions = {
157
+ ...options,
158
+ timeZone: tz,
159
+ };
160
+ return date.toLocaleString(loc, formatOptions);
161
+ };
162
+ /**
163
+ * Check if a time falls within a time range
164
+ *
165
+ * @param time - The time to check
166
+ * @param range - The time range to check against
167
+ * @param timeZone - The timezone for conversion. Defaults to configured timezone.
168
+ * @param locale - The locale for formatting. Defaults to configured locale.
169
+ * @returns True if the time is within the range
170
+ */
171
+ export const isInTimeRange = (time, range, timeZone) => {
172
+ const tz = timeZone ?? getTimezone();
173
+ const startTime = range.startTime
174
+ ? convertTimeOfDayToDateTime(range.startTime, tz)
175
+ : time;
176
+ const endTime = range.endTime
177
+ ? convertTimeOfDayToDateTime(range.endTime, tz)
178
+ : time;
179
+ return (time.getTime() >= startTime.getTime() && time.getTime() <= endTime.getTime());
180
+ };
181
+ /**
182
+ * Get the current day of week as a number (1-7, Monday-Sunday)
183
+ * JavaScript's getDay() returns 0 (Sunday) to 6 (Saturday),
184
+ * this function converts to 1 (Monday) to 7 (Sunday)
185
+ *
186
+ * @param date - The date to get the day of week from
187
+ * @returns The day of week as a number (1-7)
188
+ */
189
+ export const getDayOfWeekNumber = (date) => {
190
+ const jsDay = date.getDay();
191
+ return jsDay === 0 ? 7 : jsDay;
192
+ };
193
+ /**
194
+ * Format a date as time only (e.g., "10:30 AM")
195
+ * Uses configured locale and timezone
196
+ *
197
+ * @param date - The date to format
198
+ * @param options - Additional Intl.DateTimeFormatOptions (defaults to hour:numeric, minute:numeric)
199
+ * @returns A formatted time string, or empty string if date is undefined
200
+ */
201
+ export const formatTime = (date, options) => {
202
+ if (!date)
203
+ return '';
204
+ const tz = getTimezone();
205
+ const loc = getLocale();
206
+ const formatOptions = {
207
+ hour: 'numeric',
208
+ minute: 'numeric',
209
+ ...options,
210
+ timeZone: tz,
211
+ };
212
+ return date.toLocaleString(loc, formatOptions);
213
+ };
214
+ /**
215
+ * Format a time range as a localized string
216
+ * If start and end times are the same, returns just the time
217
+ * Otherwise returns "start - end" format
218
+ *
219
+ * @param startTime - The start time
220
+ * @param endTime - The end time
221
+ * @param options - Additional Intl.DateTimeFormatOptions (defaults to hour:numeric, minute:numeric, hour12:true)
222
+ * @returns A formatted time range string
223
+ */
224
+ export const formatTimeRange = (startTime, endTime, options) => {
225
+ const tz = getTimezone();
226
+ const loc = getLocale();
227
+ const formatOptions = {
228
+ hour: 'numeric',
229
+ minute: 'numeric',
230
+ hour12: true,
231
+ ...options,
232
+ timeZone: tz,
233
+ };
234
+ const start = startTime.toLocaleString(loc, formatOptions);
235
+ const end = endTime.toLocaleString(loc, formatOptions);
236
+ return start === end ? start : `${start} - ${end}`;
237
+ };
238
+ /**
239
+ * Check if two dates are on the same calendar day
240
+ * Compares year, month, and day components
241
+ *
242
+ * @param date1 - The first date to compare
243
+ * @param date2 - The second date to compare
244
+ * @returns True if both dates are on the same calendar day
245
+ */
246
+ export const isSameDay = (date1, date2) => {
247
+ return (date1.getFullYear() === date2.getFullYear() &&
248
+ date1.getMonth() === date2.getMonth() &&
249
+ date1.getDate() === date2.getDate());
250
+ };
251
+ /**
252
+ * Get today's date with time set to midnight (00:00:00.000)
253
+ *
254
+ * @returns A Date object representing the start of today
255
+ */
256
+ export const getToday = () => {
257
+ const today = new Date();
258
+ today.setHours(0, 0, 0, 0);
259
+ return today;
260
+ };
261
+ /**
262
+ * Get a future date with time set to 23:59:59.999
263
+ *
264
+ * @param days - The number of days to add to the current date
265
+ * @returns A Date object representing the end of the future date
266
+ */
267
+ export const getFutureDate = (days) => {
268
+ const future = new Date();
269
+ future.setDate(future.getDate() + days);
270
+ future.setHours(23, 59, 59, 999);
271
+ return future;
272
+ };
273
+ /**
274
+ * Create a Date object from year, month, and day numbers
275
+ * Adjusts for timezone offset to ensure the date represents the correct local date
276
+ *
277
+ * @param year - The year (e.g., 2024)
278
+ * @param month - The month (1-12, where 1 is January)
279
+ * @param day - The day of the month (1-31)
280
+ * @returns A Date object representing midnight on the specified date in local time
281
+ */
282
+ export const createDateFromYMD = (year, month, day) => {
283
+ const date = new Date(year, month - 1, day);
284
+ // Adjust for timezone offset to ensure the date is correct in local time
285
+ const timezoneOffset = date.getTimezoneOffset() * 60000;
286
+ return new Date(date.getTime() - timezoneOffset);
287
+ };
288
+ /**
289
+ * Format a Date as an ISO date string (YYYY-MM-DD)
290
+ * Useful for HTML date input values and attributes
291
+ *
292
+ * @param date - The date to format
293
+ * @returns A string in YYYY-MM-DD format
294
+ */
295
+ export const toISODateString = (date) => {
296
+ return date.toISOString().split('T')[0];
297
+ };
@@ -3,6 +3,7 @@ import { DispatchesInfo, TimeSlot } from '../types/fulfillments-types.js';
3
3
  import { Operation } from '../types/operation.js';
4
4
  import * as fulfillemtMethodsSDK from '@wix/auto_sdk_restaurants_fulfillment-methods';
5
5
  import { FulfillmentDetails } from '@wix/auto_sdk_restaurants_operations';
6
+ export { convertTimeOfDayToDateTime, convertDateToTimezone, formatDateInTimezone, formatTime, formatTimeRange, getDatePartsInTimezone, buildDateFromParts, isInTimeRange, DAY_OF_WEEK, DayOfWeek, getDayOfWeekNumber, TimeOfDay, TimeOfDayRange, getLocale, getTimezone, } from './date-utils.js';
6
7
  /**
7
8
  * Format a string with placeholders like {0}, {1}, etc.
8
9
  * Similar to C#'s String.Format
@@ -49,8 +50,8 @@ export declare const createTimeRange: (arr: FulfillmentDetails[]) => {
49
50
  };
50
51
  maxTimeOptions?: undefined;
51
52
  };
52
- export declare const processFulfillments: (fulfillments: fulfillemtMethodsSDK.FulfillmentMethod[], timeSlots: TimeSlot[], operation: Operation) => Promise<{
53
+ export declare const processFulfillments: (fulfillments: fulfillemtMethodsSDK.FulfillmentMethod[], timeSlots: TimeSlot[], operation: Operation) => {
53
54
  dispatchesInfo: DispatchesInfo;
54
55
  isPickupConfigured: boolean;
55
56
  isDeliveryConfigured: boolean;
56
- } | undefined>;
57
+ } | undefined;