Skip to content

Commit fe08ba1

Browse files
Merge pull request #92 from knowledgecode/develop
Develop
2 parents 5befba4 + a68533c commit fe08ba1

21 files changed

Lines changed: 1882 additions & 1107 deletions

PLUGINS.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ date.plugin('foobar');
7676
- It adds `timeSpan()` function that calculates the difference of two dates to the library.
7777

7878
- [timezone](#timezone)
79-
- It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zone names` to the library.
79+
- It adds `formatTZ()`, `parseTZ()`, `transformTZ()`, `addYearsTZ()`, `addMonthsTZ()` and `addDaysTZ()` that support `IANA time zone names` to the library.
8080

8181
- [two-digit-year](#two-digit-year)
8282
- It adds two-digit year notation to the parser.
@@ -290,7 +290,7 @@ In these functions can be available some tokens to format the calculation result
290290

291291
### timezone
292292

293-
It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zone names` (`America/Los_Angeles`, `Asia/Tokyo`, and so on) to the library.
293+
It adds `formatTZ()`, `parseTZ()`, `transformTZ()`, `addYearsTZ()`, `addMonthsTZ()` and `addDaysTZ()` that support `IANA time zone names` (`America/Los_Angeles`, `Asia/Tokyo`, and so on) to the library.
294294

295295
#### formatTZ(dateObj, arg[, timeZone])
296296

@@ -299,7 +299,7 @@ It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zo
299299
- @param {**string**} [timeZone] - Output as this time zone
300300
- @returns {**string**} A formatted string
301301

302-
`formatTZ()` is upward compatible with `format()`. Tokens available for `arg` are the same as those for `format()`. If `timeZone` is omitted, this function assumes `timeZone` to be a local time zone and outputs a string. This means that the result is the same as when `format()` is used.
302+
`formatTZ()` is upward compatible with `format()`. Tokens available for `arg` are the same as those for `format()`. If `timeZone` is omitted, this function assumes `timeZone` to be the local time zone and outputs a string. This means that the result is the same as when `format()` is used.
303303

304304
#### parseTZ(dateString, arg[, timeZone])
305305

@@ -308,7 +308,7 @@ It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zo
308308
- @param {**string**} [timeZone] - Input as this time zone
309309
- @returns {**Date**} A Date object
310310

311-
`parseTZ()` is upward compatible with `parse()`. Tokens available for `arg` are the same as those for `parse()`. `timeZone` in this function is used as supplemental information. if `dateString` contains a time zone offset value (i.e. -0800, +0900), `timeZone` is not be used. If `dateString` doesn't contain a time zone offset value and `timeZone` is omitted, this function assumes `timeZone` to be a local time zone. This means that the result is the same as when `parse()` is used.
311+
`parseTZ()` is upward compatible with `parse()`. Tokens available for `arg` are the same as those for `parse()`. `timeZone` in this function is used as supplemental information. if `dateString` contains a time zone offset value (i.e. -0800, +0900), `timeZone` is not be used. If `dateString` doesn't contain a time zone offset value and `timeZone` is omitted, this function assumes `timeZone` to be the local time zone. This means that the result is the same as when `parse()` is used.
312312

313313
#### transformTZ(dateString, arg1, arg2[, timeZone])
314314

@@ -318,7 +318,34 @@ It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zo
318318
- @param {**string**} [timeZone] - Output as this time zone
319319
- @returns {**string**} A formatted string
320320

321-
`transformTZ()` is upward compatible with `transform()`. `dateString` must itself contain a time zone offset value (i.e. -0800, +0900), otherwise this function assumes it is a local time zone. Tokens available for `arg1` are the same as those for `parse()`, also tokens available for `arg2` are the same as those for `format()`. `timeZone` is a `IANA time zone names`, which is required to output a new formatted string. If it is omitted, this function assumes `timeZone` to be a local time zone. This means that the result is the same as when `transform()` is used.
321+
`transformTZ()` is upward compatible with `transform()`. `dateString` must itself contain a time zone offset value (i.e. -0800, +0900), otherwise this function assumes it is the local time zone. Tokens available for `arg1` are the same as those for `parse()`, also tokens available for `arg2` are the same as those for `format()`. `timeZone` is a `IANA time zone names`, which is required to output a new formatted string. If it is omitted, this function assumes `timeZone` to be the local time zone. This means that the result is the same as when `transform()` is used.
322+
323+
#### addYearsTZ(dateObj, years[, timeZone])
324+
325+
- @param {**Date**} dateObj - A Date object
326+
- @param {**number**} years - The number of years to add
327+
- @param {**string**} [timeZone] - The time zone to use for the calculation
328+
- @returns {**Date**} The Date object after adding the specified number of years
329+
330+
`addYearsTZ()` can calculate adding years in the specified time zone regardless of the execution environment.
331+
332+
#### addMonthsTZ(dateObj, months[, timeZone])
333+
334+
- @param {**Date**} dateObj - A Date object
335+
- @param {**number**} months - The number of months to add
336+
- @param {**string**} [timeZone] - The time zone to use for the calculation
337+
- @returns {**Date**} The Date object after adding the specified number of months
338+
339+
`addMonthsTZ()` can calculate adding months in the specified time zone regardless of the execution environment.
340+
341+
#### addDaysTZ(dateObj, days[, timeZone])
342+
343+
- @param {**Date**} dateObj - A Date object
344+
- @param {**number**} days - The number of days to add
345+
- @param {**string**} [timeZone] - The time zone to use for the calculation
346+
- @returns {**Date**} The Date object after adding the specified number of days
347+
348+
`addDaysTZ()` can calculate adding days in the specified time zone regardless of the execution environment.
322349

323350
```javascript
324351
const date = require('date-and-time');

README.md

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ npm i date-and-time
2525

2626
## Recent Changes
2727

28+
- 3.5.0
29+
- Added `addYearsTZ()`, `addMonthsTZ()`, and `addDaysTZ()` to the `timezone` plugin.
30+
- Revised the approach to adding time and removed the third parameter from `addHours()`, `addMinutes()`, `addSeconds()`, and `addMilliseconds()`.
31+
2832
- 3.4.1
2933
- Fixed an issue where `formatTZ()` would output 0:00 as 24:00 in 24-hour format in Node.js.
3034

3135
- 3.4.0
3236
- Added `zz` (time zone name) and `z` (time zone name abbreviation) tokens to the `timezone` plugin.
3337
- Fixed an issue where token extensions by other plugins were not reflected in functions provided by the `timezone` plugin.
3438

35-
- 3.3.0
36-
- Refactored `format()`, `isValid()`, and `preparse()`, further improved performance.
37-
3839
## Usage
3940

4041
- ES Modules:
@@ -98,16 +99,16 @@ import date from '/path/to/date-and-time.es.min.js';
9899
- [addDays](#adddaysdateobj-days-utc)
99100
- Adding days
100101

101-
- [addHours](#addhoursdateobj-hours-utc)
102+
- [addHours](#addhoursdateobj-hours)
102103
- Adding hours
103104

104-
- [addMinutes](#addminutesdateobj-minutes-utc)
105+
- [addMinutes](#addminutesdateobj-minutes)
105106
- Adding minutes
106107

107-
- [addSeconds](#addsecondsdateobj-seconds-utc)
108+
- [addSeconds](#addsecondsdateobj-seconds)
108109
- Adding seconds
109110

110-
- [addMilliseconds](#addmillisecondsdateobj-milliseconds-utc)
111+
- [addMilliseconds](#addmillisecondsdateobj-milliseconds)
111112
- Adding milliseconds
112113

113114
- [subtract](#subtractdate1-date2)
@@ -434,11 +435,11 @@ date.transform('13:05', 'HH:mm', 'hh:mm A');
434435
### addYears(dateObj, years[, utc])
435436

436437
- @param {**Date**} dateObj - A Date object
437-
- @param {**number**} years - Number of years to add
438-
- @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
439-
- @returns {**Date**} The Date object after adding the value
438+
- @param {**number**} years - The number of years to add
439+
- @param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`
440+
- @returns {**Date**} The Date object after adding the specified number of years
440441

441-
Adds years to the date object.
442+
Adds years to a date object. Subtraction is also possible by specifying a negative value. If the third parameter is false or omitted, this function calculates based on the system's default time zone. If you need to obtain calculation results based on a specific time zone regardless of the execution system, consider using the `addYearsTZ()`, which allows you to specify a time zone name as the third parameter. See [PLUGINS.md](./PLUGINS.md) for details.
442443

443444
```javascript
444445
const now = new Date();
@@ -456,11 +457,11 @@ const next_next_year = date.addYears(next_year, 1, true); // => Feb 28 2022
456457
### addMonths(dateObj, months[, utc])
457458

458459
- @param {**Date**} dateObj - A Date object
459-
- @param {**number**} months - Number of months to add
460-
- @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
461-
- @returns {**Date**} The Date object after adding the value
460+
- @param {**number**} months - The number of months to add
461+
- @param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`
462+
- @returns {**Date**} The Date object after adding the specified number of months
462463

463-
Adds months to the date object.
464+
Adds months to a date object. Subtraction is also possible by specifying a negative value. If the third parameter is false or omitted, this function calculates based on the system's default time zone. If you need to obtain calculation results based on a specific time zone regardless of the execution system, consider using the `addMonthsTZ()`, which allows you to specify a time zone name as the third parameter. See [PLUGINS.md](./PLUGINS.md) for details.
464465

465466
```javascript
466467
const now = new Date();
@@ -478,57 +479,67 @@ const next_next_month = date.addMonths(next_month, 1, true); // => Mar 28 202
478479
### addDays(dateObj, days[, utc])
479480

480481
- @param {**Date**} dateObj - A Date object
481-
- @param {**number**} days - Number of days to add
482-
- @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
483-
- @returns {**Date**} The Date object after adding the value
482+
- @param {**number**} days - The number of days to add
483+
- @param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`
484+
- @returns {**Date**} The Date object after adding the specified number of days
485+
486+
Adds days to a date object. Subtraction is also possible by specifying a negative value. If the third parameter is false or omitted, this function calculates based on the system's default time zone. If you need to obtain calculation results based on a specific time zone regardless of the execution system, consider using the `addDaysTZ()`, which allows you to specify a time zone name as the third parameter. See [PLUGINS.md](./PLUGINS.md) for details.
484487

485488
```javascript
486489
const now = new Date();
487490
const yesterday = date.addDays(now, -1);
488491
```
489492

490-
### addHours(dateObj, hours[, utc])
493+
### addHours(dateObj, hours)
491494

492495
- @param {**Date**} dateObj - A Date object
493-
- @param {**number**} hours - Number of hours to add
494-
- @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
495-
- @returns {**Date**} The Date object after adding the value
496+
- @param {**number**} hours - The number of hours to add
497+
- ~~@param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`~~ `Removed in: v3.5.0`
498+
- @returns {**Date**} The Date object after adding the specified number of hours
499+
500+
Adds hours to a date object. Subtraction is also possible by specifying a negative value. The third parameter was deprecated in version 3.5.0. Regardless of what is specified for this parameter, the calculation results will not change.
496501

497502
```javascript
498503
const now = new Date();
499504
const an_hour_ago = date.addHours(now, -1);
500505
```
501506

502-
### addMinutes(dateObj, minutes[, utc])
507+
### addMinutes(dateObj, minutes)
503508

504509
- @param {**Date**} dateObj - A Date object
505-
- @param {**number**} minutes - Number of minutes to add
506-
- @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
507-
- @returns {**Date**} The Date object after adding the value
510+
- @param {**number**} minutes - The number of minutes to add
511+
- ~~@param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`~~ `Removed in: v3.5.0`
512+
- @returns {**Date**} The Date object after adding the specified number of minutes
513+
514+
Adds minutes to a date object. Subtraction is also possible by specifying a negative value. The third parameter was deprecated in version 3.5.0. Regardless of what is specified for this parameter, the calculation results will not change.
508515

509516
```javascript
510517
const now = new Date();
511518
const two_minutes_later = date.addMinutes(now, 2);
512519
```
513520

514-
### addSeconds(dateObj, seconds[, utc])
521+
### addSeconds(dateObj, seconds)
515522

516523
- @param {**Date**} dateObj - A Date object
517-
- @param {**number**} seconds - Number of seconds to add
518-
- @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
519-
- @returns {**Date**} The Date object after adding the value
524+
- @param {**number**} seconds - The number of seconds to add
525+
- ~~@param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`~~ `Removed in: v3.5.0`
526+
- @returns {**Date**} The Date object after adding the specified number of seconds
527+
528+
Adds seconds to a date object. Subtraction is also possible by specifying a negative value. The third parameter was deprecated in version 3.5.0. Regardless of what is specified for this parameter, the calculation results will not change.
520529

521530
```javascript
522531
const now = new Date();
523532
const three_seconds_ago = date.addSeconds(now, -3);
524533
```
525534

526-
### addMilliseconds(dateObj, milliseconds[, utc])
535+
### addMilliseconds(dateObj, milliseconds)
527536

528537
- @param {**Date**} dateObj - A Date object
529-
- @param {**number**} milliseconds - Number of milliseconds to add
530-
- @param {**boolean**} [utc] - Calculates as UTC `Added in: v3.0.0`
531-
- @returns {**Date**} The Date object after adding the value
538+
- @param {**number**} milliseconds - The number of milliseconds to add
539+
- ~~@param {**boolean**} [utc] - If true, calculates the date in UTC `Added in: v3.0.0`~~ `Removed in: v3.5.0`
540+
- @returns {**Date**} The Date object after adding the specified number of milliseconds
541+
542+
Adds milliseconds to a date object. Subtraction is also possible by specifying a negative value. The third parameter was deprecated in version 3.5.0. Regardless of what is specified for this parameter, the calculation results will not change.
532543

533544
```javascript
534545
const now = new Date();

date-and-time.d.ts

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -153,63 +153,95 @@ export function transform(dateString: string, compiledObj1: string[], compiledOb
153153
/**
154154
* Adding years
155155
* @param dateObj - A Date object
156-
* @param years - Number of years to add
157-
* @param [utc] - Calculates as UTC
158-
* @returns The Date object after adding the value
156+
* @param years - The number of years to add
157+
* @param [utc] - If true, calculates the date in UTC
158+
* @returns The Date object after adding the specified number of years
159159
*/
160160
export function addYears(dateObj: Date, years: number, utc?: boolean): Date;
161161

162162
/**
163163
* Adding months
164164
* @param dateObj - A Date object
165-
* @param months - Number of months to add
166-
* @param [utc] - Calculates as UTC
167-
* @returns The Date object after adding the value
165+
* @param months - The number of months to add
166+
* @param [utc] - If true, calculates the date in UTC
167+
* @returns The Date object after adding the specified number of months
168168
*/
169169
export function addMonths(dateObj: Date, months: number, utc?: boolean): Date;
170170

171171
/**
172172
* Adding days
173173
* @param dateObj - A Date object
174-
* @param days - Number of days to add
175-
* @param [utc] - Calculates as UTC
176-
* @returns The Date object after adding the value
174+
* @param days - The number of days to add
175+
* @param [utc] - If true, calculates the date in UTC
176+
* @returns The Date object after adding the specified number of days
177177
*/
178178
export function addDays(dateObj: Date, days: number, utc?: boolean): Date;
179179

180180
/**
181181
* Adding hours
182182
* @param dateObj - A Date object
183-
* @param hours - Number of hours to add
184-
* @param [utc] - Calculates as UTC
185-
* @returns The Date object after adding the value
183+
* @param hours - The number of hours to add
184+
* @returns The Date object after adding the specified number of hours
185+
*/
186+
export function addHours(dateObj: Date, hours: number): Date;
187+
188+
/**
189+
* @deprecated The `utc` parameter is ignored. The function always returns the same result regardless of this value.
190+
* @param dateObj - A Date object
191+
* @param hours - The number of hours to add
192+
* @param [utc] - If true, calculates the date in UTC
193+
* @returns The Date object after adding the specified number of hours
186194
*/
187195
export function addHours(dateObj: Date, hours: number, utc?: boolean): Date;
188196

189197
/**
190198
* Adding minutes
191199
* @param dateObj - A Date object
192-
* @param minutes - Number of minutes to add
193-
* @param [utc] - Calculates as UTC
194-
* @returns The Date object after adding the value
200+
* @param minutes - The number of minutes to add
201+
* @returns The Date object after adding the specified number of minutes
202+
*/
203+
export function addMinutes(dateObj: Date, minutes: number): Date;
204+
205+
/**
206+
* @deprecated The `utc` parameter is ignored. The function always returns the same result regardless of this value.
207+
* @param dateObj - A Date object
208+
* @param minutes - The number of minutes to add
209+
* @param [utc] - If true, calculates the date in UTC
210+
* @returns The Date object after adding the specified number of minutes
195211
*/
196212
export function addMinutes(dateObj: Date, minutes: number, utc?: boolean): Date;
197213

198214
/**
199215
* Adding seconds
200216
* @param dateObj - A Date object
201-
* @param seconds - Number of seconds to add
202-
* @param [utc] - Calculates as UTC
203-
* @returns The Date object after adding the value
217+
* @param seconds - The number of seconds to add
218+
* @returns The Date object after adding the specified number of seconds
219+
*/
220+
export function addSeconds(dateObj: Date, seconds: number): Date;
221+
222+
/**
223+
* @deprecated The `utc` parameter is ignored. The function always returns the same result regardless of this value.
224+
* @param dateObj - A Date object
225+
* @param seconds - The number of seconds to add
226+
* @param [utc] - If true, calculates the date in UTC
227+
* @returns The Date object after adding the specified number of seconds
204228
*/
205229
export function addSeconds(dateObj: Date, seconds: number, utc?: boolean): Date;
206230

207231
/**
208232
* Adding milliseconds
209233
* @param dateObj - A Date object
210-
* @param milliseconds - Number of milliseconds to add
211-
* @param [utc] - Calculates as UTC
212-
* @returns The Date object after adding the value
234+
* @param milliseconds - The number of milliseconds to add
235+
* @returns The Date object after adding the specified number of milliseconds
236+
*/
237+
export function addMilliseconds(dateObj: Date, milliseconds: number): Date;
238+
239+
/**
240+
* @deprecated The `utc` parameter is ignored. The function always returns the same result regardless of this value.
241+
* @param dateObj - A Date object
242+
* @param milliseconds - The number of milliseconds to add
243+
* @param [utc] - If true, calculates the date in UTC
244+
* @returns The Date object after adding the specified number of milliseconds
213245
*/
214246
export function addMilliseconds(dateObj: Date, milliseconds: number, utc?: boolean): Date;
215247

0 commit comments

Comments
 (0)