@synerise/ds-date-range-picker 2.1.7 → 2.2.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/CLAUDE.md +11 -1
  3. package/README.md +51 -0
  4. package/dist/DateRangePicker.js +6 -3
  5. package/dist/DateRangePicker.types.d.ts +8 -1
  6. package/dist/Footer/Footer.d.ts +1 -1
  7. package/dist/Footer/Footer.js +8 -6
  8. package/dist/Footer/Footer.types.d.ts +6 -0
  9. package/dist/RangeFilter/Filters/MonthlyFilter/MonthlyFilter.js +2 -2
  10. package/dist/RangeFilter/Filters/new/Monthly/Monthly.js +2 -2
  11. package/dist/RangeFilter/Filters/new/Weekly/Weekly.js +2 -2
  12. package/dist/RangeFilter/RangeFilter.js +2 -2
  13. package/dist/RangeFilter/Shared/TimeWindow/Day/Day.js +1 -1
  14. package/dist/RangeFilter/constants.js +2 -2
  15. package/dist/RangePicker/RangePicker.js +22 -15
  16. package/dist/RangePicker/RangePicker.types.d.ts +6 -0
  17. package/dist/RangePicker/utils.d.ts +2 -2
  18. package/dist/RangePicker/utils.js +4 -5
  19. package/dist/RangePickerInput/RangePickerInput.d.ts +1 -1
  20. package/dist/RangePickerInput/RangePickerInput.js +14 -9
  21. package/dist/RangePickerInput/RangePickerInput.types.d.ts +6 -0
  22. package/dist/RawDateRangePicker.d.ts +1 -1
  23. package/dist/RawDateRangePicker.js +45 -24
  24. package/dist/RelativeRangePicker/Elements/CustomRangeForm/CustomRangeForm.d.ts +1 -1
  25. package/dist/RelativeRangePicker/Elements/CustomRangeForm/CustomRangeForm.js +5 -4
  26. package/dist/RelativeRangePicker/Elements/CustomRangeForm/CustomRangeForm.types.d.ts +2 -0
  27. package/dist/RelativeRangePicker/Elements/CustomRangeForm/DurationField/DurationField.js +2 -2
  28. package/dist/RelativeRangePicker/Elements/RangeButtons/RangeButtons.js +2 -2
  29. package/dist/RelativeRangePicker/Elements/RangeDropdown/RangeDropdown.js +3 -3
  30. package/dist/RelativeRangePicker/Elements/TimestampRange/TimestampRange.js +15 -12
  31. package/dist/RelativeRangePicker/Elements/TimestampRange/TimestampRange.types.d.ts +2 -0
  32. package/dist/RelativeRangePicker/RelativeRangePicker.js +15 -8
  33. package/dist/RelativeRangePicker/RelativeRangePicker.types.d.ts +2 -0
  34. package/dist/RelativeRangePicker/utils/setDurationValue.utils.js +2 -2
  35. package/dist/RelativeRangePicker/utils/setFuture.utils.js +2 -2
  36. package/dist/RelativeRangePicker/utils/setOffsetValue.utils.js +2 -2
  37. package/dist/date.types.d.ts +1 -0
  38. package/dist/dateUtils/displayDate.d.ts +19 -0
  39. package/dist/dateUtils/displayDate.js +10 -0
  40. package/dist/dateUtils/getNow.d.ts +11 -0
  41. package/dist/dateUtils/getNow.js +5 -0
  42. package/dist/dateUtils/relativeToAbsolute.d.ts +1 -1
  43. package/dist/dateUtils/relativeToAbsolute.js +3 -2
  44. package/dist/utils.d.ts +9 -1
  45. package/dist/utils.js +12 -5
  46. package/package.json +28 -25
@@ -4,6 +4,12 @@ import { FormFieldCommonProps } from '@synerise/ds-form-field';
4
4
  import { Texts } from '../DateRangePicker.types';
5
5
  import { DateFilter, DateRange } from '../date.types';
