Skip to content

Commit ebcd8f6

Browse files
Merge pull request #122 from knowledgecode/develop
feat: release v4.4.0 — new plugins, utilities, and docs improvements
2 parents a36a35a + 5e9b49e commit ebcd8f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2597
-3460
lines changed

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ The simplest, most intuitive date and time library.
1717
## Installation
1818

1919
```shell
20-
npm i date-and-time
20+
npm install date-and-time
2121
```
2222

23-
- ES Modules:
23+
### ES Modules (Recommended)
2424

2525
```typescript
2626
import { format } from 'date-and-time';
@@ -29,7 +29,7 @@ format(new Date(), 'ddd, MMM DD YYYY');
2929
// => Wed, Jul 09 2025
3030
```
3131

32-
- CommonJS:
32+
### CommonJS
3333

3434
```typescript
3535
const { format } = require('date-and-time');
@@ -38,6 +38,28 @@ format(new Date(), 'ddd, MMM DD YYYY');
3838
// => Wed, Jul 09 2025
3939
```
4040

41+
## CDN Usage
42+
43+
### Via jsDelivr
44+
45+
```html
46+
<script type="module">
47+
import { format } from 'https://cdn.jsdelivr.net/npm/date-and-time/dist/index.js';
48+
49+
console.log(format(new Date(), 'YYYY/MM/DD'));
50+
</script>
51+
```
52+
53+
### Via unpkg
54+
55+
```html
56+
<script type="module">
57+
import { format } from 'https://unpkg.com/date-and-time/dist/index.js';
58+
59+
console.log(format(new Date(), 'YYYY/MM/DD'));
60+
</script>
61+
```
62+
4163
## Migration
4264

4365
Version `4.x` has been completely rewritten in TypeScript and some features from `3.x` are no longer compatible. The main changes are as follows:

docs/.vitepress/config.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,16 @@ export default defineConfig({
5959
{ text: 'addSeconds()', link: '/api/addSeconds' },
6060
{ text: 'addMilliseconds()', link: '/api/addMilliseconds' },
6161
{ text: 'subtract()', link: '/api/subtract' },
62-
{ text: 'isLeapYear()', link: '/api/isLeapYear' },
63-
{ text: 'isSameDay()', link: '/api/isSameDay' },
62+
]
63+
},
64+
{
65+
text: 'Utility Functions',
66+
items: [
67+
{ text: 'isLeapYear()', link: '/api/utils/isLeapYear' },
68+
{ text: 'isSameDay()', link: '/api/utils/isSameDay' },
69+
{ text: 'getDaysInMonth()', link: '/api/utils/getDaysInMonth' },
70+
{ text: 'getISOWeekYear()', link: '/api/utils/getISOWeekYear' },
71+
{ text: 'getISOWeek()', link: '/api/utils/getISOWeek' },
6472
]
6573
}
6674
]

docs/api/addDays.md

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ addDays(dateObj, days[, timeZone])
1010

1111
### Parameters
1212

13-
| Parameter | Type | Required | Description |
14-
|-----------|------|----------|-------------|
15-
| `dateObj` | `Date` | Yes | The base Date object |
16-
| `days` | `number` | Yes | Number of days to add (positive) or subtract (negative) |
17-
| `timeZone` | `TimeZone \| string` | No | Timezone for the calculation |
13+
| Parameter | Type | Required | Description |
14+
|------------|----------------------|----------|---------------------------------------------------------|
15+
| `dateObj` | `Date` | Yes | The base Date object |
16+
| `days` | `number` | Yes | Number of days to add (positive) or subtract (negative) |
17+
| `timeZone` | `TimeZone \| string` | No | Timezone for the calculation |
1818

1919
### Returns
2020

@@ -42,34 +42,19 @@ console.log(past); // August 10, 2024
4242

