diff --git a/docs/en/API-reference.md b/docs/en/API-reference.md index a95bfe18f..1035b8773 100644 --- a/docs/en/API-reference.md +++ b/docs/en/API-reference.md @@ -492,3 +492,9 @@ plugin [`ToObject`](./Plugin.md#toobject) `.min` `.max` to compare given dayjs instances plugin [`MinMax`](./Plugin.md#minmax) + +### Calendar + +`.calendar` to display calendar time + +plugin [`Calendar`](./Plugin.md#calendar) diff --git a/docs/en/Plugin.md b/docs/en/Plugin.md index 3df237257..5fc968750 100644 --- a/docs/en/Plugin.md +++ b/docs/en/Plugin.md @@ -401,6 +401,26 @@ dayjs.max(dayjs(), dayjs('2018-01-01'), dayjs('2019-01-01')) dayjs.min([dayjs(), dayjs('2018-01-01'), dayjs('2019-01-01')]) ``` +### Calendar + +- Calendar adds `.calendar` API to return a `string` to display calendar time + +```javascript +import calendar from 'dayjs/plugin/calendar' + +dayjs.extend(calendar) + +dayjs().calendar(dayjs('2008-01-01')) +dayjs().calendar(null, { + sameDay: '[Today at] h:mm A', // The same day ( Today at 2:30 AM ) + nextDay: '[Tomorrow]', // The next day ( Tomorrow at 2:30 AM ) + nextWeek: 'dddd', // The next week ( Sunday at 2:30 AM ) + lastDay: '[Yesterday]', // The day before ( Yesterday at 2:30 AM ) + lastWeek: '[Last] dddd', // Last week ( Last Monday at 2:30 AM ) + sameElse: 'DD/MM/YYYY' // Everything else ( 7/10/2011 ) +}) +``` + ## Customize You could build your own Day.js plugin to meet different needs. diff --git a/docs/es-es/API-reference.md b/docs/es-es/API-reference.md index 8d3b1a31e..cde19d343 100644 --- a/docs/es-es/API-reference.md +++ b/docs/es-es/API-reference.md @@ -492,3 +492,9 @@ plugin [`ToObject`](./Plugin.md#toobject) `.min` `.max` to compare given dayjs instances. plugin [`MinMax`](./Plugin.md#minmax) + +### Calendar + +`.calendar` to display calendar time + +plugin [`Calendar`](./Plugin.md#calendar) diff --git a/docs/es-es/Plugin.md b/docs/es-es/Plugin.md index 279c5c85c..1b5362afd 100644 --- a/docs/es-es/Plugin.md +++ b/docs/es-es/Plugin.md @@ -401,6 +401,26 @@ dayjs.max(dayjs(), dayjs('2018-01-01'), dayjs('2019-01-01')) dayjs.min([dayjs(), dayjs('2018-01-01'), dayjs('2019-01-01')]) ``` +### Calendar + +- Calendar adds `.calendar` API to return a `string` to display calendar time + +```javascript +import calendar from 'dayjs/plugin/calendar' + +dayjs.extend(calendar) + +dayjs().calendar(dayjs('2008-01-01')) +dayjs().calendar(null, { + sameDay: '[Today at] h:mm A', // The same day ( Today at 2:30 AM ) + nextDay: '[Tomorrow]', // The next day ( Tomorrow at 2:30 AM ) + nextWeek: 'dddd', // The next week ( Sunday at 2:30 AM ) + lastDay: '[Yesterday]', // The day before ( Yesterday at 2:30 AM ) + lastWeek: '[Last] dddd', // Last week ( Last Monday at 2:30 AM ) + sameElse: 'DD/MM/YYYY' // Everything else ( 7/10/2011 ) +}) +``` + ## Personalización Puedes construir tu propio complemento de Day.js para cubrir tus necesidades. diff --git a/docs/ja/API-reference.md b/docs/ja/API-reference.md index 37fbcf409..d703fe3cc 100644 --- a/docs/ja/API-reference.md +++ b/docs/ja/API-reference.md @@ -548,3 +548,9 @@ plugin [`ToObject`](./Plugin.md#toobject) `.min` `.max` to compare given dayjs instances. plugin [`MinMax`](./Plugin.md#minmax) + +### Calendar + +`.calendar` to display calendar time + +plugin [`Calendar`](./Plugin.md#calendar) diff --git a/docs/ja/Plugin.md b/docs/ja/Plugin.md index d29c57f63..2daa02cb0 100644 --- a/docs/ja/Plugin.md +++ b/docs/ja/Plugin.md @@ -410,6 +410,26 @@ dayjs.max(dayjs(), dayjs('2018-01-01'), dayjs('2019-01-01')) dayjs.min([dayjs(), dayjs('2018-01-01'), dayjs('2019-01-01')]) ``` +### Calendar + +- Calendar adds `.calendar` API to return a `string` to display calendar time + +```javascript +import calendar from 'dayjs/plugin/calendar' + +dayjs.extend(calendar) + +dayjs().calendar(dayjs('2008-01-01')) +dayjs().calendar(null, { + sameDay: '[Today at] h:mm A', // The same day ( Today at 2:30 AM ) + nextDay: '[Tomorrow]', // The next day ( Tomorrow at 2:30 AM ) + nextWeek: 'dddd', // The next week ( Sunday at 2:30 AM ) + lastDay: '[Yesterday]', // The day before ( Yesterday at 2:30 AM ) + lastWeek: '[Last] dddd', // Last week ( Last Monday at 2:30 AM ) + sameElse: 'DD/MM/YYYY' // Everything else ( 7/10/2011 ) +}) +``` + ## カスタマイズ さまざまなニーズに合わせて独自の Day.js プラグインを構築することができます。 diff --git a/docs/ko/API-reference.md b/docs/ko/API-reference.md index a5f40ef0a..10be81e2e 100644 --- a/docs/ko/API-reference.md +++ b/docs/ko/API-reference.md @@ -491,3 +491,9 @@ plugin [`ToObject`](./Plugin.md#toobject) `.min` `.max` to compare given dayjs instances. plugin [`MinMax`](./Plugin.md#minmax) + +### Calendar + +`.calendar` to display calendar time + +plugin [`Calendar`](./Plugin.md#calendar) diff --git a/docs/ko/Plugin.md b/docs/ko/Plugin.md index 91a705870..25c706221 100644 --- a/docs/ko/Plugin.md +++ b/docs/ko/Plugin.md @@ -402,6 +402,26 @@ dayjs.max(dayjs(), dayjs('2018-01-01'), dayjs('2019-01-01')) dayjs.min([dayjs(), dayjs('2018-01-01'), dayjs('2019-01-01')]) ``` +### Calendar + +- Calendar adds `.calendar` API to return a `string` to display calendar time + +```javascript +import calendar from 'dayjs/plugin/calendar' + +dayjs.extend(calendar) + +dayjs().calendar(dayjs('2008-01-01')) +dayjs().calendar(null, { + sameDay: '[Today at] h:mm A', // The same day ( Today at 2:30 AM ) + nextDay: '[Tomorrow]', // The next day ( Tomorrow at 2:30 AM ) + nextWeek: 'dddd', // The next week ( Sunday at 2:30 AM ) + lastDay: '[Yesterday]', // The day before ( Yesterday at 2:30 AM ) + lastWeek: '[Last] dddd', // Last week ( Last Monday at 2:30 AM ) + sameElse: 'DD/MM/YYYY' // Everything else ( 7/10/2011 ) +}) +``` + ## Customize 다양한 요구를 충족하기위해 자신만의 Day.js 플러그인을 만들 수 있습니다. diff --git a/docs/pt-br/API-reference.md b/docs/pt-br/API-reference.md index d14c7958d..5a7009ef5 100644 --- a/docs/pt-br/API-reference.md +++ b/docs/pt-br/API-reference.md @@ -490,3 +490,9 @@ plugin [`ToObject`](./Plugin.md#toobject) `.min` `.max` to compare given dayjs instances. plugin [`MinMax`](./Plugin.md#minmax) + +### Calendar + +`.calendar` to display calendar time + +plugin [`Calendar`](./Plugin.md#calendar) diff --git a/docs/pt-br/Plugin.md b/docs/pt-br/Plugin.md index dfcb55499..676cff560 100644 --- a/docs/pt-br/Plugin.md +++ b/docs/pt-br/Plugin.md @@ -401,6 +401,26 @@ dayjs.max(dayjs(), dayjs('2018-01-01'), dayjs('2019-01-01')) dayjs.min([dayjs(), dayjs('2018-01-01'), dayjs('2019-01-01')]) ``` +### Calendar + +- Calendar adds `.calendar` API to return a `string` to display calendar time + +```javascript +import calendar from 'dayjs/plugin/calendar' + +dayjs.extend(calendar) + +dayjs().calendar(dayjs('2008-01-01')) +dayjs().calendar(null, { + sameDay: '[Today at] h:mm A', // The same day ( Today at 2:30 AM ) + nextDay: '[Tomorrow]', // The next day ( Tomorrow at 2:30 AM ) + nextWeek: 'dddd', // The next week ( Sunday at 2:30 AM ) + lastDay: '[Yesterday]', // The day before ( Yesterday at 2:30 AM ) + lastWeek: '[Last] dddd', // Last week ( Last Monday at 2:30 AM ) + sameElse: 'DD/MM/YYYY' // Everything else ( 7/10/2011 ) +}) +``` + ## Customizar Você também pode construir seu próprio plugin Day.js para diferentes necessidades. diff --git a/docs/zh-cn/API-reference.md b/docs/zh-cn/API-reference.md index 75c7a3d0a..4c0c4e5fd 100644 --- a/docs/zh-cn/API-reference.md +++ b/docs/zh-cn/API-reference.md @@ -543,3 +543,9 @@ plugin [`IsoWeeksInYear`](./Plugin.md#isoweeksinyear) `.min` `.max` 比较传入的 dayjs 实例的大小 plugin [`MinMax`](./Plugin.md#minmax) + +### 日历时间 + +`.calendar` 来显示日历时间 + +plugin [`Calendar`](./Plugin.md#calendar) diff --git a/docs/zh-cn/Plugin.md b/docs/zh-cn/Plugin.md index 49b0a65ab..89caccc6b 100644 --- a/docs/zh-cn/Plugin.md +++ b/docs/zh-cn/Plugin.md @@ -389,7 +389,7 @@ dayjs('2019-01-25').toObject() ### MinMax -- MinMax 增加了 `.min` `.max` API 返回一个 `dayjs` 来比较传入的 dayjs 实例的大小. +- MinMax 增加了 `.min` `.max` API 返回一个 `dayjs` 来比较传入的 dayjs 实例的大小。 ```javascript import minMax from 'dayjs/plugin/minMax' @@ -400,6 +400,26 @@ dayjs.max(dayjs(), dayjs('2018-01-01'), dayjs('2019-01-01')) dayjs.min([dayjs(), dayjs('2018-01-01'), dayjs('2019-01-01')]) ``` +### Calendar + +- Calendar 增加了 `.calendar` API 返回一个 `string` 来显示日历时间。 + +```javascript +import calendar from 'dayjs/plugin/calendar' + +dayjs.extend(calendar) + +dayjs().calendar(dayjs('2008-01-01')) +dayjs().calendar(null, { + sameDay: '[今天] HH:mm', // 今天 ( 今天 2:30 AM ) + nextDay: '[明天]', // 明天 ( 明天 2:30 AM ) + nextWeek: '[下]dddd', // 下周 ( Sunday at 2:30 AM ) + lastDay: '[昨天]', // 昨天 ( 昨天 2:30 AM ) + lastWeek: '[上] dddd', // 上周 ( Last Monday at 2:30 AM ) + sameElse: 'DD/MM/YYYY' // 其他情况 ( 7/10/2011 ) +}) +``` + ## 自定义 你可以根据需要自由的编写一个 Day.js 插件 diff --git a/src/index.js b/src/index.js index 780ad3ba1..d0213dedb 100644 --- a/src/index.js +++ b/src/index.js @@ -219,6 +219,7 @@ class Dayjs { const arg = unit === C.D ? this.$D + (int - this.$W) : int if (unit === C.M || unit === C.Y) { + // clone is for badMutable plugin const date = this.clone().set(C.DATE, 1) date.$d[name](arg) date.init()