|
43 | 43 | * @property {string} timezone - Time zone in IANA database format 'Europe/Stockholm'
|
44 | 44 | */
|
45 | 45 |
|
46 |
| - /* |
| 46 | + /** |
47 | 47 | * Converts a date/time from a specific timezone to a normal date object using the system local time
|
48 | 48 | *
|
49 | 49 | * Shortcut for minitz.fromTZ(minitz.tp(...));
|
50 | 50 | *
|
51 |
| - * @public |
| 51 | + * @constructor |
52 | 52 | *
|
53 | 53 | * @param {Number} year - 1970--
|
54 | 54 | * @param {Number} month - 1-12
|
|
59 | 59 | * @param {string} timezone - Time zone in IANA database format 'Europe/Stockholm'
|
60 | 60 | * @param {boolean} [throwOnInvalidTime] - Default is to return the adjusted time if the call happens during a Daylight-Saving-Time switch.
|
61 | 61 | * E.g. Value "01:01:01" is returned if input time is 00:01:01 while one hour got actually
|
62 |
| - * skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw instead. |
| 62 | + * skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw an exception instead. |
63 | 63 | * @returns {date} - Normal date object with correct UTC and system local time
|
64 | 64 | *
|
65 |
| - */ |
| 65 | + */ |
66 | 66 | function minitz(year, month, day, hour, minute, second, timezone, throwOnInvalidTime) {
|
67 | 67 | return minitz.fromTZ(minitz.tp(year, month, day, hour, minute, second, timezone), throwOnInvalidTime);
|
68 | 68 | }
|
69 | 69 |
|
70 | 70 | /**
|
71 | 71 | * Converts a date/time from a specific timezone to a normal date object using the system local time
|
72 |
| - * |
| 72 | + * |
73 | 73 | * @public
|
74 |
| - * |
| 74 | + * @static |
| 75 | + * |
75 | 76 | * @param {string} localTimeString - ISO8601 formatted local time string, non UTC
|
76 | 77 | * @param {string} timezone - Time zone in IANA database format 'Europe/Stockholm'
|
77 | 78 | * @param {boolean} [throwOnInvalidTime] - Default is to return the adjusted time if the call happens during a Daylight-Saving-Time switch.
|
78 | 79 | * E.g. Value "01:01:01" is returned if input time is 00:01:01 while one hour got actually
|
79 |
| - * skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw instead. |
80 |
| - * @returns {date} - Normal date object |
| 80 | + * skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw an exception instead. |
| 81 | + * @return {date} - Normal date object |
| 82 | + * |
81 | 83 | */
|
82 |
| - minitz.fromTZISO = function(localTimeString, timezone, throwOnInvalidTime) { |
| 84 | + minitz.fromTZISO = (localTimeString, timezone, throwOnInvalidTime) => { |
83 | 85 | return minitz.fromTZ(parseISOLocal(localTimeString, timezone), throwOnInvalidTime);
|
84 | 86 | };
|
85 | 87 |
|
86 | 88 | /**
|
87 | 89 | * Converts a date/time from a specific timezone to a normal date object using the system local time
|
88 | 90 | *
|
89 | 91 | * @public
|
| 92 | + * @static |
90 | 93 | *
|
91 | 94 | * @param {TimePoint} date - Object with specified timezone
|
92 | 95 | * @param {boolean} [throwOnInvalidTime] - Default is to return the adjusted time if the call happens during a Daylight-Saving-Time switch.
|
93 | 96 | * E.g. Value "01:01:01" is returned if input time is 00:01:01 while one hour got actually
|
94 |
| - * skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw instead. |
| 97 | + * skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw an exception instead. |
95 | 98 | * @returns {date} - Normal date object
|
96 | 99 | */
|
97 | 100 | minitz.fromTZ = function(timePoint, throwOnInvalidTime) {
|
|
150 | 153 | * time zone, use vanilla JS. See the example below.
|
151 | 154 | *
|
152 | 155 | * @public
|
| 156 | + * @static |
153 | 157 | *
|
154 | 158 | * @param {date} date - Input date
|
155 | 159 | * @param {string} [tzString] - Timezone string in Europe/Stockholm format
|
|
192 | 196 | };
|
193 | 197 | };
|
194 | 198 |
|
195 |
| - /* |
| 199 | + /** |
196 | 200 | * Convenience function which returns a TimePoint object for later use in fromTZ
|
197 | 201 | *
|
198 | 202 | * @public
|
| 203 | + * @static |
199 | 204 | *
|
200 | 205 | * @param {Number} year - 1970--
|
201 | 206 | * @param {Number} month - 1-12
|
|
220 | 225 | *
|
221 | 226 | * @returns {number} - Offset in ms between UTC and timeZone
|
222 | 227 | */
|
223 |
| - const getTimezoneOffset = (timeZone, date = new Date()) => { |
| 228 | + function getTimezoneOffset(timeZone, date = new Date()) { |
224 | 229 | const tz = date.toLocaleString("en", {timeZone, timeStyle: "long"}).split(" ").slice(-1)[0];
|
225 | 230 | const dateString = date.toString();
|
226 | 231 | return Date.parse(`${dateString} UTC`) - Date.parse(`${dateString} ${tz}`);
|
227 |
| - }; |
| 232 | + } |
228 | 233 |
|
229 | 234 |
|
230 | 235 | /**
|
|
237 | 242 | * with all components, e.g. 2015-11-24T19:40:00
|
238 | 243 | * @returns {TimePoint} - TimePoint instance from parsing the string
|
239 | 244 | */
|
240 |
| - const parseISOLocal = function (dateTimeString, timezone) { |
| 245 | + function parseISOLocal(dateTimeString, timezone) { |
241 | 246 | const dateTimeStringSplit = dateTimeString.split(/\D/);
|
242 | 247 |
|
243 | 248 | // Check for completeness
|
|
277 | 282 | return minitz.tp(year, month, day, hour, minute, second, timezone);
|
278 | 283 | }
|
279 | 284 | }
|
280 |
| - }; |
| 285 | + } |
281 | 286 |
|
282 | 287 | minitz.minitz = minitz;
|
283 | 288 |
|
|
0 commit comments