Skip to content

Commit 1556efa

Browse files
committed
Update documentation for v4.3.0 IANA timezone string support
- Update type signatures from TimeZone | 'UTC' to TimeZone | string across all API docs (addDays, addMonths, addYears, format, parse, subtract, etc.) - Document IANA timezone string usage for all date manipulation functions - Add v4.3.0 new features section to migration.md - Promote Method 3 (IANA string) as the recommended approach in timezones.md - Fix minor grammar and punctuation issues
1 parent d50f51f commit 1556efa

File tree

14 files changed

+143
-37
lines changed

14 files changed

+143
-37
lines changed

docs/api/addDays.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ addDays(dateObj, days[, timeZone])
1414
|-----------|------|----------|-------------|
1515
| `dateObj` | `Date` | Yes | The base Date object |
1616
| `days` | `number` | Yes | Number of days to add (positive) or subtract (negative) |
17-
| `timeZone` | `TimeZone \| 'UTC'` | No | Timezone for the calculation |
17+
| `timeZone` | `TimeZone \| string` | No | Timezone for the calculation |
1818

1919
### Returns
2020

@@ -56,6 +56,20 @@ const futureUTC = addDays(nyDate, 30, 'UTC');
5656
console.log(futureUTC); // April 9, 2024 05:00 UTC (same time, no DST adjustment)
5757
```
5858

59+
### Using IANA Timezone Name Strings
60+
61+
As of v4.3.0, you can use IANA timezone name strings directly instead of importing TimeZone objects:
62+
63+
```typescript
64+
import { addDays } from 'date-and-time';
65+
66+
const nyDate = new Date('2024-03-10T05:00:00Z'); // March 10, 2024 05:00 UTC
67+
68+
// Using IANA timezone name string (New in v4.3.0)
69+
const futureNY = addDays(nyDate, 30, 'America/New_York');
70+
console.log(futureNY); // April 9, 2024 04:00 UTC (EDT, DST adjusted)
71+
```
72+
5973
## Use Cases
6074

6175
### Work Day Calculations

docs/api/addMonths.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ addMonths(dateObj, months[, timeZone])
1414
|-----------|------|----------|-------------|
1515
| `dateObj` | `Date` | Yes | The base Date object |
1616
| `months` | `number` | Yes | Number of months to add (positive) or subtract (negative) |
17-
| `timeZone` | `TimeZone \| 'UTC'` | No | Timezone for the calculation |
17+
| `timeZone` | `TimeZone \| string` | No | Timezone for the calculation |
1818

1919
### Returns
2020

@@ -56,6 +56,20 @@ const futureUTC = addMonths(nyDate, 6, 'UTC');
5656
console.log(futureUTC); // September 10, 2024 05:00 UTC (same time, no DST adjustment)
5757
```
5858

59+
### Using IANA Timezone Name Strings
60+
61+
As of v4.3.0, you can use IANA timezone name strings directly instead of importing TimeZone objects:
62+
63+
```typescript
64+
import { addMonths } from 'date-and-time';
65+
66+
const nyDate = new Date('2024-03-10T05:00:00Z'); // March 10, 2024 05:00 UTC
67+
68+
// Using IANA timezone name string (New in v4.3.0)
69+
const futureNY = addMonths(nyDate, 6, 'America/New_York');
70+
console.log(futureNY); // September 10, 2024 04:00 UTC (EDT, DST adjusted)
71+
```
72+
5973
## Use Cases
6074

6175
### Payment Due Dates

docs/api/addYears.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ addYears(dateObj, years[, timeZone])
1414
|-----------|------|----------|-------------|
1515
| `dateObj` | `Date` | Yes | The base Date object |
1616
| `years` | `number` | Yes | Number of years to add (positive) or subtract (negative) |
17-
| `timeZone` | `TimeZone \| 'UTC'` | No | Timezone for the calculation |
17+
| `timeZone` | `TimeZone \| string` | No | Timezone for the calculation |
1818

1919
### Returns
2020