6
6
  export type RangePickerInputProps = {
7
+ /**
8
+ * The zone the `timeZone` prop resolved to, or `undefined` when it was not set. Read from a
9
+ * prop rather than `intl`, so a consumer that has not opted in keeps rendering the way it
10
+ * does today.
11
+ */
12
+ timeZone?: string;
7
13
  size?: 'large' | 'default' | 'small';
8
14
  valueFormatOptions?: DateToFormatOptions;
9
15
  showTime?: boolean;
@@ -2,5 +2,5 @@ import { default as React } from 'react';
2
2
  import { DateRangePickerProps } from './DateRangePicker.types';
3
3
  import { DateRange } from './date.types';
4
4
  export declare function defaultValueTransformer(value: DateRange): DateRange;
5
- export declare const RawDateRangePicker: ({ showRelativePicker, showFilter, showTime, valueFormatOptions, disabledDate, validate, forceAdjacentMonths, savedFilters, onFilterSave, containerClass, footerProps, allowedFilterTypes, disableAbsoluteTimepickerInRelative, filterValueSelectionModes, filterRangeDisplayMode, showNowButton, relativeFuture, relativePast, ranges, relativeModes, rangeUnits, showCustomRange, valueTransformer, onValueChange, isTruncateMs, forceAbsolute, onApply, texts, value, }: Omit<DateRangePickerProps, "placement">) => React.JSX.Element;
5
+ export declare const RawDateRangePicker: ({ showRelativePicker, showFilter, showTime, valueFormatOptions, disabledDate, validate, forceAdjacentMonths, savedFilters, onFilterSave, containerClass, footerProps, allowedFilterTypes, disableAbsoluteTimepickerInRelative, filterValueSelectionModes, filterRangeDisplayMode, showNowButton, relativeFuture, relativePast, ranges, relativeModes, rangeUnits, showCustomRange, valueTransformer, onValueChange, isTruncateMs, forceAbsolute, onApply, texts, value, timeZone: timeZoneProp, }: Omit<DateRangePickerProps, "placement">) => React.JSX.Element;
6
6
  export default RawDateRangePicker;
@@ -4,6 +4,7 @@ import isUndefined from "lodash.isundefined";
4
4
  import omitBy from "lodash.omitby";
5
5
  import { useState, useEffect, useMemo, useCallback } from "react";
6
6
  import { useIntl } from "react-intl";
7
+ import { getTimeZone, applyTimezoneOffset, toIsoString } from "@synerise/ds-core";
7
8
  import AddonCollapse from "./AddonCollapse/AddonCollapse.js";
8
9
  import { MODES, ALL_TIME, RELATIVE, ABSOLUTE, RELATIVE_PRESETS, ABSOLUTE_PRESETS, CUSTOM_RANGE_KEY } from "./constants.js";
9
10
  import { Container, Separator, Addon, DateRangePickerWrapper } from "./DateRangePicker.styles.js";
@@ -15,8 +16,13 @@ import RangeFilterStatus from "./RangeFilter/Shared/RangeFilterStatus/RangeFilte
15
16
  import RangePicker from "./RangePicker/RangePicker.js";
16
17
  import { isLifetime } from "./RelativeRangePicker/Elements/RangeDropdown/RangeDropdown.js";
17
18
  import RelativeRangePicker from "./RelativeRangePicker/RelativeRangePicker.js";
18
- import { normalizeRange, getDefaultTexts } from "./utils.js";
19
- import { toIsoString } from "@synerise/ds-core";
19
+ import { normalizeRange, getDefaultTexts, normalizeLocalRange } from "./utils.js";
20
+ const toEmittedLimit = (limit, timeZone, asZonedDate) => {
21
+ if (!(limit instanceof Date)) {
22
+ return void 0;
23
+ }
24
+ return asZonedDate ? applyTimezoneOffset(limit, timeZone, void 0) : toIsoString(limit, timeZone);
25
+ };
20
26
  const isRelative = (dateRange) => {
21
27
  const isLegacyCustom = Object.keys(dateRange).includes("key") && dateRange.key === void 0;
22
28
  return dateRange.key && (RELATIVE_PRESETS.map((preset) => preset.key).includes(dateRange.key) || dateRange.key === CUSTOM_RANGE_KEY) || isLegacyCustom;
@@ -107,18 +113,20 @@ const RawDateRangePicker = ({
107
113
  forceAbsolute,
108
114
  onApply,
109
115
  texts,
110
- value
116
+ value,
117
+ timeZone: timeZoneProp
111
118
  }) => {
112
- const [localValue, setLocalValue] = useState(normalizeRange(value));
119
+ const intl = useIntl();
120
+ const resolvedTimeZone = getTimeZone(timeZoneProp, intl);
121
+ const emitZonedDates = Boolean(timeZoneProp);
122
+ const timeZone = resolvedTimeZone;
123
+ const encodeTimeZone = resolvedTimeZone ?? intl.timeZone;
124
+ const [localValue, setLocalValue] = useState(normalizeRange(value, timeZone));
113
125
  const [mode, setMode] = useState(MODES.DATE);
114
126
  const [visibleAddonKey, setVisibleAddonKey] = useState("relative-picker");
115
- const intl = useIntl();
116
- const {
117
- timeZone
118
- } = intl;
119
127
  useEffect(() => {
120
- setLocalValue(normalizeRange(value));
121
- }, [value]);
128
+ setLocalValue(normalizeRange(value, timeZone));
129
+ }, [value, timeZone]);
122
130
  const allTexts = useMemo(() => {
123
131
  return getDefaultTexts(intl, false, texts);
124
132
  }, [intl, texts]);
@@ -129,10 +137,10 @@ const RawDateRangePicker = ({
129
137
  if (range.from && !isValid(range?.from)) {
130
138
  return;
131
139
  }
132
- const newValue = normalizeRange({
140
+ const newValue = normalizeLocalRange({
133
141
  ...range,
134
142
  filter: localValue.filter
135
- });
143
+ }, timeZone);
136
144
  if (isTruncateMs) {
137
145
  if (newValue.from !== void 0) {
138
146
  newValue.from = startOfSecond(toDateValue(newValue.from));
@@ -152,8 +160,16 @@ const RawDateRangePicker = ({
152
160
  ...legacyValue,
153
161
  translationKey: range?.translationKey
154
162
  });
155
- onValueChange && onValueChange(legacyValue);
156
- }, [isTruncateMs, mode, localValue.filter, onValueChange, valueTransformer]);
163
+ onValueChange && onValueChange(timeZoneProp ? {
164
+ ...legacyValue,
165
+ ...legacyValue.from ? {
166
+ from: toEmittedLimit(legacyValue.from, encodeTimeZone, emitZonedDates)
167
+ } : {},
168
+ ...legacyValue.to ? {
169
+ to: toEmittedLimit(legacyValue.to, encodeTimeZone, emitZonedDates)
170
+ } : {}
171
+ } : legacyValue);
172
+ }, [isTruncateMs, mode, localValue.filter, onValueChange, timeZone, timeZoneProp, encodeTimeZone, emitZonedDates, valueTransformer]);
157
173
  const handleAddonCollapse = useCallback((addonKey, expanded) => {
158
174
  setVisibleAddonKey(expanded ? addonKey : void 0);
159
175
  }, []);
@@ -175,9 +191,14 @@ const RawDateRangePicker = ({
175
191
  }, []);
176
192
  const handleApply = useCallback(() => {
177
193
  if (forceAbsolute && localValue.type === RELATIVE) {
194
+ const resolved = relativeToAbsolute(localValue, timeZone);
178
195
  onApply && onApply({
179
196
  ...localValue,
180
- ...relativeToAbsolute(localValue)
197
+ ...resolved,
198
+ ...timeZoneProp ? {
199
+ from: toEmittedLimit(resolved.from, encodeTimeZone, emitZonedDates),
200
+ to: toEmittedLimit(resolved.to, encodeTimeZone, emitZonedDates)
201
+ } : {}
181
202
  });
182
203
  return;
183
204
  }
@@ -188,13 +209,13 @@ const RawDateRangePicker = ({
188
209
  if (onApply) {
189
210
  const valueToEmit = {
190
211
  ...localValue,
191
- from: localValue.type === ABSOLUTE && localValue.from instanceof Date ? toIsoString(localValue.from, timeZone) : void 0,
192
- to: localValue.type === ABSOLUTE && localValue.to instanceof Date ? toIsoString(localValue.to, timeZone) : void 0,
212
+ from: localValue.type === ABSOLUTE ? toEmittedLimit(localValue.from, encodeTimeZone, emitZonedDates) : void 0,
213
+ to: localValue.type === ABSOLUTE ? toEmittedLimit(localValue.to, encodeTimeZone, emitZonedDates) : void 0,
193
214
  type: localValue.type
194
215
  };
195
216
  onApply(valueToEmit);
196
217
  }
197
- }, [forceAbsolute, timeZone, localValue, onApply]);
218
+ }, [forceAbsolute, timeZone, timeZoneProp, encodeTimeZone, emitZonedDates, localValue, onApply]);
198
219
  const handleSwitchMode = useCallback(() => {
199
220
  const updatedMode = mode === MODES.TIME ? MODES.DATE : MODES.TIME;
200
221
  setMode(updatedMode);
@@ -204,7 +225,7 @@ const RawDateRangePicker = ({
204
225
  const {
205
226
  to,
206
227
  from
207
- } = normalizeRange(localValue);
228
+ } = normalizeLocalRange(localValue, timeZone);
208
229
  return {
209
230
  ...localValue,
210
231
  from,
@@ -212,14 +233,14 @@ const RawDateRangePicker = ({
212
233
  };
213
234
  }
214
235
  return localValue;
215
- }, [localValue]);
236
+ }, [localValue, timeZone]);
216
237
  const addons = useMemo(() => {
217
238
  const result = [];
218
239
  if (showRelativePicker && relativeModes && relativeModes?.length > 0) {
219
240
  const addonKey = "relative-picker";
220
241
  const rangeTranslationKey = localValue?.translationKey;
221
242
  result.push({
222
- content: /* @__PURE__ */ jsx(AddonCollapse, { content: /* @__PURE__ */ jsx(RelativeRangePicker, { future: relativeFuture, past: relativePast, ranges, value: localValue, onChange: handleRangeChange, relativeModes, texts: allTexts, rangeUnits, showCustomRange, valueTransformer }), expanded: addonKey === visibleAddonKey, title: allTexts.relativeDateRange, onCollapseChange: (expanded) => handleAddonCollapse(addonKey, expanded), collapsedSummary: rangeTranslationKey && allTexts[rangeTranslationKey] }),
243
+ content: /* @__PURE__ */ jsx(AddonCollapse, { content: /* @__PURE__ */ jsx(RelativeRangePicker, { future: relativeFuture, past: relativePast, ranges, value: localValue, onChange: handleRangeChange, relativeModes, texts: allTexts, rangeUnits, showCustomRange, valueTransformer, timeZone }), expanded: addonKey === visibleAddonKey, title: allTexts.relativeDateRange, onCollapseChange: (expanded) => handleAddonCollapse(addonKey, expanded), collapsedSummary: rangeTranslationKey && allTexts[rangeTranslationKey] }),
223
244
  key: addonKey
224
245
  });
225
246
  }
@@ -233,7 +254,7 @@ const RawDateRangePicker = ({
233
254
  });
234
255
  }
235
256
  return result;
236
- }, [showRelativePicker, relativeModes, showFilter, localValue, relativeFuture, relativePast, ranges, handleRangeChange, allTexts, rangeUnits, showCustomRange, valueTransformer, visibleAddonKey, handleAddonCollapse, fullValue, handleRemoveFilterClick, handleModalOpenClick]);
257
+ }, [showRelativePicker, relativeModes, showFilter, timeZone, localValue, relativeFuture, relativePast, ranges, handleRangeChange, allTexts, rangeUnits, showCustomRange, valueTransformer, visibleAddonKey, handleAddonCollapse, fullValue, handleRemoveFilterClick, handleModalOpenClick]);
237
258
  let content;
