react-timezone-select 3.1.0 → 3.2.1
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 +15 -16
- package/package.json +2 -3
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
|
@@ -119,16 +119,18 @@ var timezone_list_default = allTimezones;
|
|
|
119
119
|
|
|
120
120
|
// src/index.tsx
|
|
121
121
|
import { jsx } from "react/jsx-runtime";
|
|
122
|
+
"use client";
|
|
122
123
|
function useTimezoneSelect({
|
|
123
124
|
timezones = timezone_list_default,
|
|
124
125
|
labelStyle = "original",
|
|
125
|
-
displayValue = "GMT"
|
|
126
|
+
displayValue = "GMT",
|
|
127
|
+
currentDatetime
|
|
126
128
|
}) {
|
|
127
129
|
const options = useMemo(() => {
|
|
128
130
|
return Object.entries(timezones).map((zone) => {
|
|
129
131
|
var _a, _b, _c, _d;
|
|
130
132
|
try {
|
|
131
|
-
const now = spacetime.now(zone[0]);
|
|
133
|
+
const now = (currentDatetime ? spacetime(currentDatetime) : spacetime.now()).goto(zone[0]);
|
|
132
134
|
const isDstString = now.isDST() ? "daylight" : "standard";
|
|
133
135
|
const tz = now.timezone();
|
|
134
136
|
const tzStrings = soft(zone[0]);
|
|
@@ -169,23 +171,17 @@ function useTimezoneSelect({
|
|
|
169
171
|
const findFuzzyTz = (zone) => {
|
|
170
172
|
let currentTime;
|
|
171
173
|
try {
|
|
172
|
-
currentTime = spacetime.now(zone);
|
|
174
|
+
currentTime = (currentDatetime ? spacetime(currentDatetime) : spacetime.now()).goto(zone);
|
|
173
175
|
} catch (err) {
|
|
174
|
-
currentTime = spacetime.now("GMT");
|
|
176
|
+
currentTime = (currentDatetime ? spacetime(currentDatetime) : spacetime.now()).goto("GMT");
|
|
175
177
|
}
|
|
176
|
-
return options.filter(
|
|
177
|
-
(tz) => tz.offset === currentTime.timezone().current.offset
|
|
178
|
-
).map((tz) => {
|
|
178
|
+
return options.filter((tz) => tz.offset === currentTime.timezone().current.offset).map((tz) => {
|
|
179
179
|
let score = 0;
|
|
180
180
|
if (currentTime.timezones[tz.value.toLowerCase()] && !!currentTime.timezones[tz.value.toLowerCase()].dst === currentTime.timezone().hasDst) {
|
|
181
|
-
if (tz.value.toLowerCase().indexOf(
|
|
182
|
-
currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)
|
|
183
|
-
) !== -1) {
|
|
181
|
+
if (tz.value.toLowerCase().indexOf(currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)) !== -1) {
|
|
184
182
|
score += 8;
|
|
185
183
|
}
|
|
186
|
-
if (tz.label.toLowerCase().indexOf(
|
|
187
|
-
currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)
|
|
188
|
-
) !== -1) {
|
|
184
|
+
if (tz.label.toLowerCase().indexOf(currentTime.tz.substring(currentTime.tz.indexOf("/") + 1)) !== -1) {
|
|
189
185
|
score += 4;
|
|
190
186
|
}
|
|
191
187
|
if (tz.value.toLowerCase().indexOf(currentTime.tz.substring(0, currentTime.tz.indexOf("/")))) {
|
|
@@ -216,19 +212,22 @@ var TimezoneSelect = (_a) => {
|
|
|
216
212
|
onChange,
|
|
217
213
|
labelStyle,
|
|
218
214
|
displayValue,
|
|
219
|
-
timezones
|
|
215
|
+
timezones,
|
|
216
|
+
currentDatetime
|
|
220
217
|
} = _b, props = __objRest(_b, [
|
|
221
218
|
"value",
|
|
222
219
|
"onBlur",
|
|
223
220
|
"onChange",
|
|
224
221
|
"labelStyle",
|
|
225
222
|
"displayValue",
|
|
226
|
-
"timezones"
|
|
223
|
+
"timezones",
|
|
224
|
+
"currentDatetime"
|
|
227
225
|
]);
|
|
228
226
|
const { options, parseTimezone } = useTimezoneSelect({
|
|
229
227
|
timezones,
|
|
230
228
|
labelStyle,
|
|
231
|
-
displayValue
|
|
229
|
+
displayValue,
|
|
230
|
+
currentDatetime
|
|
232
231
|
});
|
|
233
232
|
const handleChange = (tz) => {
|
|
234
233
|
onChange && onChange(tz);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-timezone-select",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
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\"",
|
|
@@ -101,8 +101,7 @@
|
|
|
101
101
|
},
|
|
102
102
|
"prettier": {
|
|
103
103
|
"semi": false,
|
|
104
|
-
"
|
|
105
|
-
"maxLineLength": 100
|
|
104
|
+
"printWidth": 100
|
|
106
105
|
},
|
|
107
106
|
"simple-git-hooks": {
|
|
108
107
|
"pre-commit": "npx lint-staged"
|