Skip to content

Commit 15a424e

Browse files
Merge pull request #101 from knowledgecode/develop
Add comprehensive documentation site with VitePress
2 parents 6ba312d + 3231a65 commit 15a424e

31 files changed

+9371
-614
lines changed

.github/workflows/deploy-docs.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Deploy VitePress site to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- 'docs/**'
9+
- '.github/workflows/deploy-docs.yml'
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
concurrency:
18+
group: pages
19+
cancel-in-progress: false
20+
21+
jobs:
22+
build:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Setup Node.js
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: 18
34+
cache: npm
35+
36+
- name: Setup Pages
37+
uses: actions/configure-pages@v4
38+
39+
- name: Install dependencies
40+
run: npm ci
41+
42+
- name: Build with VitePress
43+
run: npm run docs:build
44+
45+
- name: Upload artifact
46+
uses: actions/upload-pages-artifact@v3
47+
with:
48+
path: docs/.vitepress/dist
49+
50+
deploy:
51+
needs: build
52+
runs-on: ubuntu-latest
53+
permissions:
54+
pages: write
55+
id-token: write
56+
steps:
57+
- name: Deploy to GitHub Pages
58+
id: deployment
59+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
.claude/
33
CLAUDE.md
4+
cache/
45
coverage/
56
dist/
6-
node_modules/
7+
node_modules/

docs/.vitepress/config.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { defineConfig } from 'vitepress';
2+
3+
export default defineConfig({
4+
title: 'date-and-time',
5+
description: 'The simplest, most intuitive date and time library',
6+
base: '/date-and-time/',
7+
ignoreDeadLinks: true,
8+
9+
head: [
10+
['link', { rel: 'icon', href: '/date-and-time/favicon.ico' }]
11+
],
12+
13+
themeConfig: {
14+
logo: '/logo.png',
15+
16+
nav: [
17+
{ text: 'Guide', link: '/guide/' },
18+
{ text: 'API Reference', link: '/api/' },
19+
{ text: 'Locales', link: '/locales' },
20+
{ text: 'Timezones', link: '/timezones' },
21+
{ text: 'Plugins', link: '/plugins' },
22+
{ text: 'Migration', link: '/migration' },
23+
{
24+
text: 'Links',
25+
items: [
26+
{ text: 'GitHub', link: 'https://github.com/knowledgecode/date-and-time' },
27+
{ text: 'npm', link: 'https://www.npmjs.com/package/date-and-time' }
28+
]
29+
}
30+
],
31+
32+
sidebar: {
33+
'/guide/': [
34+
{
35+
text: 'Getting Started',
36+
items: [
37+
{ text: 'Introduction', link: '/guide/' },
38+
{ text: 'Installation', link: '/guide/installation' },
39+
{ text: 'Quick Start', link: '/guide/quick-start' }
40+
]
41+
}
42+
],
43+
'/api/': [
44+
{
45+
text: 'Core Functions',
46+
items: [
47+
{ text: 'Overview', link: '/api/' },
48+
{ text: 'format()', link: '/api/format' },
49+
{ text: 'parse()', link: '/api/parse' },
50+
{ text: 'compile()', link: '/api/compile' },
51+
{ text: 'preparse()', link: '/api/preparse' },
52+
{ text: 'isValid()', link: '/api/isValid' },
53+
{ text: 'transform()', link: '/api/transform' },
54+
{ text: 'addYears()', link: '/api/addYears' },
55+
{ text: 'addMonths()', link: '/api/addMonths' },
56+
{ text: 'addDays()', link: '/api/addDays' },
57+
{ text: 'addHours()', link: '/api/addHours' },
58+
{ text: 'addMinutes()', link: '/api/addMinutes' },
59+
{ text: 'addSeconds()', link: '/api/addSeconds' },
60+
{ text: 'addMilliseconds()', link: '/api/addMilliseconds' },
61+
{ text: 'subtract()', link: '/api/subtract' },
62+
{ text: 'isLeapYear()', link: '/api/isLeapYear' },
63+
{ text: 'isSameDay()', link: '/api/isSameDay' },
64+
]
65+
}
66+
]
67+
},
68+
69+
socialLinks: [
70+
{ icon: 'github', link: 'https://github.com/knowledgecode/date-and-time' }
71+
],
72+
73+
footer: {
74+
message: 'Released under the MIT License.',
75+
copyright: 'Copyright © 2015 KNOWLEDGECODE'
76+
},
77+
78+
search: {
79+
provider: 'local'
80+
}
81+
},
82+
83+
markdown: {
84+
theme: {
85+
light: 'github-light',
86+
dark: 'github-dark'
87+
},
88+
lineNumbers: true
89+
}
90+
})