4343
```typescript
4444
import { addDays } from 'date-and-time';
45-
import New_York from 'date-and-time/timezones/America/New_York';
4645

4746
// Working with specific timezones
4847
const nyDate = new Date('2024-03-10T05:00:00Z'); // March 10, 2024 05:00 UTC (DST transition day)
4948

5049
// Add 30 days in New York timezone
51-
const futureNY = addDays(nyDate, 30, New_York);
50+
const futureNY = addDays(nyDate, 30, 'America/New_York');
5251
console.log(futureNY); // April 9, 2024 04:00 UTC (EDT, DST adjusted)
5352

5453
// UTC calculation for comparison
5554
const futureUTC = addDays(nyDate, 30, 'UTC');
5655
console.log(futureUTC); // April 9, 2024 05:00 UTC (same time, no DST adjustment)
5756
```
5857

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-
7358
## Use Cases
7459

7560
### Work Day Calculations

docs/api/addHours.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ addHours(dateObj, hours)
1010

1111
### Parameters
1212

13-
| Parameter | Type | Required | Description |
14-
|-----------|------|----------|-------------|
15-
| `dateObj` | `Date` | Yes | The base Date object |
16-
| `hours` | `number` | Yes | Number of hours to add (positive) or subtract (negative) |
13+
| Parameter | Type | Required | Description |
14+
|-----------|----------|----------|----------------------------------------------------------|
15+
| `dateObj` | `Date` | Yes | The base Date object |
16+
| `hours` | `number` | Yes | Number of hours to add (positive) or subtract (negative) |
1717

1818
### Returns
1919

docs/api/addMilliseconds.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ addMilliseconds(dateObj, milliseconds)
1010

1111
### Parameters
1212

13-
| Parameter | Type | Required | Description |
14-
|-----------|------|----------|-------------|
15-
| `dateObj` | `Date` | Yes | The base Date object |
16-
| `milliseconds` | `number` | Yes | Number of milliseconds to add (positive) or subtract (negative) |
13+
| Parameter | Type | Required | Description |
14+
|----------------|----------|----------|-----------------------------------------------------------------|
15+
| `dateObj` | `Date` | Yes | The base Date object |
16+
| `milliseconds` | `number` | Yes | Number of milliseconds to add (positive) or subtract (negative) |
1717

1818
### Returns
1919

docs/api/addMinutes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ addMinutes(dateObj, minutes)
1010

1111
### Parameters
1212

13-
| Parameter | Type | Required | Description |
14-
|-----------|------|----------|-------------|
15-
| `dateObj` | `Date` | Yes | The base Date object |
16-
| `minutes` | `number` | Yes | Number of minutes to add (positive) or subtract (negative) |
13+
| Parameter | Type | Required | Description |
14+
|-----------|----------|----------|------------------------------------------------------------|
15+
| `dateObj` | `Date` | Yes | The base Date object |
16+
| `minutes` | `number` | Yes | Number of minutes to add (positive) or subtract (negative) |
1717

1818
### Returns
1919

docs/api/addMonths.md

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ addMonths(dateObj, months[, timeZone])
1010

1111
### Parameters
1212

13-
| Parameter | Type | Required | Description |
14-
|-----------|------|----------|-------------|
15-
| `dateObj` | `Date` | Yes | The base Date object |
16-
| `months` | `number` | Yes | Number of months to add (positive) or subtract (negative) |
17-
| `timeZone` | `TimeZone \| string` | No | Timezone for the calculation |
13+
| Parameter | Type | Required | Description |
14+
|------------|----------------------|----------|-----------------------------------------------------------|
15+
| `dateObj` | `Date` | Yes | The base Date object |
16+
| `months` | `number` | Yes | Number of months to add (positive) or subtract (negative) |
17+
| `timeZone` | `TimeZone \| string` | No | Timezone for the calculation |
1818

1919
### Returns
2020

@@ -42,34 +42,19 @@ console.log(past); // October 15, 2023
4242

