Skip to content

Commit fd65464

Browse files
authored
fix(): update isSame isBefore isAfter
fix(): update api && add plugin
2 parents 3b47264 + 8390e64 commit fd65464

14 files changed

+294
-69
lines changed

docs/en/API-reference.md

+23-6
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ The `Dayjs` object is immutable, that is, all API operations that change the `Da
4343
- [As Object `.toObject()`](#as-object-toobject)
4444
- [As String `.toString()`](#as-string-tostring)
4545
- [Query](#query)
46-
- [Is Before `.isBefore(compared: Dayjs)`](#is-before-isbeforecompared-dayjs)
47-
- [Is Same `.isSame(compared: Dayjs)`](#is-same-issamecompared-dayjs)
48-
- [Is After `.isAfter(compared: Dayjs)`](#is-after-isaftercompared-dayjs)
46+
- [Is Before `.isBefore(compared: Dayjs, unit?: string)`](#is-before-isbeforecompared-dayjs-unit-string)
47+
- [Is Same `.isSame(compared: Dayjs, unit?: string)`](#is-same-issamecompared-dayjs-unit-string)
48+
- [Is After `.isAfter(compared: Dayjs, unit?: string)`](#is-after-isaftercompared-dayjs-unit-string)
4949
- [Is a Dayjs `.isDayjs()`](#is-a-dayjs-isdayjscompared-any)
5050
- [Plugin APIs](#plugin-apis)
5151
- [RelativeTime](#relativetime)
5252
- [IsLeapYear](#isleapyear)
5353
- [WeekOfYear](#weekofyear)
54+
- [IsSameOrAfter](#issameorafter)
55+
- [IsSameOrBefore](#issameorbefore)
5456
- [IsBetween](#isbetween)
5557

5658
## Parsing
@@ -383,28 +385,31 @@ dayjs('2019-01-25').toString(); // 'Fri, 25 Jan 2019 02:00:00 GMT'
383385

384386
## Query
385387

386-
### Is Before `.isBefore(compared: Dayjs)`
388+
### Is Before `.isBefore(compared: Dayjs, unit?: string)`
387389

388390
Returns a `boolean` indicating whether the `Dayjs`'s date is before the other supplied `Dayjs`'s.
389391

390392
```js
391393
dayjs().isBefore(dayjs()); // false
394+
dayjs().isBefore(dayjs(), 'year'); // false
392395
```
393396

394-
### Is Same `.isSame(compared: Dayjs)`
397+
### Is Same `.isSame(compared: Dayjs, unit?: string)`
395398

396399
Returns a `boolean` indicating whether the `Dayjs`'s date is the same as the other supplied `Dayjs`'s.
397400

398401
```js
399402
dayjs().isSame(dayjs()); // true
403+
dayjs().isSame(dayjs(), 'year'); // true
400404
```
401405

402-
### Is After `.isAfter(compared: Dayjs)`
406+
### Is After `.isAfter(compared: Dayjs, unit?: string)`
403407

404408
Returns a `boolean` indicating whether the `Dayjs`'s date is after the other supplied `Dayjs`'s.
405409

406410
```js
407411
dayjs().isAfter(dayjs()); // false
412+
dayjs().isAfter(dayjs(), 'year'); // false
408413
```
409414

410415
### Is a Dayjs `.isDayjs(compared: any)`
@@ -436,6 +441,18 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear)
436441

437442
plugin [`WeekOfYear`](./Plugin.md#weekofyear)
438443

444+
### IsSameOrAfter
445+
446+
`.isSameOrAfter` to check if a date is same of after another date
447+
448+
plugin [`IsSameOrAfter`](./Plugin.md#issameorafter)
449+
450+
### IsSameOrBefore
451+
452+
`.isSameOrBefore` to check if a date is same of before another date.
453+
454+
plugin [`IsSameOrBefore`](./Plugin.md#issameorbefore)
455+
439456
### IsBetween
440457

441458
`.isBetween` to check if a date is between two other dates

docs/en/Plugin.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,28 @@ dayjs.extend(weekOfYear)
155155
dayjs('06/27/2018').week() // 26
156156
```
157157

158+
### IsSameOrAfter
159+
- IsSameOrAfter adds `.isSameOrAfter()` API to returns a `boolean` indicating if a date is same of after another date.
160+
161+
```javascript
162+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'
163+
164+
dayjs.extend(isSameOrAfter)
165+
166+
dayjs('2010-10-20').isSameOrAfter('2010-10-19', 'year');
167+
```
168+
169+
### IsSameOrBefore
170+
- IsSameOrBefore adds `.isSameOrBefore()` API to returns a `boolean` indicating if a date is same of before another date.
171+
172+
```javascript
173+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
174+
175+
dayjs.extend(isSameOrBefore)
176+
177+
dayjs('2010-10-20').isSameOrBefore('2010-10-19', 'year');
178+
```
179+
158180
### IsBetween
159181
- IsBetween adds `.isBetween()` API to returns a `boolean` indicating if a date is between two other dates.
160182

