Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ The simplest, most intuitive date and time library.
## Installation

```shell
npm i date-and-time
npm install date-and-time
```

- ES Modules:
### ES Modules (Recommended)

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

- CommonJS:
### CommonJS

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

## CDN Usage

### Via jsDelivr

```html
<script type="module">
import { format } from 'https://cdn.jsdelivr.net/npm/date-and-time/dist/index.js';

console.log(format(new Date(), 'YYYY/MM/DD'));
</script>
```

### Via unpkg

```html
<script type="module">
import { format } from 'https://unpkg.com/date-and-time/dist/index.js';

console.log(format(new Date(), 'YYYY/MM/DD'));
</script>
```

## Migration

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:
Expand Down
12 changes: 10 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@ export default defineConfig({
{ text: 'addSeconds()', link: '/api/addSeconds' },
{ text: 'addMilliseconds()', link: '/api/addMilliseconds' },
{ text: 'subtract()', link: '/api/subtract' },
{ text: 'isLeapYear()', link: '/api/isLeapYear' },
{ text: 'isSameDay()', link: '/api/isSameDay' },
]
},
{
text: 'Utility Functions',
items: [
{ text: 'isLeapYear()', link: '/api/utils/isLeapYear' },
{ text: 'isSameDay()', link: '/api/utils/isSameDay' },
{ text: 'getDaysInMonth()', link: '/api/utils/getDaysInMonth' },
{ text: 'getISOWeekYear()', link: '/api/utils/getISOWeekYear' },
{ text: 'getISOWeek()', link: '/api/utils/getISOWeek' },
]
}
]
Expand Down
27 changes: 6 additions & 21 deletions docs/api/addDays.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ addDays(dateObj, days[, timeZone])

### Parameters

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

### Returns

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

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

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

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

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

### Using IANA Timezone Name Strings

As of v4.3.0, you can use IANA timezone name strings directly instead of importing TimeZone objects:

```typescript
import { addDays } from 'date-and-time';

const nyDate = new Date('2024-03-10T05:00:00Z'); // March 10, 2024 05:00 UTC

// Using IANA timezone name string (New in v4.3.0)
const futureNY = addDays(nyDate, 30, 'America/New_York');
console.log(futureNY); // April 9, 2024 04:00 UTC (EDT, DST adjusted)
```

## Use Cases

### Work Day Calculations
Expand Down
8 changes: 4 additions & 4 deletions docs/api/addHours.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ addHours(dateObj, hours)

### Parameters

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

### Returns

Expand Down
8 changes: 4 additions & 4 deletions docs/api/addMilliseconds.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ addMilliseconds(dateObj, milliseconds)

### Parameters

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

### Returns

Expand Down
8 changes: 4 additions & 4 deletions docs/api/addMinutes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ addMinutes(dateObj, minutes)

### Parameters

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

### Returns

Expand Down
27 changes: 6 additions & 21 deletions docs/api/addMonths.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ addMonths(dateObj, months[, timeZone])

### Parameters

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

### Returns

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

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

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

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

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

### Using IANA Timezone Name Strings

As of v4.3.0, you can use IANA timezone name strings directly instead of importing TimeZone objects:

```typescript
import { addMonths } from 'date-and-time';

const nyDate = new Date('2024-03-10T05:00:00Z'); // March 10, 2024 05:00 UTC

// Using IANA timezone name string (New in v4.3.0)
const futureNY = addMonths(nyDate, 6, 'America/New_York');
console.log(futureNY); // September 10, 2024 04:00 UTC (EDT, DST adjusted)
```

## Use Cases

### Payment Due Dates
Expand Down
8 changes: 4 additions & 4 deletions docs/api/addSeconds.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ addSeconds(dateObj, seconds)

### Parameters

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

### Returns

Expand Down
27 changes: 6 additions & 21 deletions docs/api/addYears.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ addYears(dateObj, years[, timeZone])

### Parameters

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

### Returns

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

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

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

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

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

### Using IANA Timezone Name Strings

As of v4.3.0, you can use IANA timezone name strings directly instead of importing TimeZone objects:

```typescript
import { addYears } from 'date-and-time';

const nyDate = new Date('2024-03-10T05:00:00Z'); // March 10, 2024 05:00 UTC

// Using IANA timezone name string (New in v4.3.0)
const futureNY = addYears(nyDate, 1, 'America/New_York');
console.log(futureNY); // March 10, 2025 04:00 UTC (EST, DST adjusted)
```

## Use Cases

### Age Calculation
Expand Down
6 changes: 3 additions & 3 deletions docs/api/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ compile(formatString)

### Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `formatString` | `string` | Yes | The format pattern to compile |
| Parameter | Type | Required | Description |
|----------------|----------|----------|-------------------------------|
| `formatString` | `string` | Yes | The format pattern to compile |

### Returns

Expand Down
Loading
Loading