@@ -56,6 +56,20 @@ const futureUTC = addYears(nyDate, 1, 'UTC');
5656
console.log(futureUTC); // March 10, 2025 05:00 UTC (same time, no DST adjustment)
5757
```
5858

59+
### Using IANA Timezone Name Strings
60+
61+
As of v4.3.0, you can use IANA timezone name strings directly instead of importing TimeZone objects:
62+
63+
```typescript
64+
import { addYears } from 'date-and-time';
65+
66+
const nyDate = new Date('2024-03-10T05:00:00Z'); // March 10, 2024 05:00 UTC
67+
68+
// Using IANA timezone name string (New in v4.3.0)
69+
const futureNY = addYears(nyDate, 1, 'America/New_York');
70+
console.log(futureNY); // March 10, 2025 04:00 UTC (EST, DST adjusted)
71+
```
72+
5973
## Use Cases
6074

6175
### Age Calculation

docs/api/format.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ format(now, 'hh:mm A [GMT]Z');
6666
| Token | Description | Output Examples |
6767
|-------|-------------|-----------------|
6868
| `HH` | Hour in 24-hour format | 23, 08 |
69-
| `H` | Hour in 24-hour format (no padding) | 23, 8 |
69+
| `H` | Hour in 24-hour format without zero padding | 23, 8 |
7070
| `hh` | Hour in 12-hour format | 11, 08 |
71-
| `h` | Hour in 12-hour format (no padding) | 11, 8 |
71+
| `h` | Hour in 12-hour format without zero padding | 11, 8 |
7272
| `mm` | Minutes | 14, 07 |
7373
| `m` | Minutes without zero padding | 14, 7 |
7474
| `ss` | Seconds | 05, 10 |
@@ -159,7 +159,7 @@ format(date, 'YYYY-MM-DD HH:mm:ss [JST]', { timeZone: Tokyo });
159159
format(date, 'YYYY-MM-DD HH:mm:ss [EST]', { timeZone: NY });
160160
// => 2025-08-23 09:30:45 EST
161161

162-
// Using IANA timezone name string (format only)
162+
// Using IANA timezone name string
163163
format(date, 'YYYY-MM-DD HH:mm:ss [EST]', { timeZone: 'America/New_York' });
164164
// => 2025-08-23 09:30:45 EST
165165

docs/api/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ format(new Date(), 'YYYY年M月D日(ddd) HH:mm', {
7878
```typescript
7979
interface FormatterOptions {
8080
locale?: Locale; // Locale object for localized formatting
81-
timeZone?: TimeZone | 'UTC'; // Timezone object or UTC string
81+
timeZone?: TimeZone | string; // Timezone object or IANA timezone name string
8282
numeral?: Numeral; // Numeral system for number formatting
8383
calendar?: 'gregory' | 'buddhist'; // Calendar system
8484
hour12?: 'h11' | 'h12'; // 12-hour format type
@@ -91,7 +91,7 @@ interface FormatterOptions {
9191
```typescript
9292
interface ParserOptions {
9393
locale?: Locale; // Locale object for localized parsing
94-
timeZone?: TimeZone | 'UTC'; // Timezone object or UTC string
94+
timeZone?: TimeZone | string; // Timezone object or IANA timezone name string
9595
numeral?: Numeral; // Numeral system for number parsing
9696
calendar?: 'gregory' | 'buddhist'; // Calendar system
9797
hour12?: 'h11' | 'h12'; // 12-hour format type

docs/api/isLeapYear.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# isLeapYear()
22

3-
Determine if a given year is a leap year according to the Gregorian calendar rules.
3+
Determines if a given year is a leap year according to the Gregorian calendar rules.
44

55
## Syntax
66

docs/api/isSameDay.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# isSameDay()
22

3-
Check if two Date objects represent the same calendar day, regardless of time.
3+
Checks if two Date objects represent the same calendar day, regardless of time.
44

55
## Syntax
66

docs/api/parse.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ parse('2025-08-23 14:30:45', 'YYYY-MM-DD HH:mm:ss');
6767
| Token | Description | Input Examples |
6868
|-------|-------------|----------------|
6969
| `HH` | Hour in 24-hour format | 23, 08 |
70-
| `H` | Hour in 24-hour format (no padding) | 23, 8 |
70+
| `H` | Hour in 24-hour format without zero padding | 23, 8 |
7171
| `hh` | Hour in 12-hour format | 11, 08 |
72-
| `h` | Hour in 12-hour format (no padding) | 11, 8 |
72+
| `h` | Hour in 12-hour format without zero padding | 11, 8 |
7373
| `mm` | Minutes | 14, 07 |
7474
| `m` | Minutes without zero padding | 14, 7 |
7575
| `ss` | Seconds | 05, 10 |
@@ -140,10 +140,12 @@ For a complete list of all supported locales with import examples, see [Supporte
140140

141141
### timeZone
142142

143-
**Type**: `TimeZone | "UTC"`
143+
**Type**: `TimeZone | string`
144144
**Default**: `undefined` (local timezone)
145145

146-
Interprets the parsed date in the specified timezone. **Note**: If the input string contains a timezone offset (e.g., `Z` or `ZZ` tokens), that offset takes precedence and the `timeZone` option is ignored.
146+
Interprets the parsed date in the specified timezone.
147+
148+
**Note**: If the input string contains a timezone offset (e.g., `Z` or `ZZ` tokens), that offset takes precedence and the `timeZone` option is ignored.
147149

148150
```typescript
149151
import { parse } from 'date-and-time';
@@ -158,6 +160,10 @@ parse('2025-08-23 14:30:00', 'YYYY-MM-DD HH:mm:ss', { timeZone: Tokyo });
158160
parse('2025-08-23 14:30:00', 'YYYY-MM-DD HH:mm:ss', { timeZone: New_York });
159161
// => Fri Aug 23 2025 14:30:00 GMT-0400
160162

163+
// Parse using an IANA timezone name string (no import needed)
164+
parse('2025-08-23 14:30:00', 'YYYY-MM-DD HH:mm:ss', { timeZone: 'Asia/Tokyo' });
165+
// => Fri Aug 23 2025 14:30:00 GMT+0900
166+
161167
// Parse in UTC
162168
parse('2025-08-23 14:30:00', 'YYYY-MM-DD HH:mm:ss', { timeZone: 'UTC' });
163169
// => Fri Aug 23 2025 14:30:00 GMT+0000
@@ -170,8 +176,8 @@ parse('2025-08-23T14:30:00 +05:00', 'YYYY-MM-DD[T]HH:mm:ss ZZ', { timeZone: New_
170176
// => Fri Aug 23 2025 14:30:00 GMT+0500 (New_York timeZone is ignored)
171177
```
172178

173-
:::warning Important Difference from format()
174-
The `parse()` function only accepts TimeZone objects and the "UTC" string for the `timeZone` option. Unlike `format()`, which supports both TimeZone objects and IANA timezone name strings, `parse()` does not support string type timezone names.
179+
:::tip
180+
Like `format()`, `parse()` accepts TimeZone objects, IANA timezone name strings (e.g., `'America/New_York'`), and the `"UTC"` string for the `timeZone` option. If the input string contains a timezone offset token (`Z` or `ZZ`), that offset takes precedence over the `timeZone` option.
175181
:::
176182

177183
For a complete list of all supported timezones with import examples, see [Supported Timezones](../timezones).
@@ -370,12 +376,12 @@ parse('Jan 1 0000', 'MMM D YYYY');
370376

371377
### UTC Input Parsing
372378

373-
If the input string doesn't contain a timezone offset and no `timeZone` option is specified, the function treats the input as local timezone. To parse input as UTC, set `timeZone: 'UTC'` in the options.
379+
If the input string doesn't contain a timezone offset and no `timeZone` option is specified, the function treats the input as the local timezone. To parse input as UTC, set `timeZone: 'UTC'` in the options.
374380

375381
```typescript
376382
import { parse } from 'date-and-time';
377383

378-
// Parsed as local timezone
384+
// Parsed as the local timezone
379385
parse('14:30:45', 'HH:mm:ss');
380386
// => Thu Jan 01 1970 14:30:45 GMT-0800
381387

docs/api/subtract.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# subtract()
22

3-
Calculates the difference between two Date objects and return a rich Duration object with multiple time units and formatting options.
3+
Calculates the difference between two Date objects and returns a rich Duration object with multiple time units and formatting options.
44

55
## Syntax
66

docs/guide/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ const localized = format(date, 'YYYY年M月D日', { locale: ja });
9898

9999
// Timezone-aware operations
100100
const tokyoTime = format(date, 'YYYY-MM-DD HH:mm:ss', { timeZone: Tokyo });
101+
// Or using IANA timezone name string (New in v4.2.0)
102+
const tokyoTime2 = format(date, 'YYYY-MM-DD HH:mm:ss', { timeZone: 'Asia/Tokyo' });
101103
```
102104

103105
## Browser and Environment Support

0 commit comments

Comments
 (0)