@@ -163,7 +185,7 @@ import isBetween from 'dayjs/plugin/isBetween'
163185

164186
dayjs.extend(isBetween)
165187

166-
dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25')); // true
188+
dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25'), 'year');
167189
```
168190

169191
## Customize

docs/es-es/API-reference.md

+23-6
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ El objeto `Dayjs` es inmutable, por lo que toda operación de la API que altere
4343
- [Como objeto `.toObject()`](#como-objecto-toobject)
4444
- [Como cadena `.toString()`](#como-cadena-tostring)
4545
- [Consulta](#consulta)
46-
- [Anterior a `.isBefore(compared: Dayjs)`](#anterior-a-isbeforecompared-dayjs)
47-
- [Igual que `.isSame(compared: Dayjs)`](#igual-que-issamecompared-dayjs)
48-
- [Posterior a `.isAfter(compared: Dayjs)`](#posterior-a-isaftercompared-dayjs)
46+
- [Anterior a `.isBefore(compared: Dayjs, unit?: string)`](#anterior-a-isbeforecompared-dayjs-unit-string)
47+
- [Igual que `.isSame(compared: Dayjs, unit?: string)`](#igual-que-issamecompared-dayjs-unit-string)
48+
- [Posterior a `.isAfter(compared: Dayjs, unit?: string)`](#posterior-a-isaftercompared-dayjs-unit-string)
4949
- [Es Dayjs `.isDayjs()`](#es-dayjs-isdayjscompared-any)
5050
- [API de complementos](#api-de-complementos)
5151
- [RelativeTime](#relativetime)
5252
- [IsLeapYear](#isleapyear)
5353
- [WeekOfYear](#weekofyear)
54+
- [IsSameOrAfter](#issameorafter)
55+
- [IsSameOrBefore](#issameorbefore)
5456
- [IsBetween](#isbetween)
5557

5658
## Análisis
@@ -383,28 +385,31 @@ dayjs('2019-01-25').toString(); // 'Fri, 25 Jan 2019 02:00:00 GMT'
383385

384386
## Consulta
385387

386-
### Anterior a `.isBefore(compared: Dayjs)`
388+
### Anterior a `.isBefore(compared: Dayjs, unit?: string)`
387389

388390
Devuelve un dato de tipo `boolean`, que indica si la fecha del objeto `Dayjs` inicial es anterior o no a la fecha del objeto `Dayjs` a comparar.
389391

390392
```js
391393
dayjs().isBefore(dayjs()); // false
394+
dayjs().isBefore(dayjs(), 'year'); // false
392395
```
393396

394-
### Igual que `.isSame(compared: Dayjs)`
397+
### Igual que `.isSame(compared: Dayjs, unit?: string)`
395398

396399
Devuelve un dato de tipo `boolean`, que indica si la fecha del objeto `Dayjs` inicial es igual o no que la fecha del objeto `Dayjs` a comparar.
397400

398401
```js
399402
dayjs().isSame(dayjs()); // true
403+
dayjs().isSame(dayjs(), 'year'); // true
400404
```
401405

402-
### Posterior a `.isAfter(compared: Dayjs)`
406+
### Posterior a `.isAfter(compared: Dayjs, unit?: string)`
403407

404408
Devuelve un dato de tipo `boolean`, que indica si la fecha del objeto `Dayjs` inicial es posterior o no a la fecha del objeto `Dayjs` a comparar.
405409

406410
```js
407411
dayjs().isAfter(dayjs()); // false
412+
dayjs().isAfter(dayjs(), 'year'); // false
408413
```
409414

410415
### Es Dayjs `.isDayjs(compared: any)`
@@ -436,6 +441,18 @@ complemento [`IsLeapYear`](./Plugin.md#isleapyear)
436441

437442
complemento [`WeekOfYear`](./Plugin.md#weekofyear)
438443

444+
### IsSameOrAfter
445+
446+
`.isSameOrAfter` to check if a date is same of after another date
447+
448+
plugin [`IsSameOrAfter`](./Plugin.md#issameorafter)
449+
450+
### IsSameOrBefore
451+
452+
`.isSameOrBefore` to check if a date is same of before another date.
453+
454+
plugin [`IsSameOrBefore`](./Plugin.md#issameorbefore)
455+
439456
### IsBetween
440457

441458
`.isBetween` para comprobar si una fecha se encuentra entre otras dos fechas dadas

docs/es-es/Plugin.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,28 @@ dayjs.extend(weekOfYear)
161161
dayjs('06/27/2018').week() // 26
162162
```
163163