238
259
  if (mode === MODES.FILTER) {
239
260
  content = /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(RangeFilter, { texts: allTexts, value: localValue.filter, onCancel: handleFilterCancel, onApply: handleFilterApply, savedFilters, allowedFilterTypes, onFilterSave, valueSelectionModes: filterValueSelectionModes, rangeDisplayMode: filterRangeDisplayMode }) });
@@ -252,10 +273,10 @@ const RawDateRangePicker = ({
252
273
  const isValid2 = (isValidAbsolute || isValidRelative || isValidSince || key === ALL_TIME) && validator.valid;
253
274
  const canSwitchToTimePicker = isValid2 && !isLifetime(localValue) && (!disableAbsoluteTimepickerInRelative || localValue.type === "ABSOLUTE");
254
275
  content = /* @__PURE__ */ jsxs(Container, { className: containerClass, children: [
255
- /* @__PURE__ */ jsx(RangePicker, { showNowButton, value: normalizeRange(localValue), onChange: handleRangeChange, mode, disabledDate, onSwitchMode: handleSwitchMode, dateOnly: !showTime, canSwitchMode: canSwitchToTimePicker, texts: allTexts, forceAdjacentMonths, intl }),
276
+ /* @__PURE__ */ jsx(RangePicker, { showNowButton, timeZone, value: normalizeLocalRange(localValue, timeZone), onChange: handleRangeChange, mode, disabledDate, onSwitchMode: handleSwitchMode, dateOnly: !showTime, canSwitchMode: canSwitchToTimePicker, texts: allTexts, forceAdjacentMonths, intl }),
256
277
  addons.length > 0 && /* @__PURE__ */ jsx(Separator, {}),
257
278
  addons.map((addon, index) => /* @__PURE__ */ jsx(Addon, { last: addons.length === index + 1, className: "addon-wrapper", children: addon.content }, addon.key)),
258
- /* @__PURE__ */ jsx(Footer, { canApply: isValid2 || isLifetime(localValue), onApply: handleApply, dateOnly: !showTime, mode, canSwitchMode: isValid2, message: !validator.valid ? validator.message : null, onSwitchMode: handleSwitchMode, texts: allTexts, value: fullValue, showTime, valueFormatOptions, ...footerProps })
279
+ /* @__PURE__ */ jsx(Footer, { canApply: isValid2 || isLifetime(localValue), onApply: handleApply, dateOnly: !showTime, mode, canSwitchMode: isValid2, message: !validator.valid ? validator.message : null, onSwitchMode: handleSwitchMode, texts: allTexts, value: fullValue, showTime, valueFormatOptions, timeZone, ...footerProps })
259
280
  ] });
260
281
  }
261
282
  return /* @__PURE__ */ jsx(DateRangePickerWrapper, { "data-testid": "date-range-picker-container", children: content });
@@ -1,5 +1,5 @@
1
1
  import { default as React } from 'react';
2
2
  import { Props } from './CustomRangeForm.types';
3
3
  export declare const setOffsetType: (a: any, obj: any) => any;
4
- declare const CustomRangeForm: ({ ranges, rangeUnits, currentRange, currentGroup, handleDurationValueChange, handleOffsetValueChange, handleModeChange, handleChange, texts, handleTimestampChange, timestamp, relativeModes, }: Props) => React.JSX.Element;
4
+ declare const CustomRangeForm: ({ ranges, rangeUnits, currentRange, currentGroup, handleDurationValueChange, handleOffsetValueChange, handleModeChange, handleChange, texts, handleTimestampChange, timestamp, relativeModes, timeZone, }: Props) => React.JSX.Element;
5
5
  export default CustomRangeForm;
@@ -1,6 +1,6 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
- import lensPath from "ramda/src/lensPath";
3
- import set from "ramda/src/set";
2
+ import lensPath from "ramda/src/lensPath.js";
3
+ import set from "ramda/src/set.js";
4
4
  import { RANGES_MODE } from "../../../constants.js";
5
5
  import { CustomForm, RangeFormColumn } from "../../RelativeRangePicker.styles.js";
6
6
  import ModeDrop from "../ModeDropdown/ModeDropdown.js";
@@ -20,7 +20,8 @@ const CustomRangeForm = ({
20
20
  texts,
21
21
  handleTimestampChange,
22
22
  timestamp,
23
- relativeModes
23
+ relativeModes,
24
+ timeZone
24
25
  }) => {
25
26
  const isSinceModeEnable = currentGroup === RANGES_MODE.SINCE;
26
27
  const renderOffsetColumn = () => {
@@ -30,7 +31,7 @@ const CustomRangeForm = ({
30
31
  return /* @__PURE__ */ jsx(RangeFormColumn, { children: /* @__PURE__ */ jsx(DurationField, { currentRange, currentGroup, handleChange, handleDurationValueChange, texts, rangeUnits }) });
31
32
  };
32
33
  const renderTimestampRange = () => {
33
- return /* @__PURE__ */ jsx(RangeFormColumn, { children: /* @__PURE__ */ jsx(TimestampRange, { handleModeChange, currentRange, handleChange, onTimestampChange: handleTimestampChange, timestamp, texts }) });
34
+ return /* @__PURE__ */ jsx(RangeFormColumn, { children: /* @__PURE__ */ jsx(TimestampRange, { handleModeChange, currentRange, handleChange, onTimestampChange: handleTimestampChange, timestamp, texts, timeZone }) });
34
35
  };
35
36
  return /* @__PURE__ */ jsxs(CustomForm, { children: [
36
37
  /* @__PURE__ */ jsx(RangeFormColumn, { children: /* @__PURE__ */ jsx(ModeDrop, { ranges, currentGroup, currentRange, onModeChange: handleModeChange, texts, modes: relativeModes }) }),
@@ -13,6 +13,8 @@ export type Props = {
13
13
  texts: Texts;
14
14
  relativeModes: RelativeMode[];
15
15
  rangeUnits: DateRangePickerProps['rangeUnits'];
16
+ /** Resolved `timeZone` prop, or `undefined` when it was not set. See `dateUtils/getNow`. */
17
+ timeZone?: string;
16
18
  };
17
19
  export type FieldProps = {
18
20
  currentRange: RelativeDateRange;
@@ -1,6 +1,6 @@
1
1
  import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
- import lensPath from "ramda/src/lensPath";
3
- import set from "ramda/src/set";
2
+ import lensPath from "ramda/src/lensPath.js";
3
+ import set from "ramda/src/set.js";
4
4
  import { useEffect } from "react";
5
5
  import InputNumber from "@synerise/ds-input-number";
6
6
  import Select from "@synerise/ds-select";
@@ -1,8 +1,8 @@
1
1
  import { jsx, Fragment } from "react/jsx-runtime";
2
2
  import { ALL_TIME } from "../../../constants.js";
3
3
  import { findMatchingPreset } from "../../utils/findMatchingPreset.utils.js";
4
- import "ramda/src/lensPath";
5
- import "ramda/src/set";
4
+ import "ramda/src/lensPath.js";
5
+ import "ramda/src/set.js";
6
6
  import "../../utils/setFuture.utils.js";
7
7
  import { Range } from "../../RelativeRangePicker.styles.js";
8
8
  import { isLifetime } from "../RangeDropdown/RangeDropdown.js";
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import isEqual from "lodash.isequal";
3
- import find from "ramda/src/find";
3
+ import find from "ramda/src/find.js";
4
4
  import { useState, useRef, useCallback } from "react";
5
5
  import { theme } from "@synerise/ds-core";
6
6
  import Icon, { CheckS, AngleDownS } from "@synerise/ds-icon";
@@ -9,8 +9,8 @@ import { useOnClickOutside } from "@synerise/ds-utils";
9
9
  import { ALL_TIME } from "../../../constants.js";
10
10
  import { OverlayWrapper, DropMenu, DropMenuItem, DropdownContainer, Range } from "../../RelativeRangePicker.styles.js";
11
11
  import { findRangeByKey } from "../../utils/findRangeByKey.utils.js";
12
- import "ramda/src/lensPath";
13
- import "ramda/src/set";
12
+ import "ramda/src/lensPath.js";
13
+ import "ramda/src/set.js";
14
14
  import "../../utils/setFuture.utils.js";
15
15
  const MAX_ITEMS_COUNT = 7;
16
16
  const ITEMS_HEIGHT = 32;
@@ -3,6 +3,7 @@ import React from "react";
3
3
  import { useIntl } from "react-intl";
4
4
  import { getDefaultTexts, DatePicker } from "@synerise/ds-date-picker";
5
5
  import { DURATION_MODIFIERS, CUSTOM_RANGE_KEY } from "../../../constants.js";
6
+ import { getNow } from "../../../dateUtils/getNow.js";
6
7
  import { DEFAULT_RANGE } from "../../../utils.js";
7
8
  import { RangeFormColumn, DatePickerWrapper } from "../../RelativeRangePicker.styles.js";
8
9
  import TimestampDuration from "./TimestampDuration/TimestampDuration.js";
@@ -11,27 +12,29 @@ const TimestampRange = ({
11
12
  handleChange,
12
13
  texts,
13
14
  onTimestampChange,
14
- getValueOnReset = () => ({
15
+ getValueOnReset,
16
+ timestamp,
17
+ timeZone
18
+ }) => {
19
+ const [durationModifier, setDurationModifier] = React.useState(currentRange?.future ? DURATION_MODIFIERS.NEXT : DURATION_MODIFIERS.LAST);
20
+ const [durationValue, setDurationValue] = React.useState(currentRange?.duration?.value);
21
+ const [durationUnit, setDurationUnit] = React.useState(currentRange?.duration?.type);
22
+ const [error, setError] = React.useState(!timestamp);
23
+ const intl = useIntl();
24
+ const allTexts = getDefaultTexts(intl, texts);
25
+ const getResetValue = React.useCallback(() => getValueOnReset?.() ?? {
15
26
  ...DEFAULT_RANGE,
16
27
  type: "RELATIVE",
17
28
  offset: {
18
29
  type: "SINCE",
19
- value: /* @__PURE__ */ new Date()
30
+ value: getNow(timeZone)
20
31
  },
21
32
  duration: {
22
33
  type: "DAYS",
23
34
  value: 30
24
35
  },
25
36
  translationKey: CUSTOM_RANGE_KEY
26
- }),
27
- timestamp
28
- }) => {
29
- const [durationModifier, setDurationModifier] = React.useState(currentRange?.future ? DURATION_MODIFIERS.NEXT : DURATION_MODIFIERS.LAST);
30
- const [durationValue, setDurationValue] = React.useState(currentRange?.duration?.value);
31
- const [durationUnit, setDurationUnit] = React.useState(currentRange?.duration?.type);
32
- const [error, setError] = React.useState(!timestamp);
33
- const intl = useIntl();
34
- const allTexts = getDefaultTexts(intl, texts);
37
+ }, [getValueOnReset, timeZone]);
35
38
  React.useEffect(() => {
36
39
  setError(!timestamp);
37
40
  }, [timestamp]);
@@ -67,7 +70,7 @@ const TimestampRange = ({
67
70
  }, onApply: (date) => {
68
71
  onTimestampChange && onTimestampChange(date);
69
72
  }, onClear: () => {
70
- onTimestampChange && onTimestampChange(getValueOnReset());
73
+ onTimestampChange && onTimestampChange(getResetValue());
71
74
  }, dropdownProps: {
72
75
  getPopupContainer: (node) => node.parentElement !== null ? node.parentElement : document.body
73
76
  }, texts: {
@@ -8,6 +8,8 @@ export type TimestampRangeProps = {
8
8
  timestamp?: Date | undefined;
9
9
  texts: Texts;
10
10
  getValueOnReset?: (value?: Date) => RelativeDateRange | Date | undefined;
11
+ /** Resolved `timeZone` prop, or `undefined` when it was not set. See `dateUtils/getNow`. */
12
+ timeZone?: string;
11
13
  };
12
14
  /**
13
15
  * @deprecated
@@ -2,9 +2,10 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
3
  import { injectIntl } from "react-intl";
4
4
  import { CUSTOM_RANGE_KEY, RANGES_MODE, RELATIVE_UNITS, RELATIVE_PRESETS, ABSOLUTE_PRESETS, RELATIVE_SECTION_BUTTON_KEYS_ORDER, RELATIVE } from "../constants.js";
5
+ import { getNow } from "../dateUtils/getNow.js";
5
6
  import getRelativePresetForRange from "../dateUtils/getRelativePresetForRange.js";
6
7
  import { isAfter } from "date-fns";
7
- import { DEFAULT_RANGE, normalizeRange } from "../utils.js";
8
+ import { DEFAULT_RANGE, normalizeRange, normalizeLocalRange } from "../utils.js";
8
9
  import CustomRangeForm from "./Elements/CustomRangeForm/CustomRangeForm.js";
9
10
  import RangeButtons from "./Elements/RangeButtons/RangeButtons.js";
10
11
  import RangeDropdown from "./Elements/RangeDropdown/RangeDropdown.js";
@@ -27,7 +28,7 @@ const _RelativeRangePicker = class _RelativeRangePicker extends React.PureCompon
27
28
  this.setState({
28
29
  currentGroup: mode,
29
30
  lastCustomRange: void 0,
30
- sinceTimestamp: /* @__PURE__ */ new Date()
31
+ sinceTimestamp: getNow(this.props.timeZone)
31
32
  });
32
33
  const {
33
34
  onChange
@@ -77,15 +78,20 @@ const _RelativeRangePicker = class _RelativeRangePicker extends React.PureCompon
77
78
  currentGroup
78
79
  } = this.state;
79
80
  const {
80
- onChange
81
+ onChange,
82
+ timeZone
81
83
  } = this.props;
82
84
  const isSince = currentGroup === RANGES_MODE.SINCE;
83
- const isFuture = isSince ? value.future : value.timestamp && isAfter(value.timestamp, /* @__PURE__ */ new Date());
85
+ const isFuture = isSince ? value.future : value.timestamp && isAfter(value.timestamp, getNow(timeZone));
84
86
  const changes = {
85
87
  ...setFuture(currentGroup === RANGES_MODE.FUTURE || isFuture, value),
86
88
  type: "RELATIVE"
87
89
  };
88
- const resultRange = normalizeRange(updatePresetKey(changes));
90
+ const resultRange = normalizeLocalRange(
91
+ // biome-ignore lint/suspicious/noExplicitAny: upstream type is not expressible here
92
+ updatePresetKey(changes),
93
+ timeZone
94
+ );
89
95
  if (resultRange?.translationKey === CUSTOM_RANGE_KEY) {
90
96
  this.setState({
91
97
  lastCustomRange: resultRange
@@ -146,15 +152,16 @@ const _RelativeRangePicker = class _RelativeRangePicker extends React.PureCompon
146
152
  ranges,
147
153
  texts,
148
154
  relativeModes,
149
- rangeUnits
155
+ rangeUnits,
156
+ timeZone
150
157
  } = this.props;
151
- return /* @__PURE__ */ jsx(CustomRangeForm, { handleModeChange: this.onModeChange, ranges, currentRange, currentGroup, handleChange: this.onChange, handleDurationValueChange: this.onDurationValueChange, handleOffsetValueChange: this.onOffsetValueChange, handleTimestampChange: this.onTimestampChange, timestamp: sinceTimestamp, relativeModes: relativeModes || [], texts, rangeUnits });
158
+ return /* @__PURE__ */ jsx(CustomRangeForm, { handleModeChange: this.onModeChange, ranges, currentRange, currentGroup, handleChange: this.onChange, handleDurationValueChange: this.onDurationValueChange, handleOffsetValueChange: this.onOffsetValueChange, handleTimestampChange: this.onTimestampChange, timestamp: sinceTimestamp, relativeModes: relativeModes || [], texts, rangeUnits, timeZone });
152
159
  };
153
160
  this.state = {
154
161
  currentGroup: getCurrentGroupFromProps(props),
155
162
  future: props.future || false,
156
163
  past: props.past || true,
157
- sinceTimestamp: /* @__PURE__ */ new Date()
164
+ sinceTimestamp: getNow(props.timeZone)
158
165
  };
159
166
  }
160
167
  static getDerivedStateFromProps(nextProps, prevState) {
@@ -9,6 +9,8 @@ export type RelativeRangePickerProps = {
9
9
  past?: boolean;
10
10
  since?: boolean;
11
11
  intl: IntlShape;
12
+ /** Resolved `timeZone` prop, or `undefined` when it was not set. See `dateUtils/getNow`. */
13
+ timeZone?: string;
12
14
  texts: Texts;
13
15
  relativeModes?: RelativeMode[];
14
16
  rangeUnits: DateRangePickerProps['rangeUnits'];
@@ -1,5 +1,5 @@
1
- import lensPath from "ramda/src/lensPath";
2
- import set from "ramda/src/set";
1
+ import lensPath from "ramda/src/lensPath.js";
2
+ import set from "ramda/src/set.js";
3
3
  const setDurationValue = (value, currentRange) => {
4
4
  const updatedValue = value === "" ? null : value;
5
5
  return set(lensPath(["duration", "value"]))(typeof updatedValue === "number" && updatedValue >= 1 ? Math.round(updatedValue) : 1, currentRange);
@@ -1,5 +1,5 @@
1
- import lensPath from "ramda/src/lensPath";
2
- import set from "ramda/src/set";
1
+ import lensPath from "ramda/src/lensPath.js";
2
+ import set from "ramda/src/set.js";
3
3
  const setFuture = set(lensPath(["future"]));
4
4
  export {
5
5
  setFuture
@@ -1,5 +1,5 @@
1
- import lensPath from "ramda/src/lensPath";
2
- import set from "ramda/src/set";
1
+ import lensPath from "ramda/src/lensPath.js";
2
+ import set from "ramda/src/set.js";
3
3
  const setOffsetValue = (value, currentRange) => {
4
4
  const updatedValue = value === "" ? null : value;
5
5
  return set(lensPath(["offset", "value"]))(typeof updatedValue === "number" && updatedValue >= 0 ? Math.round(updatedValue) : 0, currentRange);
@@ -4,6 +4,7 @@ import { default as startOf } from './dateUtils/startOf';
4
4
  export type RelativeUnits = 'SECONDS' | 'MINUTES' | 'HOURS' | 'DAYS' | 'WEEKS' | 'MONTHS' | 'YEARS' | 'SINCE' | keyof typeof startOf | keyof typeof endOf;
5
5
  export type RangeKey = 'TODAY' | 'YESTERDAY' | 'TOMORROW' | 'LAST_WEEK' | 'THIS_WEEK' | 'NEXT_WEEK' | 'LAST_7_DAYS' | 'NEXT_7_DAYS' | 'LAST_MONTH' | 'THIS_MONTH' | 'NEXT_MONTH' | 'LAST_3_MONTHS' | 'NEXT_3_MONTHS' | 'LAST_6_MONTHS' | 'NEXT_6_MONTHS' | 'LAST_YEAR' | 'NEXT_YEAR' | 'ALL_TIME';
6
6
  export type NullableDateLimit = null | string | Date;
7
+ export type DateLimit = string | Date;
7
8
  export interface DateFilter {
8
9
  key?: string;
9
10
  type: 'ABSOLUTE' | 'RELATIVE' | 'SINCE';
@@ -0,0 +1,19 @@
1
+ import { DateToFormatOptions } from '@synerise/ds-core';
2
+ /**
3
+ * Inside the picker a `Date` holds the wall clock of the provider timezone in its
4
+ * local fields — `toIsoString` is the encoder of that convention, `getLocalDateInTimeZone`
5
+ * the decoder. To display one, it has to be re-anchored to a real instant first.
6
+ *
7
+ * Without a provider timezone the date is already in the timezone it will be rendered in,
8
+ * so it is passed through: `toIsoString` falls back to `'UTC'` for a missing timezone and
9
+ * would stamp `+00:00` onto local fields, shifting the value by the browser offset.
10
+ */
11
+ export declare const getDateToDisplay: (date: Date, timeZone?: string) => Date;
12
+ /**
13
+ * Counterpart of `getDateToDisplay`: `formatValue` only projects an instant into the
14
+ * provider timezone when `applyTimeZoneOffset` is set, and it defaults to `false` in
15
+ * `DataFormatConfig`. The re-anchoring above is only correct together with that projection,
16
+ * so the flag is forced here rather than inherited from the consumer's config — otherwise
17
+ * the rendered value drifts by the browser-to-provider timezone delta.
18
+ */
19
+ export declare const getFormatOptionsToDisplay: <T extends DateToFormatOptions>(options: T, timeZone?: string) => T;
@@ -0,0 +1,10 @@
1
+ import { toIsoString } from "@synerise/ds-core";
2
+ const getDateToDisplay = (date, timeZone) => timeZone ? new Date(toIsoString(date, timeZone)) : date;
3
+ const getFormatOptionsToDisplay = (options, timeZone) => timeZone ? {
4
+ ...options,
5
+ applyTimeZoneOffset: true
6
+ } : options;
7
+ export {
8
+ getDateToDisplay,
9
+ getFormatOptionsToDisplay
10
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * "Now" on the provider's clock, as a wall-clock date — the convention the panel keeps its
3
+ * dates in (see `dateUtils/displayDate`). Read per call rather than captured once per module,
4
+ * so relative ranges, the circled day and the SINCE anchor keep following the clock past
5
+ * midnight, and resolve on the provider's day rather than the browser's.
6
+ *
7
+ * Takes the zone the `timeZone` prop resolved to rather than reading `intl` itself: without
8
+ * that prop there is no zone, and this has to stay the browser's `new Date()` that every
9
+ * current consumer already gets.
10
+ */
11
+ export declare const getNow: (timeZone?: string) => Date;
@@ -0,0 +1,5 @@
1
+ import { currentTimeInTimezone } from "@synerise/ds-core";
2
+ const getNow = (timeZone) => timeZone ? currentTimeInTimezone(timeZone) : /* @__PURE__ */ new Date();
3
+ export {
4
+ getNow
5
+ };
@@ -1,4 +1,4 @@
1
1
  import { DateFilter, RelativeDateRange } from '../date.types';
2
2
  export type Relative = 'SECONDS' | 'MINUTES' | 'HOURS' | 'DAYS' | 'WEEKS' | 'MONTHS' | 'YEARS';
3
- declare const relativeToAbsolute: (range: RelativeDateRange) => DateFilter;
3
+ declare const relativeToAbsolute: (range: RelativeDateRange, timeZone?: string) => DateFilter;
4
4
  export default relativeToAbsolute;
@@ -1,15 +1,16 @@
1
1
  import { min, max } from "date-fns";
2
+ import { currentTimeInTimezone } from "@synerise/ds-core";
2
3
  import ADD from "./add.js";
3
4
  import endOf from "./endOf.js";
4
5
  import startOf from "./startOf.js";
5
6
  import toDateValue from "./toDateValue.js";
6
- const relativeToAbsolute = (range) => {
7
+ const relativeToAbsolute = (range, timeZone) => {
7
8
  const {
8
9
  future,
9
10
  offset,
10
11
  duration
11
12
  } = range;
12
- const now = /* @__PURE__ */ new Date();
13
+ const now = timeZone ? currentTimeInTimezone(timeZone) : /* @__PURE__ */ new Date();
13
14
  let left;
14
15
  let right;
15
16
  if (future) {
package/dist/utils.d.ts CHANGED
@@ -15,6 +15,14 @@ import { default as START_OF } from './dateUtils/startOf';
15
15
  export { toIsoString } from '@synerise/ds-core';
16
16
  export { END_OF, START_OF };
17
17
  export declare function toIsoStringWithoutZone(date: Date): string;
18
- export declare const normalizeRange: (range: DateRange) => DateRange;
18
+ export declare const normalizeRange: (range: DateRange, timeZone?: string) => DateRange;
19
+ /**
20
+ * `normalizeRange` for values that are already in the panel's wall-clock convention.
21
+ *
22
+ * The provider timezone is then only useful for resolving a relative range against "now" —
23
+ * handing it to the absolute branch would re-decode bounds that are already wall clock (a
24
+ * `Date` there is read as a real instant), shifting them by the browser-to-provider delta.
25
+ */
26
+ export declare const normalizeLocalRange: (range: DateRange, timeZone?: string) => DateRange;
19
27
  export declare const getDefaultTexts: (intl: IntlShape, disableDefault?: boolean, texts?: Partial<Texts>) => Texts;
20
28
  export declare const DEFAULT_RANGE: DateRange;
package/dist/utils.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { min, max } from "date-fns";
2
2
  import omit from "lodash.omit";
3
+ import { currentTimeInTimezone, getValueAsLocalDate } from "@synerise/ds-core";
4
+ import { toIsoString } from "@synerise/ds-core";
3
5
  import { ABSOLUTE, RELATIVE, CUSTOM_RANGE_KEY } from "./constants.js";
4
6
  import ADD from "./dateUtils/add.js";
5
7
  import endOf from "./dateUtils/endOf.js";
6
8
  import startOf from "./dateUtils/startOf.js";
7
- import { toIsoString } from "@synerise/ds-core";
8
9
  const rmvTZOffset = (dateString) => {
9
10
  const date = dateString.toString();
10
11
  const finalDate = date.replace(/[+-]\d\d:\d\d$/, "");
@@ -14,7 +15,8 @@ const pad = (num) => (num < 10 ? "0" : "") + num;
14
15
  function toIsoStringWithoutZone(date) {
15
16
  return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
16
17
  }
17
- const normalizeRange = (range) => {
18
+ const decodeLimit = (limit, timeZone) => timeZone ? getValueAsLocalDate(limit, timeZone) : new Date(rmvTZOffset(limit));
19
+ const normalizeRange = (range, timeZone) => {
18
20
  if (!range || !range.type) {
19
21
  return {
20
22
  type: ABSOLUTE,
@@ -27,7 +29,7 @@ const normalizeRange = (range) => {
27
29
  offset,
28
30
  duration
29
31
  } = range;
30
- const now = /* @__PURE__ */ new Date();
32
+ const now = timeZone ? currentTimeInTimezone(timeZone) : /* @__PURE__ */ new Date();
31
33
  let left;
32
34
  let right;
33
35
  if (offset?.type === "SINCE") {
@@ -69,14 +71,18 @@ const normalizeRange = (range) => {
69
71
  const dropNonAbsolute = (dateRange) => omit(dateRange, ["offset", "duration", "future"]);
70
72
  const absoluteRange = {
71
73
  ...dropNonAbsolute(range),
72
- from: range.from ? new Date(rmvTZOffset(range?.from)) : void 0,
73
- to: range.to ? new Date(rmvTZOffset(range?.to)) : void 0
74
+ // Absent a timezone this is the legacy decode, byte for byte — see `rmvTZOffset`. A
75
+ // timezone is only ever passed down from a `timeZone` prop, so a consumer that does not
76
+ // set one cannot observe the new decode.
77
+ from: range.from ? decodeLimit(range.from, timeZone) : void 0,
78
+ to: range.to ? decodeLimit(range.to, timeZone) : void 0
74
79
  };
75
80
  if (!keys.includes("from") && !keys.includes("to")) {
76
81
  absoluteRange.translationKey = "allTime";
77
82
  }
78
83
  return absoluteRange;
79
84
  };
85
+ const normalizeLocalRange = (range, timeZone) => normalizeRange(range, range?.type === RELATIVE ? timeZone : void 0);
80
86
  const getIntlMessage = (textMessageId, intl, areDefaultTextsDisabled, defaultMessage) => areDefaultTextsDisabled ? "" : intl.formatMessage({
81
87
  id: textMessageId,
82
88
  defaultMessage
@@ -191,6 +197,7 @@ export {
191
197
  endOf as END_OF,
192
198
  startOf as START_OF,
193
199
  getDefaultTexts,
200
+ normalizeLocalRange,
194
201
  normalizeRange,
195
202
  toIsoString,
196
203
  toIsoStringWithoutZone