react-timezone-select 3.0.4-beta.1 → 3.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.
package/README.md CHANGED
@@ -130,6 +130,7 @@ The above example will generate two additional choices in the select options, on
130
130
  - `labelStyle` - `'original' | 'altName' | 'abbrev' | 'offsetHidden'`
131
131
  - `displayValue` - `'GMT' | 'UTC'`
132
132
  - `timezones` - `Record<string,string>`
133
+ - `currentDatetime` - `Date | string` - Set datetime used to calculate timezone values (alternative to current datetime)
133
134
  ```
134
135
  timezones={{
135
136
  ...allTimezones,
package/dist/index.d.ts CHANGED
@@ -1,34 +1,36 @@
1
+ import * as react_jsx_runtime_js from 'react/jsx-runtime.js';
1
2
  import { Props as Props$1 } from 'react-select';
2
3
 
3
- declare type ICustomTimezone = {
4
+ type ICustomTimezone = {
4
5
  [key: string]: string;
5
6
  };
6
- declare type ILabelStyle = 'original' | 'altName' | 'abbrev' | 'offsetHidden';
7
- declare type IDisplayValue = 'GMT' | 'UTC';
8
- declare type ITimezoneOption = {
7
+ type ILabelStyle = 'original' | 'altName' | 'abbrev' | 'offsetHidden';
8
+ type IDisplayValue = 'GMT' | 'UTC';
9
+ type ITimezoneOption = {
9
10
  value: string;
10
11
  label: string;
11
12
  abbrev?: string;
12
13
  altName?: string;
13
14
  offset?: number;
14
15
  };
15
- declare type ITimezone = ITimezoneOption | string;
16
- declare type TimezoneSelectOptions = {
16
+ type ITimezone = ITimezoneOption | string;
17
+ type TimezoneSelectOptions = {
17
18
  labelStyle?: ILabelStyle;
18
19
  displayValue?: IDisplayValue;
19
20
  timezones?: ICustomTimezone;
21
+ currentDatetime?: Date | string;
20
22
  };
21
- declare type Props = Omit<Props$1<ITimezone, false>, 'onChange'> & TimezoneSelectOptions & {
23
+ type Props = Omit<Props$1<ITimezone, false>, 'onChange'> & TimezoneSelectOptions & {
22
24
  value: ITimezone;
23
25
  onChange?: (timezone: ITimezone) => void;
24
26
  };
25
27
 
26
28
  declare const allTimezones: ICustomTimezone;
27
29
 
28
- declare function useTimezoneSelect({ timezones, labelStyle, displayValue, }: TimezoneSelectOptions): {
30
+ declare function useTimezoneSelect({ timezones, labelStyle, displayValue, currentDatetime, }: TimezoneSelectOptions): {
29
31
  parseTimezone: (zone: ITimezone) => ITimezoneOption;
30
32
  options: ITimezoneOption[];
31
33
  };
32
- declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, displayValue, timezones, ...props }: Props) => JSX.Element;
34
+ declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, displayValue, timezones, currentDatetime, ...props }: Props) => react_jsx_runtime_js.JSX.Element;
33
35
 
34
36
  export { ILabelStyle, ITimezone, ITimezoneOption, Props, TimezoneSelectOptions, allTimezones, TimezoneSelect as default, useTimezoneSelect };
package/dist/index.js CHANGED
@@ -122,13 +122,14 @@ import { jsx } from "react/jsx-runtime";
122
122
  function useTimezoneSelect({
123
123
  timezones = timezone_list_default,
124
124
  labelStyle = "original",
125
- displayValue = "GMT"
125
+ displayValue = "GMT",
126
+ currentDatetime
126
127
  }) {
127
128
  const options = useMemo(() => {
128
129
  return Object.entries(timezones).map((zone) => {
129
130
  var _a, _b, _c, _d;
130
131
  try {
131
- const now = spacetime.now(zone[0]);
132
+ const now = (currentDatetime ? spacetime(currentDatetime) : spacetime.now()).goto(zone[0]);
132
133
  const isDstString = now.isDST() ? "daylight" : "standard";
133
134
  const tz = now.timezone();
134
135
  const tzStrings = soft(zone[0]);
@@ -169,9 +170,9 @@ function useTimezoneSelect({
169
170
  const findFuzzyTz = (zone) => {
170
171
  let currentTime;
171
172
  try {
172
- currentTime = spacetime.now(zone);
173
+ currentTime = (currentDatetime ? spacetime(currentDatetime) : spacetime.now()).goto(zone);
173
174
  } catch (err) {
174
- currentTime = spacetime.now("GMT");
175
+ currentTime = (currentDatetime ? spacetime(currentDatetime) : spacetime.now()).goto("GMT");
175
176
  }
176
177
  return options.filter(
177
178
  (tz) => tz.offset === currentTime.timezone().current.offset
@@ -216,19 +217,22 @@ var TimezoneSelect = (_a) => {
216
217
  onChange,
217
218
  labelStyle,
218
219
  displayValue,
219
- timezones
220
+ timezones,
221
+ currentDatetime
220
222
  } = _b, props = __objRest(_b, [
221
223
  "value",
222
224
  "onBlur",
223
225
  "onChange",
224
226
  "labelStyle",
225
227
  "displayValue",
226
- "timezones"
228
+ "timezones",
229
+ "currentDatetime"
227
230
  ]);
228
231
  const { options, parseTimezone } = useTimezoneSelect({
229
232
  timezones,
230
233
  labelStyle,
231
- displayValue
234
+ displayValue,
235
+ currentDatetime
232
236
  });
233
237
  const handleChange = (tz) => {
234
238
  onChange && onChange(tz);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-timezone-select",
3
- "version": "3.0.4-beta.1",
3
+ "version": "3.2.0",
4
4
  "description": "Usable, dynamic React Timezone Select",
5
5
  "scripts": {
6
6
  "dev": "concurrently \"tsup src/index.tsx --format esm --watch\" \"cd example && pnpm dev\"",