164+
### IsSameOrAfter
165+
- IsSameOrAfter adds `.isSameOrAfter()` API to returns a `boolean` indicating if a date is same of after another date.
166+
167+
```javascript
168+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'
169+
170+
dayjs.extend(isSameOrAfter)
171+
172+
dayjs('2010-10-20').isSameOrAfter('2010-10-19', 'year');
173+
```
174+
175+
### IsSameOrBefore
176+
- IsSameOrBefore adds `.isSameOrBefore()` API to returns a `boolean` indicating if a date is same of before another date.
177+
178+
```javascript
179+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
180+
181+
dayjs.extend(isSameOrBefore)
182+
183+
dayjs('2010-10-20').isSameOrBefore('2010-10-19', 'year');
184+
```
185+
164186
### IsBetween
165187

166188
* IsBetween añade la API `.isBetween()`, que devuelve un dato de tipo `boolean` indicando si una fecha se encuentra o no entre otras dos dadas.
@@ -170,7 +192,7 @@ import isBetween from 'dayjs/plugin/isBetween'
170192

171193
dayjs.extend(isBetween)
172194

173-
dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25')); // true
195+
dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25'), 'year');
174196
```
175197

176198
## Personalización

docs/ja/API-reference.md

+20-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Day.js は組み込みの `Date.prototype` を変更する代わりに `Dayjs`
4848
* [RelativeTime](#relativetime)
4949
* [IsLeapYear](#isleapyear)
5050
* [WeekOfYear](#weekofyear)
51+
* [IsSameOrAfter](#issameorafter)
52+
* [IsSameOrBefore](#issameorbefore)
5153
* [IsBetween](#isbetween)
5254

5355
---
@@ -451,8 +453,9 @@ dayjs().toString();
451453
`Dayjs` オブジェクトが別の `Dayjs` オブジェクト以前の値かどうかを判定します。
452454

453455
```js
454-
dayjs().isBefore(Dayjs);
456+
dayjs().isBefore(Dayjs, unit? : String);
455457
dayjs().isBefore(dayjs()); // false
458+
dayjs().isBefore(dayjs(), 'year'); // false
456459
```
457460

458461
#### Is Same
@@ -462,8 +465,9 @@ dayjs().isBefore(dayjs()); // false
462465
`Dayjs` オブジェクトが別の `Dayjs` オブジェクトの値と等しいかどうかを判定します。
463466

464467
```js
465-
dayjs().isSame(Dayjs);
468+
dayjs().isSame(Dayjs, unit? : String);
466469
dayjs().isSame(dayjs()); // true
470+
dayjs().isSame(dayjs(), 'year'); // true
467471
```
468472

469473
#### Is After
@@ -473,8 +477,9 @@ dayjs().isSame(dayjs()); // true
473477
`Dayjs` オブジェクトが別の `Dayjs` オブジェクト以降の値かどうかを判定します。
474478

475479
```js
476-
dayjs().isAfter(Dayjs);
480+
dayjs().isAfter(Dayjs, unit? : String);
477481
dayjs().isAfter(dayjs()); // false
482+
dayjs().isAfter(dayjs(), 'year'); // false
478483
```
479484

480485
### Is a Dayjs `.isDayjs(compared: any)`
@@ -506,6 +511,18 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear)
506511

507512
plugin [`WeekOfYear`](./Plugin.md#weekofyear)
508513

514+
### IsSameOrAfter
515+
516+
`.isSameOrAfter` to check if a date is same of after another date
517+
518+
plugin [`IsSameOrAfter`](./Plugin.md#issameorafter)
519+
520+
### IsSameOrBefore
521+
522+
`.isSameOrBefore` to check if a date is same of before another date.
523+
524+
plugin [`IsSameOrBefore`](./Plugin.md#issameorbefore)
525+
509526
### IsBetween
510527

511528
`.isBetween` to check if a date is between two other dates

docs/ja/Plugin.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,27 @@ dayjs.extend(weekOfYear)
155155

156156
dayjs('06/27/2018').week() // 26
157157
```
158+
### IsSameOrAfter
159+
- IsSameOrAfter adds `.isSameOrAfter()` API to returns a `boolean` indicating if a date is same of after another date.
160+
161+
```javascript
162+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'
163+
164+
dayjs.extend(isSameOrAfter)
165+
166+
dayjs('2010-10-20').isSameOrAfter('2010-10-19', 'year');
167+
```
168+
169+
### IsSameOrBefore
170+
- IsSameOrBefore adds `.isSameOrBefore()` API to returns a `boolean` indicating if a date is same of before another date.
171+
172+
```javascript
173+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
174+
175+
dayjs.extend(isSameOrBefore)
176+
177+
dayjs('2010-10-20').isSameOrBefore('2010-10-19', 'year');
178+
```
158179

