From 1eb3499116ce23712e0014eb0751038e5d6e6826 Mon Sep 17 00:00:00 2001 From: iamkun Date: Tue, 11 Dec 2018 20:03:37 +0800 Subject: [PATCH 1/7] chore: add comments --- src/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 3b57655bc..b4875227e 100644 --- a/src/index.js +++ b/src/index.js @@ -244,7 +244,7 @@ class Dayjs { [C.MIN]: C.MILLISECONDS_A_MINUTE, [C.H]: C.MILLISECONDS_A_HOUR, [C.S]: C.MILLISECONDS_A_SECOND - }[unit] || 1 + }[unit] || 1 // ms const nextTimeStamp = this.valueOf() + (number * step) return wrapper(nextTimeStamp, this) @@ -296,7 +296,7 @@ class Dayjs { ss: Utils.padStart(this.$s, 2, '0'), SSS: Utils.padStart(this.$ms, 3, '0'), Z: zoneStr - }[match] || zoneStr.replace(':', '') + }[match] || zoneStr.replace(':', '') // 'ZZ' }) } @@ -315,7 +315,7 @@ class Dayjs { [C.H]: diff / C.MILLISECONDS_A_HOUR, [C.MIN]: diff / C.MILLISECONDS_A_MINUTE, [C.S]: diff / C.MILLISECONDS_A_SECOND - }[unit] || diff + }[unit] || diff // milliseconds return float ? result : Utils.absFloor(result) } From 766cd6ad59d8272c1187cbce1a14624ef8e6c2d7 Mon Sep 17 00:00:00 2001 From: iamkun Date: Tue, 11 Dec 2018 20:09:44 +0800 Subject: [PATCH 2/7] docs: update en doc --- docs/en/API-reference.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/en/API-reference.md b/docs/en/API-reference.md index 5d21d2ffb..b5d4e7502 100644 --- a/docs/en/API-reference.md +++ b/docs/en/API-reference.md @@ -43,9 +43,9 @@ The `Dayjs` object is immutable, that is, all API operations that change the `Da - [As Object `.toObject()`](#as-object-toobject) - [As String `.toString()`](#as-string-tostring) - [Query](#query) - - [Is Before `.isBefore(compared: Dayjs)`](#is-before-isbeforecompared-dayjs) - - [Is Same `.isSame(compared: Dayjs)`](#is-same-issamecompared-dayjs) - - [Is After `.isAfter(compared: Dayjs)`](#is-after-isaftercompared-dayjs) + - [Is Before `.isBefore(compared: Dayjs, unit?: string)`](#is-before-isbeforecompared-dayjs-unit-string) + - [Is Same `.isSame(compared: Dayjs, unit?: string)`](#is-same-issamecompared-dayjs-unit-string) + - [Is After `.isAfter(compared: Dayjs, unit?: string)`](#is-after-isaftercompared-dayjs-unit-string) - [Is a Dayjs `.isDayjs()`](#is-a-dayjs-isdayjscompared-any) - [Plugin APIs](#plugin-apis) - [RelativeTime](#relativetime) @@ -383,28 +383,31 @@ dayjs('2019-01-25').toString(); // 'Fri, 25 Jan 2019 02:00:00 GMT' ## Query -### Is Before `.isBefore(compared: Dayjs)` +### Is Before `.isBefore(compared: Dayjs, unit?: string)` Returns a `boolean` indicating whether the `Dayjs`'s date is before the other supplied `Dayjs`'s. ```js dayjs().isBefore(dayjs()); // false +dayjs().isBefore(dayjs(), 'year'); // false ``` -### Is Same `.isSame(compared: Dayjs)` +### Is Same `.isSame(compared: Dayjs, unit?: string)` Returns a `boolean` indicating whether the `Dayjs`'s date is the same as the other supplied `Dayjs`'s. ```js dayjs().isSame(dayjs()); // true +dayjs().isSame(dayjs(), 'year'); // true ``` -### Is After `.isAfter(compared: Dayjs)` +### Is After `.isAfter(compared: Dayjs, unit?: string)` Returns a `boolean` indicating whether the `Dayjs`'s date is after the other supplied `Dayjs`'s. ```js dayjs().isAfter(dayjs()); // false +dayjs().isAfter(dayjs(), 'year'); // false ``` ### Is a Dayjs `.isDayjs(compared: any)` From 30176656f01cca5f424b06f8351504e696399df0 Mon Sep 17 00:00:00 2001 From: iamkun Date: Wed, 12 Dec 2018 10:36:23 +0800 Subject: [PATCH 3/7] docs: update docs --- docs/es-es/API-reference.md | 15 +++++++++------ docs/ja/API-reference.md | 9 ++++++--- docs/ko/API-reference.md | 15 +++++++++------ docs/pt-br/API-reference.md | 17 ++++++++++------- docs/zh-cn/API-reference.md | 9 ++++++--- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/docs/es-es/API-reference.md b/docs/es-es/API-reference.md index 2fc5b0660..e7504ee62 100644 --- a/docs/es-es/API-reference.md +++ b/docs/es-es/API-reference.md @@ -43,9 +43,9 @@ El objeto `Dayjs` es inmutable, por lo que toda operación de la API que altere - [Como objeto `.toObject()`](#como-objecto-toobject) - [Como cadena `.toString()`](#como-cadena-tostring) - [Consulta](#consulta) - - [Anterior a `.isBefore(compared: Dayjs)`](#anterior-a-isbeforecompared-dayjs) - - [Igual que `.isSame(compared: Dayjs)`](#igual-que-issamecompared-dayjs) - - [Posterior a `.isAfter(compared: Dayjs)`](#posterior-a-isaftercompared-dayjs) + - [Anterior a `.isBefore(compared: Dayjs, unit?: string)`](#anterior-a-isbeforecompared-dayjs-unit-string) + - [Igual que `.isSame(compared: Dayjs, unit?: string)`](#igual-que-issamecompared-dayjs-unit-string) + - [Posterior a `.isAfter(compared: Dayjs, unit?: string)`](#posterior-a-isaftercompared-dayjs-unit-string) - [Es Dayjs `.isDayjs()`](#es-dayjs-isdayjscompared-any) - [API de complementos](#api-de-complementos) - [RelativeTime](#relativetime) @@ -383,28 +383,31 @@ dayjs('2019-01-25').toString(); // 'Fri, 25 Jan 2019 02:00:00 GMT' ## Consulta -### Anterior a `.isBefore(compared: Dayjs)` +### Anterior a `.isBefore(compared: Dayjs, unit?: string)` 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. ```js dayjs().isBefore(dayjs()); // false +dayjs().isBefore(dayjs(), 'year'); // false ``` -### Igual que `.isSame(compared: Dayjs)` +### Igual que `.isSame(compared: Dayjs, unit?: string)` 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. ```js dayjs().isSame(dayjs()); // true +dayjs().isSame(dayjs(), 'year'); // true ``` -### Posterior a `.isAfter(compared: Dayjs)` +### Posterior a `.isAfter(compared: Dayjs, unit?: string)` 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. ```js dayjs().isAfter(dayjs()); // false +dayjs().isAfter(dayjs(), 'year'); // false ``` ### Es Dayjs `.isDayjs(compared: any)` diff --git a/docs/ja/API-reference.md b/docs/ja/API-reference.md index a181b3750..d13bb6d16 100644 --- a/docs/ja/API-reference.md +++ b/docs/ja/API-reference.md @@ -451,8 +451,9 @@ dayjs().toString(); `Dayjs` オブジェクトが別の `Dayjs` オブジェクト以前の値かどうかを判定します。 ```js -dayjs().isBefore(Dayjs); +dayjs().isBefore(Dayjs, unit? : String); dayjs().isBefore(dayjs()); // false +dayjs().isBefore(dayjs(), 'year'); // false ``` #### Is Same @@ -462,8 +463,9 @@ dayjs().isBefore(dayjs()); // false `Dayjs` オブジェクトが別の `Dayjs` オブジェクトの値と等しいかどうかを判定します。 ```js -dayjs().isSame(Dayjs); +dayjs().isSame(Dayjs, unit? : String); dayjs().isSame(dayjs()); // true +dayjs().isSame(dayjs(), 'year'); // true ``` #### Is After @@ -473,8 +475,9 @@ dayjs().isSame(dayjs()); // true `Dayjs` オブジェクトが別の `Dayjs` オブジェクト以降の値かどうかを判定します。 ```js -dayjs().isAfter(Dayjs); +dayjs().isAfter(Dayjs, unit? : String); dayjs().isAfter(dayjs()); // false +dayjs().isAfter(dayjs(), 'year'); // false ``` ### Is a Dayjs `.isDayjs(compared: any)` diff --git a/docs/ko/API-reference.md b/docs/ko/API-reference.md index 99a5c7c7f..f97298b67 100644 --- a/docs/ko/API-reference.md +++ b/docs/ko/API-reference.md @@ -42,9 +42,9 @@ Day.js는 네이티브 `Date.prototype`을 수정하는 대신 `Dayjs` 오브젝 - [As Object `.toObject()`](#as-object-toobject) - [As String `.toString()`](#as-string-tostring) - [Query](#query) - - [Is Before `.isBefore(compared: Dayjs)`](#is-before-isbeforecompared--dayjs) - - [Is Same `.isSame(compared: Dayjs)`](#is-same-issamecompared--dayjs) - - [Is After `.isAfter(compared: Dayjs)`](#is-after-isaftercompared--dayjs) + - [Is Before `.isBefore(compared: Dayjs, unit?: string)`](#is-before-isbeforecompared--dayjs-unit-string) + - [Is Same `.isSame(compared: Dayjs, unit?: string)`](#is-same-issamecompared--dayjs-unit-string) + - [Is After `.isAfter(compared: Dayjs, unit?: string)`](#is-after-isaftercompared--dayjs-unit-string) - [Is a Dayjs `.isDayjs()`](#is-a-dayjs-isdayjscompared-any) - [Plugin APIs](#plugin-apis) - [RelativeTime](#relativetime) @@ -382,28 +382,31 @@ dayjs('2019-01-25').toString(); // 'Fri, 25 Jan 2019 02:00:00 GMT' ## Query -### Is Before `.isBefore(compared: Dayjs)` +### Is Before `.isBefore(compared: Dayjs, unit?: string)` `Dayjs`가 다른 `Dayjs`보다 앞선 시점인지를 확인합니다. 반환 타입은 `boolean` 입니다. ```js dayjs().isBefore(dayjs()); // false +dayjs().isBefore(dayjs(), 'year'); // false ``` -### Is Same `.isSame(compared: Dayjs)` +### Is Same `.isSame(compared: Dayjs, unit?: string)` `Dayjs`가 다른 `Dayjs`과 동일한 시점인지를 확인합니다. 반환 타입은 `boolean` 입니다. ```js dayjs().isSame(dayjs()); // true +dayjs().isSame(dayjs(), 'year'); // true ``` -### Is After `.isAfter(compared: Dayjs)` +### Is After `.isAfter(compared: Dayjs, unit?: string)` `Dayjs`가 다른 `Dayjs`보다 뒷선 시점인지를 확인합니다. 반환 타입은 `boolean` 입니다. ```js dayjs().isAfter(dayjs()); // false +dayjs().isAfter(dayjs(), 'year'); // false ``` ### Is a Dayjs `.isDayjs(compared: any)` diff --git a/docs/pt-br/API-reference.md b/docs/pt-br/API-reference.md index 60414ae5e..ee21167dc 100644 --- a/docs/pt-br/API-reference.md +++ b/docs/pt-br/API-reference.md @@ -43,9 +43,9 @@ O objeto `Dayjs` é imutável, ou seja, todas as operações da API que alteram - [Como Objeto `.toObject()`](#como-objeto-toobject) - [Como String `.toString()`](#como-string-tostring) - [Consulta](#consulta) - - [Antes `.isBefore(compared: Dayjs)`](#antes-isbeforecompared-dayjs) - - [Igual `.isSame(compared: Dayjs)`](#igual-issamecompared-dayjs) - - [Depois `.isAfter(compared: Dayjs)`](#depois-isaftercompared-dayjs) + - [Antes `.isBefore(compared: Dayjs, unit?: string)`](#antes-isbeforecompared-dayjs-unit-string) + - [Igual `.isSame(compared: Dayjs, unit?: string)`](#igual-issamecompared-dayjs-unit-string) + - [Depois `.isAfter(compared: Dayjs, unit?: string)`](#depois-isaftercompared-dayjs-unit-string) - [É um objeto `Dayjs` `.isDayjs()`](#é-um-objeto-dayjs-isdayjs) - [Plugin APIs](#plugin-apis) - [RelativeTime](#relativetime) @@ -381,28 +381,31 @@ dayjs('2019-01-25').toString(); // 'Fri, 25 Jan 2019 02:00:00 GMT' ## Consulta -### Antes `.isBefore(compared: Dayjs)` +### Antes `.isBefore(compared: Dayjs, unit?: string)`] Retorna um `boolean` indicando se a data do objeto `Dayjs` é antes da data fornecida de em outro objeto `Dayjs`. ```js dayjs().isBefore(dayjs()); // false +dayjs().isBefore(dayjs(), 'year'); // false ``` -### Igual `.isSame(compared: Dayjs)` +### Igual `.isSame(compared: Dayjs, unit?: string)`] Retorna um `boolean` indicando se a data do objeto `Dayjs` é a mesma data fornecida de em outro objeto `Dayjs`. ```js -dayjs().isBefore(dayjs()); // false +dayjs().isSame(dayjs()); // true +dayjs().isSame(dayjs(), 'year'); // true ``` -### Depois `.isAfter(compared: Dayjs)` +### Depois `.isAfter(compared: Dayjs, unit?: string)`] Retorna um `boolean` indicando se a data do objeto `Dayjs` é depois da data fornecida de em outro objeto `Dayjs`. ```js dayjs().isAfter(dayjs()); // false +dayjs().isAfter(dayjs(), 'year'); // false ``` ### É um objeto `Dayjs` `.isDayjs()` diff --git a/docs/zh-cn/API-reference.md b/docs/zh-cn/API-reference.md index b590055a9..59e883ca1 100644 --- a/docs/zh-cn/API-reference.md +++ b/docs/zh-cn/API-reference.md @@ -338,24 +338,27 @@ dayjs().toString(); 检查一个 `Dayjs` 对象是否在另一个 `Dayjs` 对象时间之前。 ```js -dayjs().isBefore(Dayjs); +dayjs().isBefore(Dayjs, unit? : String); dayjs().isBefore(dayjs()); // false +dayjs().isBefore(dayjs(), 'year'); // false ``` #### 是否相同 - return Boolean 检查一个 `Dayjs` 对象是否和另一个 `Dayjs` 对象时间相同。 ```js -dayjs().isSame(Dayjs); +dayjs().isSame(Dayjs, unit? : String); dayjs().isSame(dayjs()); // true +dayjs().isSame(dayjs(), 'year'); // true ``` #### 是否之后 - return Boolean 检查一个 `Dayjs` 对象是否在另一个 `Dayjs` 对象时间之后。 ```js -dayjs().isAfter(Dayjs); +dayjs().isAfter(Dayjs, unit? : String); dayjs().isAfter(dayjs()); // false +dayjs().isAfter(dayjs(), 'year'); // false ``` ### 是否是 Dayjs `.isDayjs(compared: any)` From d8fae844758111b1620a62727bdce17208a976c8 Mon Sep 17 00:00:00 2001 From: iamkun Date: Thu, 13 Dec 2018 22:15:02 +0800 Subject: [PATCH 4/7] docs: update plugin docs --- docs/en/Plugin.md | 24 +++++++++++++++++++++++- docs/es-es/Plugin.md | 24 +++++++++++++++++++++++- docs/ja/Plugin.md | 23 ++++++++++++++++++++++- docs/ko/Plugin.md | 24 +++++++++++++++++++++++- docs/pt-br/Plugin.md | 24 +++++++++++++++++++++++- docs/zh-cn/Plugin.md | 24 +++++++++++++++++++++++- 6 files changed, 137 insertions(+), 6 deletions(-) diff --git a/docs/en/Plugin.md b/docs/en/Plugin.md index 2660013f7..ffbf86c21 100644 --- a/docs/en/Plugin.md +++ b/docs/en/Plugin.md @@ -155,6 +155,28 @@ dayjs.extend(weekOfYear) dayjs('06/27/2018').week() // 26 ``` +### IsSameOrAfter + - IsSameOrAfter adds `.isSameOrAfter()` API to returns a `boolean` indicating if a date is same of after another date. + +```javascript +import isSameOrAfter from 'dayjs/plugin/isSameOrAfter' + +dayjs.extend(isSameOrAfter) + +dayjs('2010-10-20').isSameOrAfter('2010-10-19', 'year'); +``` + +### IsSameOrBefore + - IsSameOrBefore adds `.isSameOrBefore()` API to returns a `boolean` indicating if a date is same of before another date. + +```javascript +import isSameOrBefore from 'dayjs/plugin/isSameOrBefore' + +dayjs.extend(isSameOrBefore) + +dayjs('2010-10-20').isSameOrBefore('2010-10-19', 'year'); +``` + ### IsBetween - IsBetween adds `.isBetween()` API to returns a `boolean` indicating if a date is between two other dates. @@ -163,7 +185,7 @@ import isBetween from 'dayjs/plugin/isBetween' dayjs.extend(isBetween) -dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25')); // true +dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25'), 'year'); ``` ## Customize diff --git a/docs/es-es/Plugin.md b/docs/es-es/Plugin.md index f5e702932..bf492b342 100644 --- a/docs/es-es/Plugin.md +++ b/docs/es-es/Plugin.md @@ -161,6 +161,28 @@ dayjs.extend(weekOfYear) dayjs('06/27/2018').week() // 26 ``` +### IsSameOrAfter + - IsSameOrAfter adds `.isSameOrAfter()` API to returns a `boolean` indicating if a date is same of after another date. + +```javascript +import isSameOrAfter from 'dayjs/plugin/isSameOrAfter' + +dayjs.extend(isSameOrAfter) + +dayjs('2010-10-20').isSameOrAfter('2010-10-19', 'year'); +``` + +### IsSameOrBefore + - IsSameOrBefore adds `.isSameOrBefore()` API to returns a `boolean` indicating if a date is same of before another date. + +```javascript +import isSameOrBefore from 'dayjs/plugin/isSameOrBefore' + +dayjs.extend(isSameOrBefore) + +dayjs('2010-10-20').isSameOrBefore('2010-10-19', 'year'); +``` + ### IsBetween * 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' dayjs.extend(isBetween) -dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25')); // true +dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25'), 'year'); ``` ## Personalización diff --git a/docs/ja/Plugin.md b/docs/ja/Plugin.md index a1886bb7d..319960384 100644 --- a/docs/ja/Plugin.md +++ b/docs/ja/Plugin.md @@ -155,6 +155,27 @@ dayjs.extend(weekOfYear) dayjs('06/27/2018').week() // 26 ``` +### IsSameOrAfter + - IsSameOrAfter adds `.isSameOrAfter()` API to returns a `boolean` indicating if a date is same of after another date. + +```javascript +import isSameOrAfter from 'dayjs/plugin/isSameOrAfter' + +dayjs.extend(isSameOrAfter) + +dayjs('2010-10-20').isSameOrAfter('2010-10-19', 'year'); +``` + +### IsSameOrBefore + - IsSameOrBefore adds `.isSameOrBefore()` API to returns a `boolean` indicating if a date is same of before another date. + +```javascript +import isSameOrBefore from 'dayjs/plugin/isSameOrBefore' + +dayjs.extend(isSameOrBefore) + +dayjs('2010-10-20').isSameOrBefore('2010-10-19', 'year'); +``` ### IsBetween - 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' dayjs.extend(isBetween) -dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25')); // true +dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25'), 'year'); ``` ## カスタマイズ diff --git a/docs/ko/Plugin.md b/docs/ko/Plugin.md index 8a2c3206f..195097760 100644 --- a/docs/ko/Plugin.md +++ b/docs/ko/Plugin.md @@ -155,6 +155,28 @@ dayjs.extend(weekOfYear) dayjs('06/27/2018').week() // 26 ``` +### IsSameOrAfter + - IsSameOrAfter adds `.isSameOrAfter()` API to returns a `boolean` indicating if a date is same of after another date. + +```javascript +import isSameOrAfter from 'dayjs/plugin/isSameOrAfter' + +dayjs.extend(isSameOrAfter) + +dayjs('2010-10-20').isSameOrAfter('2010-10-19', 'year'); +``` + +### IsSameOrBefore + - IsSameOrBefore adds `.isSameOrBefore()` API to returns a `boolean` indicating if a date is same of before another date. + +```javascript +import isSameOrBefore from 'dayjs/plugin/isSameOrBefore' + +dayjs.extend(isSameOrBefore) + +dayjs('2010-10-20').isSameOrBefore('2010-10-19', 'year'); +``` + ### IsBetween - IsBetween adds `.isBetween()` API to returns a `boolean` indicating if a date is between two other dates. @@ -163,7 +185,7 @@ import isBetween from 'dayjs/plugin/isBetween' dayjs.extend(isBetween) -dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25')); // true +dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25'), 'year'); ``` ## Customize diff --git a/docs/pt-br/Plugin.md b/docs/pt-br/Plugin.md index e67e1bb04..17a11721e 100644 --- a/docs/pt-br/Plugin.md +++ b/docs/pt-br/Plugin.md @@ -155,6 +155,28 @@ dayjs.extend(weekOfYear) dayjs('06/27/2018').week() // 26 ``` +### IsSameOrAfter + - IsSameOrAfter adds `.isSameOrAfter()` API to returns a `boolean` indicating if a date is same of after another date. + +```javascript +import isSameOrAfter from 'dayjs/plugin/isSameOrAfter' + +dayjs.extend(isSameOrAfter) + +dayjs('2010-10-20').isSameOrAfter('2010-10-19', 'year'); +``` + +### IsSameOrBefore + - IsSameOrBefore adds `.isSameOrBefore()` API to returns a `boolean` indicating if a date is same of before another date. + +```javascript +import isSameOrBefore from 'dayjs/plugin/isSameOrBefore' + +dayjs.extend(isSameOrBefore) + +dayjs('2010-10-20').isSameOrBefore('2010-10-19', 'year'); +``` + ### IsBetween - IsBetween adiciona `.isBetween()` à API para retornar um `boolean` indicando se a data está entre outras duas datas. @@ -163,7 +185,7 @@ import isBetween from 'dayjs/plugin/isBetween' dayjs.extend(isBetween) -dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25')); // true +dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25'), 'year'); ``` ## Customizar diff --git a/docs/zh-cn/Plugin.md b/docs/zh-cn/Plugin.md index 5d88c44b6..cf209dd66 100644 --- a/docs/zh-cn/Plugin.md +++ b/docs/zh-cn/Plugin.md @@ -155,6 +155,28 @@ dayjs.extend(weekOfYear) dayjs('06/27/2018').week() // 26 ``` +### IsSameOrAfter + - IsSameOrAfter 增加了 `.isSameOrAfter()` API 返回一个 `boolean` 来展示一个时间是否和一个时间相同或在一个时间之后. + +```javascript +import isSameOrAfter from 'dayjs/plugin/isSameOrAfter' + +dayjs.extend(isSameOrAfter) + +dayjs('2010-10-20').isSameOrAfter('2010-10-19', 'year'); +``` + +### IsSameOrBefore + - IsSameOrBefore 增加了 `.isSameOrBefore()` API 返回一个 `boolean` 来展示一个时间是否和一个时间相同或在一个时间之前. + +```javascript +import isSameOrBefore from 'dayjs/plugin/isSameOrBefore' + +dayjs.extend(isSameOrBefore) + +dayjs('2010-10-20').isSameOrBefore('2010-10-19', 'year'); +``` + ### IsBetween - IsBetween 增加了 `.isBetween()` API 返回一个 `boolean` 来展示一个时间是否介于两个时间之间. @@ -163,7 +185,7 @@ import isBetween from 'dayjs/plugin/isBetween' dayjs.extend(isBetween) -dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25')); // true +dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25'), 'year'); ``` ## 自定义 From 275aa06a7a7618927c9813ad2cd17422eba8b8ca Mon Sep 17 00:00:00 2001 From: iamkun Date: Thu, 13 Dec 2018 22:22:39 +0800 Subject: [PATCH 5/7] docs: add toc --- docs/en/API-reference.md | 14 ++++++++++++++ docs/es-es/API-reference.md | 14 ++++++++++++++ docs/ja/API-reference.md | 14 ++++++++++++++ docs/ko/API-reference.md | 14 ++++++++++++++ docs/pt-br/API-reference.md | 14 ++++++++++++++ docs/zh-cn/API-reference.md | 14 ++++++++++++++ docs/zh-cn/Plugin.md | 2 +- 7 files changed, 85 insertions(+), 1 deletion(-) diff --git a/docs/en/API-reference.md b/docs/en/API-reference.md index b5d4e7502..1bcb3a625 100644 --- a/docs/en/API-reference.md +++ b/docs/en/API-reference.md @@ -51,6 +51,8 @@ The `Dayjs` object is immutable, that is, all API operations that change the `Da - [RelativeTime](#relativetime) - [IsLeapYear](#isleapyear) - [WeekOfYear](#weekofyear) + - [IsSameOrAfter](#issameorafter) + - [IsSameOrBefore](#issameorbefore) - [IsBetween](#isbetween) ## Parsing @@ -439,6 +441,18 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear) plugin [`WeekOfYear`](./Plugin.md#weekofyear) +### IsSameOrAfter + +`.isSameOrAfter` to check if a date is same of after another date + +plugin [`IsSameOrAfter`](./Plugin.md#issameorafter) + +### IsSameOrBefore + +`.isSameOrBefore` to check if a date is same of before another date. + +plugin [`IsSameOrBefore`](./Plugin.md#issameorbefore) + ### IsBetween `.isBetween` to check if a date is between two other dates diff --git a/docs/es-es/API-reference.md b/docs/es-es/API-reference.md index e7504ee62..2926c0df3 100644 --- a/docs/es-es/API-reference.md +++ b/docs/es-es/API-reference.md @@ -51,6 +51,8 @@ El objeto `Dayjs` es inmutable, por lo que toda operación de la API que altere - [RelativeTime](#relativetime) - [IsLeapYear](#isleapyear) - [WeekOfYear](#weekofyear) + - [IsSameOrAfter](#issameorafter) + - [IsSameOrBefore](#issameorbefore) - [IsBetween](#isbetween) ## Análisis @@ -439,6 +441,18 @@ complemento [`IsLeapYear`](./Plugin.md#isleapyear) complemento [`WeekOfYear`](./Plugin.md#weekofyear) +### IsSameOrAfter + +`.isSameOrAfter` to check if a date is same of after another date + +plugin [`IsSameOrAfter`](./Plugin.md#issameorafter) + +### IsSameOrBefore + +`.isSameOrBefore` to check if a date is same of before another date. + +plugin [`IsSameOrBefore`](./Plugin.md#issameorbefore) + ### IsBetween `.isBetween` para comprobar si una fecha se encuentra entre otras dos fechas dadas diff --git a/docs/ja/API-reference.md b/docs/ja/API-reference.md index d13bb6d16..f35be32b7 100644 --- a/docs/ja/API-reference.md +++ b/docs/ja/API-reference.md @@ -48,6 +48,8 @@ Day.js は組み込みの `Date.prototype` を変更する代わりに `Dayjs` * [RelativeTime](#relativetime) * [IsLeapYear](#isleapyear) * [WeekOfYear](#weekofyear) + * [IsSameOrAfter](#issameorafter) + * [IsSameOrBefore](#issameorbefore) * [IsBetween](#isbetween) --- @@ -509,6 +511,18 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear) plugin [`WeekOfYear`](./Plugin.md#weekofyear) +### IsSameOrAfter + +`.isSameOrAfter` to check if a date is same of after another date + +plugin [`IsSameOrAfter`](./Plugin.md#issameorafter) + +### IsSameOrBefore + +`.isSameOrBefore` to check if a date is same of before another date. + +plugin [`IsSameOrBefore`](./Plugin.md#issameorbefore) + ### IsBetween `.isBetween` to check if a date is between two other dates diff --git a/docs/ko/API-reference.md b/docs/ko/API-reference.md index f97298b67..3f7d82529 100644 --- a/docs/ko/API-reference.md +++ b/docs/ko/API-reference.md @@ -50,6 +50,8 @@ Day.js는 네이티브 `Date.prototype`을 수정하는 대신 `Dayjs` 오브젝 - [RelativeTime](#relativetime) - [IsLeapYear](#isleapyear) - [WeekOfYear](#weekofyear) + - [IsSameOrAfter](#issameorafter) + - [IsSameOrBefore](#issameorbefore) - [IsBetween](#isbetween) ## Parsing @@ -438,6 +440,18 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear) plugin [`WeekOfYear`](./Plugin.md#weekofyear) +### IsSameOrAfter + +`.isSameOrAfter` to check if a date is same of after another date + +plugin [`IsSameOrAfter`](./Plugin.md#issameorafter) + +### IsSameOrBefore + +`.isSameOrBefore` to check if a date is same of before another date. + +plugin [`IsSameOrBefore`](./Plugin.md#issameorbefore) + ### IsBetween `.isBetween` to check if a date is between two other dates diff --git a/docs/pt-br/API-reference.md b/docs/pt-br/API-reference.md index ee21167dc..b2f594fde 100644 --- a/docs/pt-br/API-reference.md +++ b/docs/pt-br/API-reference.md @@ -51,6 +51,8 @@ O objeto `Dayjs` é imutável, ou seja, todas as operações da API que alteram - [RelativeTime](#relativetime) - [IsLeapYear](#isleapyear) - [WeekOfYear](#weekofyear) + - [IsSameOrAfter](#issameorafter) + - [IsSameOrBefore](#issameorbefore) - [IsBetween](#isbetween) ## Conversões @@ -437,6 +439,18 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear) plugin [`WeekOfYear`](./Plugin.md#weekofyear) +### IsSameOrAfter + +`.isSameOrAfter` to check if a date is same of after another date + +plugin [`IsSameOrAfter`](./Plugin.md#issameorafter) + +### IsSameOrBefore + +`.isSameOrBefore` to check if a date is same of before another date. + +plugin [`IsSameOrBefore`](./Plugin.md#issameorbefore) + ### IsBetween `.isBetween` para verificar se uma data está entre duas outras datas diff --git a/docs/zh-cn/API-reference.md b/docs/zh-cn/API-reference.md index 59e883ca1..bf9138ada 100644 --- a/docs/zh-cn/API-reference.md +++ b/docs/zh-cn/API-reference.md @@ -48,6 +48,8 @@ * [相对时间](#relativetime) * [是否是闰年](#是否是闰年) * [年中的第几周](#年中的第几周) + * [IsSameOrAfter](#issameorafter) + * [IsSameOrBefore](#issameorbefore) * [是否之间](#isbetween) --- @@ -390,6 +392,18 @@ dayjs.isDayjs(new Date()); // false 插件 [`WeekOfYear`](./Plugin.md#weekofyear) +### 是否相同或之后 + +`.isSameOrAfter` 返回一个时间和一个时间相同或在一个时间之后 + +plugin [`IsSameOrAfter`](./Plugin.md#issameorafter) + +### 是否相同或之前 + +`.isSameOrBefore` 返回一个时间是否和一个时间相同或在一个时间之前 + +plugin [`IsSameOrBefore`](./Plugin.md#issameorbefore) + ### 是否之间 `.isBetween` 返回一个时间是否介于两个时间之间 diff --git a/docs/zh-cn/Plugin.md b/docs/zh-cn/Plugin.md index cf209dd66..082dd6562 100644 --- a/docs/zh-cn/Plugin.md +++ b/docs/zh-cn/Plugin.md @@ -144,7 +144,7 @@ List of added formats: | `BBBB` | 2561 | Full BE Year (Year + 543) | | `BB` | 61 | 2-digit of BE Year | -### 年中的第几周 +### WeekOfYear - WeekOfYear 增加了 `.week()` API 返回一个 `number` 来表示 `Dayjs` 的日期是年中第几周. ```javascript From 6c78b046208eba9dc07d058eee5e283abe3ea900 Mon Sep 17 00:00:00 2001 From: iamkun Date: Thu, 13 Dec 2018 22:33:36 +0800 Subject: [PATCH 6/7] test: rm useless test --- test/query.test.js | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/test/query.test.js b/test/query.test.js index 09f99b7f8..2c05ec96d 100644 --- a/test/query.test.js +++ b/test/query.test.js @@ -1,4 +1,3 @@ -import moment from 'moment' import MockDate from 'mockdate' import dayjs from '../src' @@ -10,40 +9,33 @@ afterEach(() => { MockDate.reset() }) -const testArr = [dayjs, moment] describe('Is Before Is After Is Same', () => { it('Compare to dayjs object', () => { - testArr.forEach((instance) => { - const dayA = instance() - const dayB = dayA.clone().add(1, 'day') - const dayC = dayA.clone().subtract(1, 'day') - expect(dayC.isBefore(dayA)).toBe(true) - expect(dayA.isSame(instance())).toBe(true) - expect(dayB.isAfter(dayA)).toBe(true) - expect(dayA.isSame()).toBe(true) - expect(dayB.isAfter()).toBe(true) - expect(dayC.isBefore()).toBe(true) - }) + const dayA = dayjs() + const dayB = dayA.clone().add(1, 'day') + const dayC = dayA.clone().subtract(1, 'day') + expect(dayC.isBefore(dayA)).toBe(true) + expect(dayA.isSame(dayjs())).toBe(true) + expect(dayB.isAfter(dayA)).toBe(true) + expect(dayA.isSame()).toBe(true) + expect(dayB.isAfter()).toBe(true) + expect(dayC.isBefore()).toBe(true) }) it('No value', () => { - testArr.forEach((instance) => { - const dayA = instance() - const dayB = dayA.clone().add(1, 'day') - const dayC = dayA.clone().subtract(1, 'day') - expect(dayA.isSame()).toBe(true) - expect(dayB.isAfter()).toBe(true) - expect(dayC.isBefore()).toBe(true) - }) + const dayA = dayjs() + const dayB = dayA.clone().add(1, 'day') + const dayC = dayA.clone().subtract(1, 'day') + expect(dayA.isSame()).toBe(true) + expect(dayB.isAfter()).toBe(true) + expect(dayC.isBefore()).toBe(true) }) it('With string', () => { - testArr.forEach((instance) => { - const dayD = instance() - expect(dayD.isSame('20180101')).toBe(false) - expect(dayD.isAfter('20180101')).toBe(true) - expect(dayD.isBefore('20180101')).toBe(false) - }) + const dayD = dayjs() + expect(dayD.isSame('20180101')).toBe(false) + expect(dayD.isAfter('20180101')).toBe(true) + expect(dayD.isBefore('20180101')).toBe(false) }) }) From 14dd81cac2e6d039c85d70c6d77bf132f0fea6ef Mon Sep 17 00:00:00 2001 From: iamkun Date: Thu, 13 Dec 2018 22:38:46 +0800 Subject: [PATCH 7/7] docs: fix doc error --- docs/zh-cn/API-reference.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/zh-cn/API-reference.md b/docs/zh-cn/API-reference.md index bf9138ada..93100de5e 100644 --- a/docs/zh-cn/API-reference.md +++ b/docs/zh-cn/API-reference.md @@ -48,9 +48,9 @@ * [相对时间](#relativetime) * [是否是闰年](#是否是闰年) * [年中的第几周](#年中的第几周) - * [IsSameOrAfter](#issameorafter) - * [IsSameOrBefore](#issameorbefore) - * [是否之间](#isbetween) + * [是否相同或之后](#是否相同或之后) + * [是否相同或之前](#是否相同或之前) + * [是否之间](#是否之间) --- 如果没有特别说明,Day.js 的返回值都是新的 `Dayjs` 对象。