docs/api/addDays.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# addDays()
2+
3+
Adds or subtracts days from a Date object. Handles month boundaries, leap years, and daylight saving time transitions properly.
4+
5+
## Syntax
6+
7+
```typescript
8+
addDays(dateObj, days[, timeZone])
9+
```
10+
11+
### Parameters
12+
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 \| 'UTC'` | No | Timezone for the calculation |
18+
19+
### Returns
20+
21+
`Date` - A new Date object with the specified number of days added or subtracted
22+
23+
## Basic Examples
24+
25+
### Adding and Subtracting Days
26+
27+
```typescript
28+
import { addDays } from 'date-and-time';
29+
30+
const date = new Date(2024, 7, 15); // August 15, 2024
31+
32+
// Add days
33+
const future = addDays(date, 10);
34+
console.log(future); // August 25, 2024
35+
36+
// Subtract days
37+
const past = addDays(date, -5);
38+
console.log(past); // August 10, 2024
39+
```
40+
41+
### Daylight Saving Time Aware Calculations
42+
43+
```typescript
44+
import { addDays } from 'date-and-time';
45+
import New_York from 'date-and-time/timezones/America/New_York';
46+
47+
// Working with specific timezones
48+
const nyDate = new Date('2024-03-10T05:00:00Z'); // March 10, 2024 05:00 UTC (DST transition day)
49+
50+
// Add 30 days in New York timezone
51+
const futureNY = addDays(nyDate, 30, New_York);
52+
console.log(futureNY); // April 9, 2024 04:00 UTC (EDT, DST adjusted)
53+
54+
// UTC calculation for comparison
55+
const futureUTC = addDays(nyDate, 30, 'UTC');
56+
console.log(futureUTC); // April 9, 2024 05:00 UTC (same time, no DST adjustment)
57+
```
58+
59+
## Use Cases
60+
61+
### Work Day Calculations
62+
63+
```typescript
64+
function addBusinessDays(date: Date, businessDays: number): Date {
65+
let result = new Date(date);
66+
let daysToAdd = businessDays;
67+
68+
while (daysToAdd > 0) {
69+
result = addDays(result, 1);
70+
const dayOfWeek = result.getDay();
71+
72+
// Skip weekends (0 = Sunday, 6 = Saturday)
73+
if (dayOfWeek !== 0 && dayOfWeek !== 6) {
74+
daysToAdd--;
75+
}
76+
}
77+
78+
return result;
79+
}
80+
81+
const friday = new Date(2024, 7, 23); // August 23, 2024 (Friday)
82+
const nextBusinessDay = addBusinessDays(friday, 1);
83+
console.log(nextBusinessDay); // August 26, 2024 (Monday)
84+
```
85+
86+
### Date Range Generation
87+
88+
```typescript
89+
function generateDateRange(startDate: Date, endDate: Date): Date[] {
90+
const dates: Date[] = [];
91+
let currentDate = new Date(startDate);
92+
93+
while (currentDate <= endDate) {
94+
dates.push(new Date(currentDate));
95+
currentDate = addDays(currentDate, 1);
96+
}
97+
98+
return dates;
99+
}
100+
101+
const start = new Date(2024, 7, 28); // August 28, 2024
102+
const end = new Date(2024, 8, 3); // September 3, 2024
103+
const dateRange = generateDateRange(start, end);
104+
console.log(dateRange);
105+
// [Aug 28, Aug 29, Aug 30, Aug 31, Sep 1, Sep 2, Sep 3]
106+
```
107+
108+
## Immutability
109+
110+
`addDays()` does not modify the original Date object:
111+
112+
```typescript
113+
const originalDate = new Date(2024, 7, 15);
114+
const modifiedDate = addDays(originalDate, 10);
115+
116+
console.log(originalDate); // August 15, 2024 (unchanged)
117+
console.log(modifiedDate); // August 25, 2024 (new object)
118+
```
119+
120+
## See Also
121+
122+
- [`addYears()`](./addYears) - Add/subtract years
123+
- [`addMonths()`](./addMonths) - Add/subtract months
124+
- [`addHours()`](./addHours) - Add/subtract hours
125+
- [`addMinutes()`](./addMinutes) - Add/subtract minutes
126+
- [`addSeconds()`](./addSeconds) - Add/subtract seconds
127+
- [`addMilliseconds()`](./addMilliseconds) - Add/subtract milliseconds
128+
- [`subtract()`](./subtract) - Calculate differences with Duration objects

0 commit comments

Comments
 (0)