159180
### IsBetween
160181
- IsBetween adds `.isBetween()` API to returns a `boolean` indicating if a date is between two other dates.
@@ -164,7 +185,7 @@ import isBetween from 'dayjs/plugin/isBetween'
164185

165186
dayjs.extend(isBetween)
166187

167-
dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25')); // true
188+
dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25'), 'year');
168189
```
169190

170191
## カスタマイズ

docs/ko/API-reference.md

+23-6
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ Day.js는 네이티브 `Date.prototype`을 수정하는 대신 `Dayjs` 오브젝
4242
- [As Object `.toObject()`](#as-object-toobject)
4343
- [As String `.toString()`](#as-string-tostring)
4444
- [Query](#query)
45-
- [Is Before `.isBefore(compared: Dayjs)`](#is-before-isbeforecompared--dayjs)
46-
- [Is Same `.isSame(compared: Dayjs)`](#is-same-issamecompared--dayjs)
47-
- [Is After `.isAfter(compared: Dayjs)`](#is-after-isaftercompared--dayjs)
45+
- [Is Before `.isBefore(compared: Dayjs, unit?: string)`](#is-before-isbeforecompared--dayjs-unit-string)
46+
- [Is Same `.isSame(compared: Dayjs, unit?: string)`](#is-same-issamecompared--dayjs-unit-string)
47+
- [Is After `.isAfter(compared: Dayjs, unit?: string)`](#is-after-isaftercompared--dayjs-unit-string)
4848
- [Is a Dayjs `.isDayjs()`](#is-a-dayjs-isdayjscompared-any)
4949
- [Plugin APIs](#plugin-apis)
5050
- [RelativeTime](#relativetime)
5151
- [IsLeapYear](#isleapyear)
5252
- [WeekOfYear](#weekofyear)
53+
- [IsSameOrAfter](#issameorafter)
54+
- [IsSameOrBefore](#issameorbefore)
5355
- [IsBetween](#isbetween)
5456

5557
## Parsing
@@ -382,28 +384,31 @@ dayjs('2019-01-25').toString(); // 'Fri, 25 Jan 2019 02:00:00 GMT'
382384

383385
## Query
384386

385-
### Is Before `.isBefore(compared: Dayjs)`
387+
### Is Before `.isBefore(compared: Dayjs, unit?: string)`
386388

387389
`Dayjs`가 다른 `Dayjs`보다 앞선 시점인지를 확인합니다. 반환 타입은 `boolean` 입니다.
388390

389391
```js
390392
dayjs().isBefore(dayjs()); // false
393+
dayjs().isBefore(dayjs(), 'year'); // false
391394
```
392395

393-
### Is Same `.isSame(compared: Dayjs)`
396+
### Is Same `.isSame(compared: Dayjs, unit?: string)`
394397

395398
`Dayjs`가 다른 `Dayjs`과 동일한 시점인지를 확인합니다. 반환 타입은 `boolean` 입니다.
396399

397400
```js
398401
dayjs().isSame(dayjs()); // true
402+
dayjs().isSame(dayjs(), 'year'); // true
399403
```
400404

401-
### Is After `.isAfter(compared: Dayjs)`
405+
### Is After `.isAfter(compared: Dayjs, unit?: string)`
402406

403407
`Dayjs`가 다른 `Dayjs`보다 뒷선 시점인지를 확인합니다. 반환 타입은 `boolean` 입니다.
404408

405409
```js
406410
dayjs().isAfter(dayjs()); // false
411+
dayjs().isAfter(dayjs(), 'year'); // false
407412
```
408413

409414
### Is a Dayjs `.isDayjs(compared: any)`
@@ -435,6 +440,18 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear)
435440

436441
plugin [`WeekOfYear`](./Plugin.md#weekofyear)
437442

443+
### IsSameOrAfter
444+
445+
`.isSameOrAfter` to check if a date is same of after another date
446+
447+
plugin [`IsSameOrAfter`](./Plugin.md#issameorafter)
448+
449+
### IsSameOrBefore
450+
451+
`.isSameOrBefore` to check if a date is same of before another date.
452+
453+
plugin [`IsSameOrBefore`](./Plugin.md#issameorbefore)
454+
438455
### IsBetween
439456

440457
`.isBetween` to check if a date is between two other dates

0 commit comments

Comments
 (0)