react-timezone-select 3.1.0 → 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 +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +11 -7
- package/package.json +1 -1
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
|
@@ -18,6 +18,7 @@ type TimezoneSelectOptions = {
|
|
|
18
18
|
labelStyle?: ILabelStyle;
|
|
19
19
|
displayValue?: IDisplayValue;
|
|
20
20
|
timezones?: ICustomTimezone;
|
|
21
|
+
currentDatetime?: Date | string;
|
|
21
22
|
};
|
|
22
23
|
type Props = Omit<Props$1<ITimezone, false>, 'onChange'> & TimezoneSelectOptions & {
|
|
23
24
|
value: ITimezone;
|
|
@@ -26,10 +27,10 @@ type Props = Omit<Props$1<ITimezone, false>, 'onChange'> & TimezoneSelectOptions
|
|
|
26
27
|
|
|
27
28
|
declare const allTimezones: ICustomTimezone;
|
|
28
29
|
|
|
29
|
-
declare function useTimezoneSelect({ timezones, labelStyle, displayValue, }: TimezoneSelectOptions): {
|
|
30
|
+
declare function useTimezoneSelect({ timezones, labelStyle, displayValue, currentDatetime, }: TimezoneSelectOptions): {
|
|
30
31
|
parseTimezone: (zone: ITimezone) => ITimezoneOption;
|
|
31
32
|
options: ITimezoneOption[];
|
|
32
33
|
};
|
|
33
|
-
declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, displayValue, timezones, ...props }: Props) => react_jsx_runtime_js.JSX.Element;
|
|
34
|
+
declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, displayValue, timezones, currentDatetime, ...props }: Props) => react_jsx_runtime_js.JSX.Element;
|
|
34
35
|
|
|
35
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