4343
```typescript
4444
import { addMonths } from 'date-and-time';
45-
import New_York from 'date-and-time/timezones/America/New_York';
4645

4746
// Working with specific timezones
4847
const nyDate = new Date('2024-03-10T05:00:00Z'); // March 10, 2024 05:00 UTC (DST transition day)
4948

5049
// Add 6 months in New York timezone
51-
const futureNY = addMonths(nyDate, 6, New_York);
50+
const futureNY = addMonths(nyDate, 6, 'America/New_York');
5251
console.log(futureNY); // September 10, 2024 04:00 UTC (EDT, DST adjusted)
5352

5453
// UTC calculation for comparison
5554
const futureUTC = addMonths(nyDate, 6, 'UTC');
5655
console.log(futureUTC); // September 10, 2024 05:00 UTC (same time, no DST adjustment)
5756
```
5857

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-
7358
## Use Cases
7459

7560
### Payment Due Dates

docs/api/addSeconds.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ addSeconds(dateObj, seconds)
1010

1111
### Parameters
1212

13-
| Parameter | Type | Required | Description |
14-
|-----------|------|----------|-------------|
15-
| `dateObj` | `Date` | Yes | The base Date object |
16-
| `seconds` | `number` | Yes | Number of seconds to add (positive) or subtract (negative) |
13+
| Parameter | Type | Required | Description |
14+
|-----------|----------|----------|------------------------------------------------------------|
15+
| `dateObj` | `Date` | Yes | The base Date object |
16+
| `seconds` | `number` | Yes | Number of seconds to add (positive) or subtract (negative) |
1717

1818
### Returns
1919

docs/api/addYears.md

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ addYears(dateObj, years[, timeZone])
1010

1111
### Parameters
1212

13-
| Parameter | Type | Required | Description |
14-
|-----------|------|----------|-------------|
15-
| `dateObj` | `Date` | Yes | The base Date object |
16-
| `years` | `number` | Yes | Number of years to add (positive) or subtract (negative) |
17-
| `timeZone` | `TimeZone \| string` | No | Timezone for the calculation |
13+
| Parameter | Type | Required | Description |
14+
|------------|----------------------|----------|----------------------------------------------------------|
15+
| `dateObj` | `Date` | Yes | The base Date object |
16+
| `years` | `number` | Yes | Number of years to add (positive) or subtract (negative) |
17+
| `timeZone` | `TimeZone \| string` | No | Timezone for the calculation |
1818

1919
### Returns
2020

@@ -42,34 +42,19 @@ console.log(past); // January 15, 2022
4242

4343
```typescript
4444
import { addYears } from 'date-and-time';
45-
import New_York from 'date-and-time/timezones/America/New_York';
4645

4746
// Working with specific timezones
4847
const nyDate = new Date('2024-03-10T05:00:00Z'); // March 10, 2024 05:00 UTC (DST transition day)
4948

5049
// Add years in New York timezone
51-
const futureNY = addYears(nyDate, 1, New_York);
50+
const futureNY = addYears(nyDate, 1, 'America/New_York');
5251
console.log(futureNY); // March 10, 2025 04:00 UTC (EST, DST adjusted)
5352

5453
// UTC calculation for comparison
5554
const futureUTC = addYears(nyDate, 1, 'UTC');
5655
console.log(futureUTC); // March 10, 2025 05:00 UTC (same time, no DST adjustment)
5756
```
5857

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-
7358
## Use Cases
7459

7560
### Age Calculation

docs/api/compile.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ compile(formatString)
1010

1111
### Parameters
1212

13-
| Parameter | Type | Required | Description |
14-
|-----------|------|----------|-------------|
15-
| `formatString` | `string` | Yes | The format pattern to compile |
13+
| Parameter | Type | Required | Description |
14+
|----------------|----------|----------|-------------------------------|
15+
| `formatString` | `string` | Yes | The format pattern to compile |
1616

1717
### Returns
1818

0 commit comments

Comments
 (0)