chronal 0.0.9 → 0.0.10
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
|
@@ -324,9 +324,28 @@ Parses a date string into a Date object using an optional format pattern.
|
|
|
324
324
|
- `dateString` (string) - The date string to parse
|
|
325
325
|
- `format` (string, optional) - Format pattern (e.g., "YYYY-MM-DD",
|
|
326
326
|
"DD/MM/YYYY")
|
|
327
|
+
- `options` (object, optional) - Parsing options
|
|
328
|
+
- `tz` (string) - IANA timezone (e.g., 'America/Sao_Paulo')
|
|
327
329
|
|
|
328
330
|
**Returns:** Date object
|
|
329
331
|
|
|
332
|
+
**Timezone Behavior:**
|
|
333
|
+
|
|
334
|
+
When parsing date strings, `parseDate` follows these rules:
|
|
335
|
+
|
|
336
|
+
1. **Explicit timezone** (e.g., `Z` or `+03:00`) - Always respected, ignores `config.timezone`
|
|
337
|
+
2. **No timezone** - Uses `config.timezone` or the `tz` option to interpret the string as local time in that timezone
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
// With explicit UTC marker (Z) - always UTC
|
|
341
|
+
parseDate("2026-01-12T02:59:59.999Z"); // UTC time, ignores config
|
|
342
|
+
|
|
343
|
+
// Without timezone - uses config.timezone
|
|
344
|
+
setChronalConfig({ timezone: "America/Sao_Paulo" });
|
|
345
|
+
parseDate("2026-01-12T02:59:59.999"); // Interpreted as São Paulo time
|
|
346
|
+
parseDate("2026-01-12"); // Midnight in São Paulo
|
|
347
|
+
```
|
|
348
|
+
|
|
330
349
|
**Supported Tokens:**
|
|
331
350
|
|
|
332
351
|
- `YYYY` - 4-digit year
|
|
@@ -346,6 +365,9 @@ parseDate("2024-06-15"); // Date object
|
|
|
346
365
|
parseDate("15/06/2024", "DD/MM/YYYY");
|
|
347
366
|
parseDate("2024-06-15 14:30:00", "YYYY-MM-DD HH:mm:ss");
|
|
348
367
|
parseDate("06/15/2024", "MM/DD/YYYY");
|
|
368
|
+
|
|
369
|
+
// With timezone
|
|
370
|
+
parseDate("2024-06-15", { tz: "America/Sao_Paulo" }); // Parse as São Paulo time
|
|
349
371
|
```
|
|
350
372
|
|
|
351
373
|
### Manipulation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-date.d.ts","sourceRoot":"","sources":["../../src/lib/parse-date.ts"],"names":[],"mappings":"AAGA,KAAK,gBAAgB,GAAG;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAClC,IAAI,
|
|
1
|
+
{"version":3,"file":"parse-date.d.ts","sourceRoot":"","sources":["../../src/lib/parse-date.ts"],"names":[],"mappings":"AAGA,KAAK,gBAAgB,GAAG;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAClC,IAAI,CA6FN"}
|
package/esm/lib/parse-date.js
CHANGED
|
@@ -27,8 +27,10 @@ export function parseDate(dateString, options) {
|
|
|
27
27
|
if (isNaN(date.getTime())) {
|
|
28
28
|
throw new Error("Invalid date");
|
|
29
29
|
}
|
|
30
|
-
// If
|
|
31
|
-
|
|
30
|
+
// If the string has explicit timezone (Z or offset like +03:00), respect it
|
|
31
|
+
// Only apply config.timezone for date strings without timezone info
|
|
32
|
+
const hasExplicitTimezone = /Z|[+-]\d{2}:\d{2}$/.test(dateString);
|
|
33
|
+
if (!hasExplicitTimezone && timezone !== "UTC") {
|
|
32
34
|
return parseDateInTimezone(date, timezone);
|
|
33
35
|
}
|
|
34
36
|
return date;
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-date.d.ts","sourceRoot":"","sources":["../../src/lib/parse-date.ts"],"names":[],"mappings":"AAGA,KAAK,gBAAgB,GAAG;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAClC,IAAI,
|
|
1
|
+
{"version":3,"file":"parse-date.d.ts","sourceRoot":"","sources":["../../src/lib/parse-date.ts"],"names":[],"mappings":"AAGA,KAAK,gBAAgB,GAAG;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAClC,IAAI,CA6FN"}
|
package/script/lib/parse-date.js
CHANGED
|
@@ -30,8 +30,10 @@ function parseDate(dateString, options) {
|
|
|
30
30
|
if (isNaN(date.getTime())) {
|
|
31
31
|
throw new Error("Invalid date");
|
|
32
32
|
}
|
|
33
|
-
// If
|
|
34
|
-
|
|
33
|
+
// If the string has explicit timezone (Z or offset like +03:00), respect it
|
|
34
|
+
// Only apply config.timezone for date strings without timezone info
|
|
35
|
+
const hasExplicitTimezone = /Z|[+-]\d{2}:\d{2}$/.test(dateString);
|
|
36
|
+
if (!hasExplicitTimezone && timezone !== "UTC") {
|
|
35
37
|
return parseDateInTimezone(date, timezone);
|
|
36
38
|
}
|
|
37
39
|
return date;
|