From 2912f475a7d5013c14c199e62185af711f9bf39c Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Thu, 11 Jul 2024 08:11:22 +0800 Subject: [PATCH 01/18] chore: update chinese locale --- src/locale/es.js | 1 - src/locale/id.js | 1 - src/locale/zh-cn.js | 17 ++++++++++++++++- test/locale/keys.test.js | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/locale/es.js b/src/locale/es.js index 2598369e..58312ea3 100644 --- a/src/locale/es.js +++ b/src/locale/es.js @@ -7,7 +7,6 @@ const locale = { relativeTime: { future: 'en %s', past: 'hace %s', - present: 'justo ahora', s: 'unos segundos', m: 'un minuto', mm: '%d minutos', diff --git a/src/locale/id.js b/src/locale/id.js index 2b0e0b39..da05f219 100644 --- a/src/locale/id.js +++ b/src/locale/id.js @@ -7,7 +7,6 @@ const locale = { relativeTime: { future: 'dalam %s', past: 'yang lalu %s', - present: 'sekarang', s: 'beberapa detik', m: 'satu menit', mm: '%d menit', diff --git a/src/locale/zh-cn.js b/src/locale/zh-cn.js index 6480ebd2..29c79e11 100644 --- a/src/locale/zh-cn.js +++ b/src/locale/zh-cn.js @@ -4,7 +4,22 @@ const locale = { name: 'zh-cn', weekdays: '星期日_星期一_星期二_星期三_星期四_星期五_星期六'.split('_'), months: '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'.split('_'), - ordinal: n => n + ordinal: n => n, + relativeTime: { + future: '%s内', + past: '%s前', + s: '几秒', + m: '1 分钟', + mm: '%d 分钟', + h: '1 小时', + hh: '%d 小时', + d: '1 天', + dd: '%d 天', + M: '1 个月', + MM: '%d 个月', + y: '1 年', + yy: '%d 年' + } } dayjs.locale(locale, null, true) diff --git a/test/locale/keys.test.js b/test/locale/keys.test.js index fc1aa9c0..ac890d76 100644 --- a/test/locale/keys.test.js +++ b/test/locale/keys.test.js @@ -25,7 +25,7 @@ it('Locale keys', () => { expect(dayjs().locale(name).$locale().name).toBe(name) if (relativeTime) { expect(Object.keys(relativeTime).sort()).toEqual(['d', 'dd', 'future', 'h', 'hh', 'm', 'mm', 'M', 'MM', - 'past', 'present', 's', 'y', 'yy'] + 'past', 's', 'y', 'yy'] .sort()) } }) From 97499575622b7b3d868a009f4030100852f28ec2 Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Thu, 11 Jul 2024 20:03:22 +0800 Subject: [PATCH 02/18] chore: rename plugin distanceInWords --- src/plugin/{advancedFormat.js => advancedFormat/index.js} | 2 +- src/plugin/{fromNow.js => distanceInWords/index.js} | 2 +- test/plugin/{fromNow.test.js => distanceInWords.test.js} | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename src/plugin/{advancedFormat.js => advancedFormat/index.js} (95%) rename src/plugin/{fromNow.js => distanceInWords/index.js} (97%) rename test/plugin/{fromNow.test.js => distanceInWords.test.js} (95%) diff --git a/src/plugin/advancedFormat.js b/src/plugin/advancedFormat/index.js similarity index 95% rename from src/plugin/advancedFormat.js rename to src/plugin/advancedFormat/index.js index 0820ee25..1af94b05 100644 --- a/src/plugin/advancedFormat.js +++ b/src/plugin/advancedFormat/index.js @@ -1,4 +1,4 @@ -import { FORMAT_DEFAULT } from '../constant' +import { FORMAT_DEFAULT } from '../../constant' export default (o, c, d) => { // locale needed later const proto = c.prototype diff --git a/src/plugin/fromNow.js b/src/plugin/distanceInWords/index.js similarity index 97% rename from src/plugin/fromNow.js rename to src/plugin/distanceInWords/index.js index a909cd25..1ac51e43 100644 --- a/src/plugin/fromNow.js +++ b/src/plugin/distanceInWords/index.js @@ -1,4 +1,4 @@ -import * as C from '../constant' +import * as C from '../../constant' export default (o, c, d) => { const proto = c.prototype diff --git a/test/plugin/fromNow.test.js b/test/plugin/distanceInWords.test.js similarity index 95% rename from test/plugin/fromNow.test.js rename to test/plugin/distanceInWords.test.js index 2e8ca364..df3709fa 100644 --- a/test/plugin/fromNow.test.js +++ b/test/plugin/distanceInWords.test.js @@ -1,9 +1,9 @@ import MockDate from 'mockdate' import moment from 'moment' import dayjs from '../../src' -import fromNow from '../../src/plugin/fromNow' +import distanceInWords from '../../src/plugin/distanceInWords' -dayjs.extend(fromNow) +dayjs.extend(distanceInWords) beforeEach(() => { MockDate.set(new Date('2018-04-04T16:00:00.000Z')) From 39027eb86247beacec9085a69cd14042f436512a Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Sat, 13 Jul 2024 12:56:02 +0800 Subject: [PATCH 03/18] build: update build plugin --- build/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/index.js b/build/index.js index 65b5bc75..c8a3fea5 100644 --- a/build/index.js +++ b/build/index.js @@ -29,7 +29,7 @@ async function build(option) { const plugins = await promisifyReadDir(path.join(__dirname, '../src/plugin')) plugins.forEach((l) => { build(configFactory({ - input: `./src/plugin/${l}`, + input: `./src/plugin/${l}/index`, fileName: `./plugin/${l}`, name: `dayjs_plugin_${formatName(l)}` })) From e50b4ba4fda7dd9dc1dae702631930ab084d3c5f Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Sun, 14 Jul 2024 21:15:02 +0800 Subject: [PATCH 04/18] docs: remove api locale, no need because of immutable --- docs/en/I18n.md | 9 --------- docs/ja/I18n.md | 9 --------- docs/pt-br/I18n.md | 9 --------- docs/zh-cn/I18n.md | 9 --------- 4 files changed, 36 deletions(-) diff --git a/docs/en/I18n.md b/docs/en/I18n.md index 50b7d275..c3f1cb83 100644 --- a/docs/en/I18n.md +++ b/docs/en/I18n.md @@ -41,15 +41,6 @@ dayjs().locale('es').format() // use loaded locale locally dayjs('2018-4-28', { locale: es }) // through constructor ``` -#### Changing locales in API call - -Check API documents for more details. - -```js -import 'dayjs/locale/es' -dayjs('2018-4-28').format(format, es) // use locale in this API call only -``` - ## Installation * Via NPM: diff --git a/docs/ja/I18n.md b/docs/ja/I18n.md index 968ab63b..fff7f312 100644 --- a/docs/ja/I18n.md +++ b/docs/ja/I18n.md @@ -41,15 +41,6 @@ dayjs().locale('es').format() // 読み込んだロケールを特定のイン dayjs('2018-4-28', { locale: es } // コンストラクタを通して適用 ``` -#### API 呼び出し時のロケールの変更 - -詳細については API ドキュメントをご覧ください。 - -```js -import 'dayjs/locale/es' -dayjs('2018-4-28').format(format, es) // この API 呼び出しにのみロケールを適用 -``` - ## インストール * NPM を使う場合: diff --git a/docs/pt-br/I18n.md b/docs/pt-br/I18n.md index edef5e47..8fe610a7 100644 --- a/docs/pt-br/I18n.md +++ b/docs/pt-br/I18n.md @@ -38,15 +38,6 @@ dayjs().locale('es').format() // usar locale localmente dayjs('2018-4-28', { locale: es }) // também pode ser feito no constructor ``` -#### Mudando locale apenas para uma chamada da API - -Pesquise os documentos da API para mais detalhes. - -```js -import 'dayjs/locale/es' -dayjs('2018-4-28').format(format, es) // usar o locale es apenas nessa chamada -``` - ## Instalação * Via NPM: diff --git a/docs/zh-cn/I18n.md b/docs/zh-cn/I18n.md index a13b8727..73a0a061 100644 --- a/docs/zh-cn/I18n.md +++ b/docs/zh-cn/I18n.md @@ -41,15 +41,6 @@ dayjs().locale('es').format() // 局部修改语言配置 dayjs('2018-4-28', { locale: es }) // 在新建实例时指定 ``` -#### 修改API调用的语言配置 - -查看相关API文档获取更多细节 - -```js -import 'dayjs/locale/es' -dayjs('2018-4-28').format(format, es) // 只在本次API调用时修改语言配置 -``` - ## 安装 * 通过 NPM: From c941f38bef5a4a09c2883b5f0efee95a25a83995 Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Thu, 18 Jul 2024 06:12:22 +0800 Subject: [PATCH 05/18] build: fix build bug --- build/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/index.js b/build/index.js index c8a3fea5..a5e08fda 100644 --- a/build/index.js +++ b/build/index.js @@ -30,7 +30,7 @@ async function build(option) { plugins.forEach((l) => { build(configFactory({ input: `./src/plugin/${l}/index`, - fileName: `./plugin/${l}`, + fileName: `./plugin/${l}.js`, name: `dayjs_plugin_${formatName(l)}` })) }) From 6472cee0d01716a75a1d4edc425145541e211c7a Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Sun, 21 Jul 2024 22:15:42 +0800 Subject: [PATCH 06/18] chore: rename to relativeTime --- src/plugin/{distanceInWords => relativeTime}/index.js | 0 test/plugin/{distanceInWords.test.js => relativeTime.js} | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/plugin/{distanceInWords => relativeTime}/index.js (100%) rename test/plugin/{distanceInWords.test.js => relativeTime.js} (96%) diff --git a/src/plugin/distanceInWords/index.js b/src/plugin/relativeTime/index.js similarity index 100% rename from src/plugin/distanceInWords/index.js rename to src/plugin/relativeTime/index.js diff --git a/test/plugin/distanceInWords.test.js b/test/plugin/relativeTime.js similarity index 96% rename from test/plugin/distanceInWords.test.js rename to test/plugin/relativeTime.js index df3709fa..f572bfd7 100644 --- a/test/plugin/distanceInWords.test.js +++ b/test/plugin/relativeTime.js @@ -1,7 +1,7 @@ import MockDate from 'mockdate' import moment from 'moment' import dayjs from '../../src' -import distanceInWords from '../../src/plugin/distanceInWords' +import distanceInWords from '../../src/plugin/relativeTime' dayjs.extend(distanceInWords) From 9791d9a438acd3f266d76e2085502850befa637d Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Mon, 22 Jul 2024 06:03:42 +0800 Subject: [PATCH 07/18] docs: relative time doc update --- docs/en/Plugin.md | 34 ++++++++++++++++++++++++++++++++-- docs/ja/Plugin.md | 4 ++-- docs/pt-br/Plugin.md | 4 ++-- docs/zh-cn/Plugin.md | 4 ++-- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/docs/en/Plugin.md b/docs/en/Plugin.md index 66e7430e..2d650458 100644 --- a/docs/en/Plugin.md +++ b/docs/en/Plugin.md @@ -47,9 +47,9 @@ dayjs.extend(AdvancedFormat) // use plugin - AdvancedFormat extends `dayjs().format` API to supply more format options. ```javascript -import AdvancedFormat from 'dayjs/plugin/AdvancedFormat' +import advancedFormat from 'dayjs/plugin/advancedFormat' -dayjs.extend(AdvancedFormat) +dayjs.extend(advancedFormat) dayjs().format('Q Do k kk X x') ``` @@ -65,6 +65,36 @@ List of added formats: | `X` | 1360013296 | Unix Timestamp in second | | `x` | 1360013296123 | Unix Timestamp in millisecond | +### RelativeTime + - RelativeTime adds `.from`, `.to`, `.fromNow`, `.toNow` APIs to formats date to relative time strings (e.g. 3 hours ago). + +```javascript +import relativeTime from 'dayjs/plugin/relativeTime' + +dayjs.extend(relativeTime) + +dayjs().from(dayjs()) +dayjs().fromNow() +dayjs().to(dayjs()) +dayjs().toNow() +``` + +| Range | Key | Sample Output | +| ------------------------ | ---- | -------------------------------- | +| 0 to 44 seconds | s | a few seconds ago | +| 44 to 44 seconds | ss | 44 seconds ago | +| 45 to 89 seconds | min | a minute ago | +| 90 seconds to 44 minutes | mins | 2 minutes ago ... 44 minutes ago | +| 45 to 89 minutes | h | an hour ago | +| 90 minutes to 21 hours | hh | 2 hours ago ... 21 hours ago | +| 22 to 35 hours | d | a day ago | +| 36 hours to 25 days | dd | 2 days ago ... 25 days ago | +| 26 to 45 days | M | a month ago | +| 46 days to 10 months | MM | 2 months ago ... 10 months ago | +| 11 months to 17months | y | a year ago | +| 18months+ | yy | 2 years ago ... 20 years ago | + + ## Customize You could build your own Day.js plugin to meet different needs. diff --git a/docs/ja/Plugin.md b/docs/ja/Plugin.md index 0c28fa19..c82de868 100644 --- a/docs/ja/Plugin.md +++ b/docs/ja/Plugin.md @@ -26,9 +26,9 @@ dayjs.extend(plugin, options) // プラグインのオプションを指定 ```javascript import dayjs from 'dayjs' -import AdvancedFormat from 'dayjs/plugin/AdvancedFormat' // 必要に応じて読み込み +import advancedFormat from 'dayjs/plugin/advancedFormat' // 必要に応じて読み込み -dayjs.extend(AdvancedFormat) // プラグインを使用 +dayjs.extend(advancedFormat) // プラグインを使用 ``` * CDN を使う場合: diff --git a/docs/pt-br/Plugin.md b/docs/pt-br/Plugin.md index 3a140eed..a2452856 100644 --- a/docs/pt-br/Plugin.md +++ b/docs/pt-br/Plugin.md @@ -26,9 +26,9 @@ dayjs.extend(plugin, options) // com opções do plugin ```javascript import dayjs from 'dayjs' -import AdvancedFormat from 'dayjs/plugin/AdvancedFormat' // carregar sob demanda +import advancedFormat from 'dayjs/plugin/advancedFormat' // carregar sob demanda -dayjs.extend(AdvancedFormat) // usar plugin +dayjs.extend(advancedFormat) // usar plugin ``` * Via CDN: diff --git a/docs/zh-cn/Plugin.md b/docs/zh-cn/Plugin.md index bbb351e0..b14b5475 100644 --- a/docs/zh-cn/Plugin.md +++ b/docs/zh-cn/Plugin.md @@ -26,9 +26,9 @@ dayjs.extend(plugin, options) // 带参数加载插件 ```javascript import dayjs from 'dayjs' -import AdvancedFormat from 'dayjs/plugin/AdvancedFormat' // 按需加载 +import advancedFormat from 'dayjs/plugin/advancedFormat' // 按需加载 -dayjs.extend(AdvancedFormat) // 使用插件 +dayjs.extend(advancedFormat) // 使用插件 ``` * 通过 CDN: From 5f5652a6f228cd76efe016e80cc5749fa82f5997 Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Thu, 25 Jul 2024 10:44:42 +0800 Subject: [PATCH 08/18] docs: doc error ifx --- README.md | 4 ++-- docs/en/Plugin.md | 6 +++--- docs/ja/README-ja.md | 4 ++-- docs/pt-br/README-pt-br.md | 4 ++-- docs/zh-cn/README.zh-CN.md | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fb91e5cf..399dd4a4 100644 --- a/README.md +++ b/README.md @@ -86,9 +86,9 @@ dayjs('2018-05-05').locale('zh-cn').format() // use Chinese Simplified locale in A plugin is an independent module that can be added to Day.js to extend functionality or add new features. ```javascript -import AdvancedFormat from 'dayjs/plugin/AdvancedFormat' // load on demand +import advancedFormat from 'dayjs/plugin/advancedFormat' // load on demand -dayjs.extend(AdvancedFormat) // use plugin +dayjs.extend(advancedFormat) // use plugin dayjs().format('Q Do k kk X x') // more available formats ``` diff --git a/docs/en/Plugin.md b/docs/en/Plugin.md index 2d650458..06ac5d26 100644 --- a/docs/en/Plugin.md +++ b/docs/en/Plugin.md @@ -83,8 +83,8 @@ dayjs().toNow() | ------------------------ | ---- | -------------------------------- | | 0 to 44 seconds | s | a few seconds ago | | 44 to 44 seconds | ss | 44 seconds ago | -| 45 to 89 seconds | min | a minute ago | -| 90 seconds to 44 minutes | mins | 2 minutes ago ... 44 minutes ago | +| 45 to 89 seconds | m | a minute ago | +| 90 seconds to 44 minutes | mm | 2 minutes ago ... 44 minutes ago | | 45 to 89 minutes | h | an hour ago | | 90 minutes to 21 hours | hh | 2 hours ago ... 21 hours ago | | 22 to 35 hours | d | a day ago | @@ -92,7 +92,7 @@ dayjs().toNow() | 26 to 45 days | M | a month ago | | 46 days to 10 months | MM | 2 months ago ... 10 months ago | | 11 months to 17months | y | a year ago | -| 18months+ | yy | 2 years ago ... 20 years ago | +| 18 months+ | yy | 2 years ago ... 20 years ago | ## Customize diff --git a/docs/ja/README-ja.md b/docs/ja/README-ja.md index 23b71fce..aaf1fb89 100644 --- a/docs/ja/README-ja.md +++ b/docs/ja/README-ja.md @@ -86,9 +86,9 @@ dayjs('2018-05-05').locale('zh-cn').format() // 簡体字中国語を特定の プラグインとは、 Day.js の機能を拡張したり、新たな機能を追加するための独立したモジュールのことです。 ```javascript -import AdvancedFormat from 'dayjs/plugin/AdvancedFormat' // 必要に応じて読み込み +import advancedFormat from 'dayjs/plugin/advancedFormat' // 必要に応じて読み込み -dayjs.extend(AdvancedFormat) // プラグインを使用 +dayjs.extend(advancedFormat) // プラグインを使用 dayjs().format('Q Do k kk X x') // 多様なフォーマットが利用可能に ``` diff --git a/docs/pt-br/README-pt-br.md b/docs/pt-br/README-pt-br.md index 5cf73613..1d01f2db 100644 --- a/docs/pt-br/README-pt-br.md +++ b/docs/pt-br/README-pt-br.md @@ -84,9 +84,9 @@ dayjs('2018-05-05').locale('pt-br').format() // usar locale em português brasil Um plugin é um módulo independente que pode ser adicionado ao Day.js para estendê-lo com mais funcionalidades. ```javascript -import AdvancedFormat from 'dayjs/plugin/AdvancedFormat' // carregar sob demanda +import advancedFormat from 'dayjs/plugin/advancedFormat' // carregar sob demanda -dayjs.extend(AdvancedFormat) // usar plugin +dayjs.extend(advancedFormat) // usar plugin dayjs().format('Q Do k kk X x') // mais formatos disponíveis pelo plugin ``` diff --git a/docs/zh-cn/README.zh-CN.md b/docs/zh-cn/README.zh-CN.md index 224a8477..b110642d 100644 --- a/docs/zh-cn/README.zh-CN.md +++ b/docs/zh-cn/README.zh-CN.md @@ -83,9 +83,9 @@ dayjs('2018-05-05').locale('zh-cn').format() // 在这个实例上使用简体 插件是一些独立的程序,可以给 Day.js 增加新功能和扩展已有功能 ```javascript -import AdvancedFormat from 'dayjs/plugin/AdvancedFormat' // 按需加载插件 +import advancedFormat from 'dayjs/plugin/advancedFormat' // 按需加载插件 -dayjs.extend(AdvancedFormat) // 使用插件 +dayjs.extend(advancedFormat) // 使用插件 dayjs().format('Q Do k kk X x') // 使用扩展后的API ``` From a456db8997e2bda435b039a75f2e5c5123d52aef Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Sat, 27 Jul 2024 06:54:22 +0800 Subject: [PATCH 09/18] docs: cn format update --- docs/zh-cn/API-reference.md | 44 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/docs/zh-cn/API-reference.md b/docs/zh-cn/API-reference.md index f21edf1e..59ac77f3 100644 --- a/docs/zh-cn/API-reference.md +++ b/docs/zh-cn/API-reference.md @@ -199,26 +199,30 @@ dayjs().format("{YYYY} MM-DDTHH:mm:ssZ[Z]"); // "{2014} 09-08T08:02:17-05:00Z" 详情如下: -| Format | Output | Description | -| ------ | ------ | ----------- | -| `YY` | 18 | 两位数的年份 | -| `YYYY` | 2018 | 四位数的年份 | -| `M` | 1-12 | 月份,从1开始 | -| `MM` | 01-12 | 月份,数字前面加上0 -| `MMM` | Jan-Dec | 简写的月份名称 | -| `MMMM` | January-December | 完整的月份名称 | -| `D` | 1-31 | 月份里的一天 | -| `DD` | 01-31 | 月份里的一天,数字前面加上0 | -| `d` | 0-6 | 一周中的一天,星期天是0 | -| `dddd` | Sunday-Saturday | 一周中一天的名称 | -| `H` | 0-23 | 小时 | -| `HH` | 00-23 | 小时,数字前面加上0 | -| `m` | 0-59 | 分钟 | -| `mm` | 00-59 | 分钟,数字前面加上0 | -| `s` | 0-59 | 秒 | -| `ss` | 00-59 | 秒,数字前面加上0 | -| `Z` | +5:00 | UTC的偏移量 | -| `ZZ` | +0500 | UTC的偏移量,数字前面加上0 | +| Format | Output | Description | +| ------ | ---------------- | ---------------------------- | +| `YY` | 18 | 两位数的年份 | +| `YYYY` | 2018 | 四位数的年份 | +| `M` | 1-12 | 月份,从 1 开始 | +| `MM` | 01-12 | 月份,两位数 | +| `MMM` | Jan-Dec | 简写的月份名称 | +| `MMMM` | January-December | 完整的月份名称 | +| `D` | 1-31 | 月份里的一天 | +| `DD` | 01-31 | 月份里的一天,两位数 | +| `d` | 0-6 | 一周中的一天,星期天是 0 | +| `dddd` | Sunday-Saturday | 一周中一天的名称 | +| `H` | 0-23 | 小时 | +| `HH` | 00-23 | 小时,两位数 | +| `m` | 0-59 | 分钟 | +| `mm` | 00-59 | 分钟,两位数 | +| `s` | 0-59 | 秒 | +| `ss` | 00-59 | 秒 两位数 | +| `SSS` | 000-999 | 秒 三位数 | +| `Z` | +5:00 | UTC 的偏移量 | +| `ZZ` | +0500 | UTC 的偏移量,数字前面加上 0 | +| `A` | AM PM | | +| `a` | am pm | | + #### 时间差 - return Number From 4c14cd600b6e51f8fbb1586a4999f63f7d8420ec Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Sun, 28 Jul 2024 18:04:52 +0800 Subject: [PATCH 10/18] docs: update en format doc --- docs/en/API-reference.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/en/API-reference.md b/docs/en/API-reference.md index f896be9a..491be003 100644 --- a/docs/en/API-reference.md +++ b/docs/en/API-reference.md @@ -254,6 +254,8 @@ dayjs('2019-01-25').format('DD/MM/YYYY'); // '25/01/2019' | `A` | AM PM | | | `a` | am pm | | +* More available formats `Q Do k kk X x` in plugin [`advancedFormat`](./Plugin.md#advancedformat) + ### Difference `.diff(compared: Dayjs, unit: string (default: 'milliseconds'), float?: boolean)` Returns a `number` indicating the difference of two `Dayjs`s in the specified unit. From c615d48f6c715ba7e49cedb8e1b74c4c509cec81 Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Mon, 29 Jul 2024 13:46:22 +0800 Subject: [PATCH 11/18] docs: update other docs format options --- docs/en/API-reference.md | 2 +- docs/ja/API-reference.md | 2 ++ docs/pt-br/API-reference.md | 2 ++ docs/zh-cn/API-reference.md | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/en/API-reference.md b/docs/en/API-reference.md index 491be003..2bd56678 100644 --- a/docs/en/API-reference.md +++ b/docs/en/API-reference.md @@ -254,7 +254,7 @@ dayjs('2019-01-25').format('DD/MM/YYYY'); // '25/01/2019' | `A` | AM PM | | | `a` | am pm | | -* More available formats `Q Do k kk X x` in plugin [`advancedFormat`](./Plugin.md#advancedformat) +* More available formats `Q Do k kk X x ...` in plugin [`advancedFormat`](./Plugin.md#advancedformat) ### Difference `.diff(compared: Dayjs, unit: string (default: 'milliseconds'), float?: boolean)` diff --git a/docs/ja/API-reference.md b/docs/ja/API-reference.md index 6f16f344..a97d94df 100644 --- a/docs/ja/API-reference.md +++ b/docs/ja/API-reference.md @@ -303,6 +303,8 @@ dayjs().format('{YYYY} MM-DDTHH:mm:ssZ[Z]'); // "{2014} 09-08T08:02:17-05:00Z" | `A` | AM PM | 午前と午後 (大文字) | | `a` | am pm | 午前と午後 (小文字) | +* More available formats `Q Do k kk X x ...` in plugin [`advancedFormat`](./Plugin.md#advancedformat) + #### Difference * Number を返します diff --git a/docs/pt-br/API-reference.md b/docs/pt-br/API-reference.md index ca3f125e..e9f5e514 100644 --- a/docs/pt-br/API-reference.md +++ b/docs/pt-br/API-reference.md @@ -284,6 +284,8 @@ Lista de todos os formatos disponíveis: | `A` | AM PM | | | `a` | am pm | | +* More available formats `Q Do k kk X x ...` in plugin [`advancedFormat`](./Plugin.md#advancedformat) + #### Diferença * retorna um Number diff --git a/docs/zh-cn/API-reference.md b/docs/zh-cn/API-reference.md index 59ac77f3..9618a116 100644 --- a/docs/zh-cn/API-reference.md +++ b/docs/zh-cn/API-reference.md @@ -223,6 +223,7 @@ dayjs().format("{YYYY} MM-DDTHH:mm:ssZ[Z]"); // "{2014} 09-08T08:02:17-05:00Z" | `A` | AM PM | | | `a` | am pm | | +* 更多格式化的选项 `Q Do k kk X x ...` 可以使用插件 [`advancedFormat`](./Plugin.md#advancedformat) #### 时间差 - return Number From b662d39f121d4925e7e4f4fc6415ef93111a6b49 Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Tue, 30 Jul 2024 15:57:42 +0800 Subject: [PATCH 12/18] docs: locale template update --- docs/en/I18n.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/en/I18n.md b/docs/en/I18n.md index c3f1cb83..fe440702 100644 --- a/docs/en/I18n.md +++ b/docs/en/I18n.md @@ -79,7 +79,22 @@ const localeObject = { name: 'es', // name String weekdays: 'Domingo_Lunes ...'.split('_'), // weekdays Array months: 'Enero_Febrero ... '.split('_'), // months Array - ordinal: n => `${n}º` // ordinal Function (number) => return number + output + ordinal: n => `${n}º`, // ordinal Function (number) => return number + output + relativeTime = { // relative time format strings, keep %s %d as the same + future: 'in %s', // e.g. in 2 hours, %s been replaced with 2hours + past: '%s ago', + s: 'a few seconds', + m: 'a minute', + mm: '%d minutes', + h: 'an hour', + hh: '%d hours', // e.g. 2 hours, %d been replaced with 2 + d: 'a day', + dd: '%d days', + M: 'a month', + MM: '%d months', + y: 'a year', + yy: '%d years' + } } ``` From 1b3b6cd8162963a5bd0b6af68e62d8cc5330022c Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Fri, 2 Aug 2024 18:12:32 +0800 Subject: [PATCH 13/18] docs: update other template --- docs/ja/I18n.md | 17 ++++++++++++++++- docs/pt-br/I18n.md | 17 ++++++++++++++++- docs/zh-cn/I18n.md | 17 ++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/docs/ja/I18n.md b/docs/ja/I18n.md index fff7f312..bbc0eff3 100644 --- a/docs/ja/I18n.md +++ b/docs/ja/I18n.md @@ -81,7 +81,22 @@ const localeObject = { name: 'es', // ロケール名を表す文字列 weekdays: 'Domingo_Lunes ...'.split('_'), // 曜日の配列 months: 'Enero_Febrero ... '.split('_'), // 月の配列 - ordinal: n => `${n}º` // 序数 Function (number) => return number + output + ordinal: n => `${n}º`, // 序数 Function (number) => return number + output + relativeTime = { // relative time format strings, keep %s %d as the same + future: 'in %s', // e.g. in 2 hours, %s been replaced with 2hours + past: '%s ago', + s: 'a few seconds', + m: 'a minute', + mm: '%d minutes', + h: 'an hour', + hh: '%d hours', // e.g. 2 hours, %d been replaced with 2 + d: 'a day', + dd: '%d days', + M: 'a month', + MM: '%d months', + y: 'a year', + yy: '%d years' + } } ``` diff --git a/docs/pt-br/I18n.md b/docs/pt-br/I18n.md index 8fe610a7..6846061e 100644 --- a/docs/pt-br/I18n.md +++ b/docs/pt-br/I18n.md @@ -74,7 +74,22 @@ const objetoLocale = { name: 'es', // name: String weekdays: 'Domingo_Lunes ...'.split('_'), // weekdays: Array months: 'Enero_Febrero ... '.split('_'), // months: Array - ordinal: n => `${n}º` // ordinal: Function (number) => return number + saída + ordinal: n => `${n}º`, // ordinal: Function (number) => return number + saída + relativeTime = { // relative time format strings, keep %s %d as the same + future: 'in %s', // e.g. in 2 hours, %s been replaced with 2hours + past: '%s ago', + s: 'a few seconds', + m: 'a minute', + mm: '%d minutes', + h: 'an hour', + hh: '%d hours', // e.g. 2 hours, %d been replaced with 2 + d: 'a day', + dd: '%d days', + M: 'a month', + MM: '%d months', + y: 'a year', + yy: '%d years' + } } ``` diff --git a/docs/zh-cn/I18n.md b/docs/zh-cn/I18n.md index 73a0a061..ce0aada2 100644 --- a/docs/zh-cn/I18n.md +++ b/docs/zh-cn/I18n.md @@ -79,7 +79,22 @@ const localeObject = { name: 'es', // 语言名 String weekdays: 'Domingo_Lunes ...'.split('_'), // 星期 Array months: 'Enero_Febrero ... '.split('_'), // 月份 Array - ordinal: n => `${n}º` // 序号生成工厂 Function (number) => return number + output + ordinal: n => `${n}º`, // 序号生成工厂函数 Function (number) => return number + output + relativeTime = { // 相对时间, %s %d 不用翻译 + future: 'in %s', // e.g. in 2 hours, %s been replaced with 2hours + past: '%s ago', + s: 'a few seconds', + m: 'a minute', + mm: '%d minutes', + h: 'an hour', + hh: '%d hours', // e.g. 2 hours, %d been replaced with 2 + d: 'a day', + dd: '%d days', + M: 'a month', + MM: '%d months', + y: 'a year', + yy: '%d years' + } } ``` From 075d36b9fe6bf1b7828ac15b583908f4c64b7b81 Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Sat, 3 Aug 2024 17:14:22 +0800 Subject: [PATCH 14/18] docs: update relative time docs --- docs/en/Plugin.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/en/Plugin.md b/docs/en/Plugin.md index 06ac5d26..0ce511e0 100644 --- a/docs/en/Plugin.md +++ b/docs/en/Plugin.md @@ -73,12 +73,32 @@ import relativeTime from 'dayjs/plugin/relativeTime' dayjs.extend(relativeTime) -dayjs().from(dayjs()) +dayjs().from(dayjs('1990')) // 2 years ago +dayjs().from(dayjs(), true) // 2 years + dayjs().fromNow() + dayjs().to(dayjs()) + dayjs().toNow() ``` +#### Time from now `.fromNow(withoutSuffix?: boolean)` + +Returns the `string` of relative time from now. + +#### Time from X `.from(compared: Dayjs, withoutSuffix?: boolean)` + +Returns the `string` of relative time from the `Dayjs`. + +#### Time to now `.toNow(withoutSuffix?: boolean)` + +Returns the `string` of relative time to now. + +#### Time to X `.to(compared: Dayjs, withoutSuffix?: boolean)` + +Returns the `string` of relative time to the `Dayjs`. + | Range | Key | Sample Output | | ------------------------ | ---- | -------------------------------- | | 0 to 44 seconds | s | a few seconds ago | From 2bd333f9d60ec080a45164e3460bb3e2926609c5 Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Tue, 6 Aug 2024 11:20:12 +0800 Subject: [PATCH 15/18] docs: update other three docs --- docs/en/Plugin.md | 5 ++--- docs/ja/Plugin.md | 49 ++++++++++++++++++++++++++++++++++++++++++++ docs/pt-br/Plugin.md | 49 ++++++++++++++++++++++++++++++++++++++++++++ docs/zh-cn/Plugin.md | 48 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+), 3 deletions(-) diff --git a/docs/en/Plugin.md b/docs/en/Plugin.md index 0ce511e0..9912aaff 100644 --- a/docs/en/Plugin.md +++ b/docs/en/Plugin.md @@ -89,7 +89,7 @@ Returns the `string` of relative time from now. #### Time from X `.from(compared: Dayjs, withoutSuffix?: boolean)` -Returns the `string` of relative time from the `Dayjs`. +Returns the `string` of relative time from X. #### Time to now `.toNow(withoutSuffix?: boolean)` @@ -97,12 +97,11 @@ Returns the `string` of relative time to now. #### Time to X `.to(compared: Dayjs, withoutSuffix?: boolean)` -Returns the `string` of relative time to the `Dayjs`. +Returns the `string` of relative time to X. | Range | Key | Sample Output | | ------------------------ | ---- | -------------------------------- | | 0 to 44 seconds | s | a few seconds ago | -| 44 to 44 seconds | ss | 44 seconds ago | | 45 to 89 seconds | m | a minute ago | | 90 seconds to 44 minutes | mm | 2 minutes ago ... 44 minutes ago | | 45 to 89 minutes | h | an hour ago | diff --git a/docs/ja/Plugin.md b/docs/ja/Plugin.md index c82de868..d2face27 100644 --- a/docs/ja/Plugin.md +++ b/docs/ja/Plugin.md @@ -66,6 +66,55 @@ dayjs().format('Q Do k kk X x') | `X` | 1360013296 | Unix タイムスタンプ (秒) | | `x` | 1360013296123 | Unix タイムスタンプ (ミリ秒) | +### RelativeTime + - RelativeTime adds `.from`, `.to`, `.fromNow`, `.toNow` APIs to formats date to relative time strings (e.g. 3 hours ago). + +```javascript +import relativeTime from 'dayjs/plugin/relativeTime' + +dayjs.extend(relativeTime) + +dayjs().from(dayjs('1990')) // 2 years ago +dayjs().from(dayjs(), true) // 2 years + +dayjs().fromNow() + +dayjs().to(dayjs()) + +dayjs().toNow() +``` + +#### Time from now `.fromNow(withoutSuffix?: boolean)` + +Returns the `string` of relative time from now. + +#### Time from X `.from(compared: Dayjs, withoutSuffix?: boolean)` + +Returns the `string` of relative time from X. + +#### Time to now `.toNow(withoutSuffix?: boolean)` + +Returns the `string` of relative time to now. + +#### Time to X `.to(compared: Dayjs, withoutSuffix?: boolean)` + +Returns the `string` of relative time to X. + +| Range | Key | Sample Output | +| ------------------------ | ---- | -------------------------------- | +| 0 to 44 seconds | s | a few seconds ago | +| 45 to 89 seconds | m | a minute ago | +| 90 seconds to 44 minutes | mm | 2 minutes ago ... 44 minutes ago | +| 45 to 89 minutes | h | an hour ago | +| 90 minutes to 21 hours | hh | 2 hours ago ... 21 hours ago | +| 22 to 35 hours | d | a day ago | +| 36 hours to 25 days | dd | 2 days ago ... 25 days ago | +| 26 to 45 days | M | a month ago | +| 46 days to 10 months | MM | 2 months ago ... 10 months ago | +| 11 months to 17months | y | a year ago | +| 18 months+ | yy | 2 years ago ... 20 years ago | + + ## カスタマイズ さまざまなニーズに合わせて独自の Day.js プラグインを構築することができます。 diff --git a/docs/pt-br/Plugin.md b/docs/pt-br/Plugin.md index a2452856..f61f8f8c 100644 --- a/docs/pt-br/Plugin.md +++ b/docs/pt-br/Plugin.md @@ -65,6 +65,55 @@ Lista de formatos adicionados: | `X` | 1360013296 | Unix Timestamp em segundos | | `x` | 1360013296123 | Unix Timestamp em milissegundos | +### RelativeTime + - RelativeTime adds `.from`, `.to`, `.fromNow`, `.toNow` APIs to formats date to relative time strings (e.g. 3 hours ago). + +```javascript +import relativeTime from 'dayjs/plugin/relativeTime' + +dayjs.extend(relativeTime) + +dayjs().from(dayjs('1990')) // 2 years ago +dayjs().from(dayjs(), true) // 2 years + +dayjs().fromNow() + +dayjs().to(dayjs()) + +dayjs().toNow() +``` + +#### Time from now `.fromNow(withoutSuffix?: boolean)` + +Returns the `string` of relative time from now. + +#### Time from X `.from(compared: Dayjs, withoutSuffix?: boolean)` + +Returns the `string` of relative time from X. + +#### Time to now `.toNow(withoutSuffix?: boolean)` + +Returns the `string` of relative time to now. + +#### Time to X `.to(compared: Dayjs, withoutSuffix?: boolean)` + +Returns the `string` of relative time to X. + +| Range | Key | Sample Output | +| ------------------------ | ---- | -------------------------------- | +| 0 to 44 seconds | s | a few seconds ago | +| 45 to 89 seconds | m | a minute ago | +| 90 seconds to 44 minutes | mm | 2 minutes ago ... 44 minutes ago | +| 45 to 89 minutes | h | an hour ago | +| 90 minutes to 21 hours | hh | 2 hours ago ... 21 hours ago | +| 22 to 35 hours | d | a day ago | +| 36 hours to 25 days | dd | 2 days ago ... 25 days ago | +| 26 to 45 days | M | a month ago | +| 46 days to 10 months | MM | 2 months ago ... 10 months ago | +| 11 months to 17months | y | a year ago | +| 18 months+ | yy | 2 years ago ... 20 years ago | + + ## Customizar Você também pode construir seu próprio plugin Day.js para diferentes necessidades. Sinta-se à vontade para abrir um pull request e compartilhar seu plugin com a comunidade. diff --git a/docs/zh-cn/Plugin.md b/docs/zh-cn/Plugin.md index b14b5475..54f3a458 100644 --- a/docs/zh-cn/Plugin.md +++ b/docs/zh-cn/Plugin.md @@ -65,6 +65,54 @@ dayjs().format('Q Do k kk X x') | `X` | 1360013296 | 秒为单位的Unix时间戳 | | `x` | 1360013296123 | 毫秒单位的Unix时间戳 | +### RelativeTime + - RelativeTime 增加了 `.from`, `.to`, `.fromNow`, `.toNow` 4个 API 来展示相对的时间 (e.g. 3 小时以前). + +```javascript +import relativeTime from 'dayjs/plugin/relativeTime' + +dayjs.extend(relativeTime) + +dayjs().from(dayjs('1990')) // 2 年以前 +dayjs().from(dayjs(), true) // 2 年 + +dayjs().fromNow() + +dayjs().to(dayjs()) + +dayjs().toNow() +``` + +#### 距离现在的相对时间 `.fromNow(withoutSuffix?: boolean)` + +返回 `string` 距离现在的相对时间 + +#### 距离 X 的相对时间 `.from(compared: Dayjs, withoutSuffix?: boolean)` + +返回 `string` 距离 X 的相对时间 + +#### 到现在的相对时间 `.toNow(withoutSuffix?: boolean)` + +返回 `string` 到现在的相对时间 + +#### 到 X 的相对时间 `.to(compared: Dayjs, withoutSuffix?: boolean)` + +返回 `string` 到 X 的相对时间 + +| Range | Key | Sample Output | +| ------------------------ | ---- | -------------------------------- | +| 0 到 44 秒 | s | 几秒前 | +| 45 到 89 秒 | m | 1 分钟前 | +| 90 秒 到 44 分 | mm | 2 分钟前 ... 44 分钟前 | +| 45 到 89 分 | h | 1 小时前 | +| 90 分 到 21 小时 | hh | 2 小时前 ... 21 小时前 | +| 22 到 35 小时 | d | 1 天前 | +| 36 小时 到 25 天 | dd | 2 天前 ... 25 天前 | +| 26 到 45 天 | M | 1 个月前 | +| 46 天 到 10 月 | MM | 2 个月前 ... 10 个月前 | +| 11 月 到 17月 | y | 1 年前 | +| 18 月以上 | yy | 2 年前 ... 20 年前 | + ## 自定义 你可以根据需要自由的编写一个Day.js插件 From da4ccf5a42f45fef80b071dd2f392183c9beca69 Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Fri, 9 Aug 2024 22:00:22 +0800 Subject: [PATCH 16/18] docs: update api reference --- docs/en/API-reference.md | 12 +++++++++++- docs/ja/API-reference.md | 12 +++++++++++- docs/pt-br/API-reference.md | 12 +++++++++++- docs/zh-cn/API-reference.md | 14 ++++++++++++-- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/docs/en/API-reference.md b/docs/en/API-reference.md index 2bd56678..04f5b21b 100644 --- a/docs/en/API-reference.md +++ b/docs/en/API-reference.md @@ -45,6 +45,8 @@ The `Dayjs` object is immutable, that is, all API operations that change the `Da - [Is Same `.isSame(compared: Dayjs)`](#is-same-issamecompared-dayjs) - [Is After `.isAfter(compared: Dayjs)`](#is-after-isaftercompared-dayjs) - [Is Leap Year `.isLeapYear()`](#is-leap-year-isleapyear) + - [Plugin APIs](#plugin-apis) + - [RelativeTime](#relativetime) ## Parsing @@ -254,7 +256,7 @@ dayjs('2019-01-25').format('DD/MM/YYYY'); // '25/01/2019' | `A` | AM PM | | | `a` | am pm | | -* More available formats `Q Do k kk X x ...` in plugin [`advancedFormat`](./Plugin.md#advancedformat) +* More available formats `Q Do k kk X x ...` in plugin [`AdvancedFormat`](./Plugin.md#advancedformat) ### Difference `.diff(compared: Dayjs, unit: string (default: 'milliseconds'), float?: boolean)` @@ -381,3 +383,11 @@ Returns a `boolean` indicating whether the `Dayjs`'s year is a leap year or not. ```js dayjs('2000-01-01').isLeapYear(); // true ``` + +## Plugin APIs + +### RelativeTime + +`.from`, `.to`, `.fromNow`, `.toNow` to get relative time + +plugin [`RelativeTime`](./Plugin.md#relativeTime) diff --git a/docs/ja/API-reference.md b/docs/ja/API-reference.md index a97d94df..65d6bf9a 100644 --- a/docs/ja/API-reference.md +++ b/docs/ja/API-reference.md @@ -43,6 +43,8 @@ Day.js は組み込みの `Date.prototype` を変更する代わりに `Dayjs` * [Is Same](#is-same) * [Is After](#is-after) * [Is Leap Year](#is-leap-year) +* [Plugin APIs](#plugin-apis) + * [RelativeTime](#relativetime) --- @@ -303,7 +305,7 @@ dayjs().format('{YYYY} MM-DDTHH:mm:ssZ[Z]'); // "{2014} 09-08T08:02:17-05:00Z" | `A` | AM PM | 午前と午後 (大文字) | | `a` | am pm | 午前と午後 (小文字) | -* More available formats `Q Do k kk X x ...` in plugin [`advancedFormat`](./Plugin.md#advancedformat) +* More available formats `Q Do k kk X x ...` in plugin [`AdvancedFormat`](./Plugin.md#advancedformat) #### Difference @@ -454,3 +456,11 @@ dayjs().isAfter(dayjs()); // false dayjs().isLeapYear(); dayjs('2000-01-01').isLeapYear(); // true ``` + +## Plugin APIs + +### RelativeTime + +`.from`, `.to`, `.fromNow`, `.toNow` to get relative time + +plugin [`RelativeTime`](./Plugin.md#relativeTime) diff --git a/docs/pt-br/API-reference.md b/docs/pt-br/API-reference.md index e9f5e514..2072f1a9 100644 --- a/docs/pt-br/API-reference.md +++ b/docs/pt-br/API-reference.md @@ -43,6 +43,8 @@ Este objeto `Dayjs` é imutável, ou seja, todas as operações desta API irão * [Igual](#igual) * [Depois](#depois) * [Ano Bissexto](#ano-bissexto) +* [Plugin APIs](#plugin-apis) + * [RelativeTime](#relativetime) --- O Day.js sempre irá retornar um novo objeto `Dayjs` se nada for especificado. @@ -284,7 +286,7 @@ Lista de todos os formatos disponíveis: | `A` | AM PM | | | `a` | am pm | | -* More available formats `Q Do k kk X x ...` in plugin [`advancedFormat`](./Plugin.md#advancedformat) +* More available formats `Q Do k kk X x ...` in plugin [`AdvancedFormat`](./Plugin.md#advancedformat) #### Diferença @@ -432,3 +434,11 @@ Se um ano é bissexto. dayjs().isLeapYear(); dayjs('2000-01-01').isLeapYear(); // true ``` + +## Plugin APIs + +### RelativeTime + +`.from`, `.to`, `.fromNow`, `.toNow` to get relative time + +plugin [`RelativeTime`](./Plugin.md#relativeTime) diff --git a/docs/zh-cn/API-reference.md b/docs/zh-cn/API-reference.md index 9618a116..e060c2d4 100644 --- a/docs/zh-cn/API-reference.md +++ b/docs/zh-cn/API-reference.md @@ -43,6 +43,8 @@ * [是否相同](#是否相同) * [是否之后](#是否之后) * [是否闰年](#是否闰年) +* [插件 APIs](#plugin-apis) + * [相对时间](#relativetime) --- 如果没有特别说明,Day.js 的返回值都是新的 `Dayjs` 对象。 @@ -223,7 +225,7 @@ dayjs().format("{YYYY} MM-DDTHH:mm:ssZ[Z]"); // "{2014} 09-08T08:02:17-05:00Z" | `A` | AM PM | | | `a` | am pm | | -* 更多格式化的选项 `Q Do k kk X x ...` 可以使用插件 [`advancedFormat`](./Plugin.md#advancedformat) +* 更多格式化的选项 `Q Do k kk X x ...` 可以使用插件 [`AdvancedFormat`](./Plugin.md#advancedformat) #### 时间差 - return Number @@ -328,4 +330,12 @@ dayjs().isAfter(dayjs()); // false ```js dayjs().isLeapYear(); dayjs('2000-01-01').isLeapYear(); // true -``` \ No newline at end of file +``` + +## 插件 APIs + +### 相对时间 + +`.from`, `.to`, `.fromNow`, `.toNow` 获得相对时间 + +插件 [`RelativeTime`](./Plugin.md#relativeTime) \ No newline at end of file From 3ac87839c608a1e2f5667e11061119882c665dd6 Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Mon, 12 Aug 2024 14:24:02 +0800 Subject: [PATCH 17/18] docs: small fix --- docs/en/API-reference.md | 4 ++-- docs/en/Plugin.md | 2 +- docs/ja/API-reference.md | 4 ++-- docs/ja/Plugin.md | 2 +- docs/pt-br/API-reference.md | 4 ++-- docs/pt-br/Plugin.md | 2 +- docs/zh-cn/API-reference.md | 4 ++-- docs/zh-cn/Plugin.md | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/en/API-reference.md b/docs/en/API-reference.md index 04f5b21b..a5420977 100644 --- a/docs/en/API-reference.md +++ b/docs/en/API-reference.md @@ -388,6 +388,6 @@ dayjs('2000-01-01').isLeapYear(); // true ### RelativeTime -`.from`, `.to`, `.fromNow`, `.toNow` to get relative time +`.from` `.to` `.fromNow` `.toNow` to get relative time -plugin [`RelativeTime`](./Plugin.md#relativeTime) +plugin [`RelativeTime`](./Plugin.md#relativetime) diff --git a/docs/en/Plugin.md b/docs/en/Plugin.md index 9912aaff..c76f3318 100644 --- a/docs/en/Plugin.md +++ b/docs/en/Plugin.md @@ -66,7 +66,7 @@ List of added formats: | `x` | 1360013296123 | Unix Timestamp in millisecond | ### RelativeTime - - RelativeTime adds `.from`, `.to`, `.fromNow`, `.toNow` APIs to formats date to relative time strings (e.g. 3 hours ago). + - RelativeTime adds `.from` `.to` `.fromNow` `.toNow` APIs to formats date to relative time strings (e.g. 3 hours ago). ```javascript import relativeTime from 'dayjs/plugin/relativeTime' diff --git a/docs/ja/API-reference.md b/docs/ja/API-reference.md index 65d6bf9a..f86061e8 100644 --- a/docs/ja/API-reference.md +++ b/docs/ja/API-reference.md @@ -461,6 +461,6 @@ dayjs('2000-01-01').isLeapYear(); // true ### RelativeTime -`.from`, `.to`, `.fromNow`, `.toNow` to get relative time +`.from` `.to` `.fromNow` `.toNow` to get relative time -plugin [`RelativeTime`](./Plugin.md#relativeTime) +plugin [`RelativeTime`](./Plugin.md#relativetime) diff --git a/docs/ja/Plugin.md b/docs/ja/Plugin.md index d2face27..1c3836f1 100644 --- a/docs/ja/Plugin.md +++ b/docs/ja/Plugin.md @@ -67,7 +67,7 @@ dayjs().format('Q Do k kk X x') | `x` | 1360013296123 | Unix タイムスタンプ (ミリ秒) | ### RelativeTime - - RelativeTime adds `.from`, `.to`, `.fromNow`, `.toNow` APIs to formats date to relative time strings (e.g. 3 hours ago). + - RelativeTime adds `.from` `.to` `.fromNow` `.toNow` APIs to formats date to relative time strings (e.g. 3 hours ago). ```javascript import relativeTime from 'dayjs/plugin/relativeTime' diff --git a/docs/pt-br/API-reference.md b/docs/pt-br/API-reference.md index 2072f1a9..ec54d62b 100644 --- a/docs/pt-br/API-reference.md +++ b/docs/pt-br/API-reference.md @@ -439,6 +439,6 @@ dayjs('2000-01-01').isLeapYear(); // true ### RelativeTime -`.from`, `.to`, `.fromNow`, `.toNow` to get relative time +`.from` `.to` `.fromNow` `.toNow` to get relative time -plugin [`RelativeTime`](./Plugin.md#relativeTime) +plugin [`RelativeTime`](./Plugin.md#relativetime) diff --git a/docs/pt-br/Plugin.md b/docs/pt-br/Plugin.md index f61f8f8c..f67d2c67 100644 --- a/docs/pt-br/Plugin.md +++ b/docs/pt-br/Plugin.md @@ -66,7 +66,7 @@ Lista de formatos adicionados: | `x` | 1360013296123 | Unix Timestamp em milissegundos | ### RelativeTime - - RelativeTime adds `.from`, `.to`, `.fromNow`, `.toNow` APIs to formats date to relative time strings (e.g. 3 hours ago). + - RelativeTime adds `.from` `.to` `.fromNow` `.toNow` APIs to formats date to relative time strings (e.g. 3 hours ago). ```javascript import relativeTime from 'dayjs/plugin/relativeTime' diff --git a/docs/zh-cn/API-reference.md b/docs/zh-cn/API-reference.md index e060c2d4..52519402 100644 --- a/docs/zh-cn/API-reference.md +++ b/docs/zh-cn/API-reference.md @@ -336,6 +336,6 @@ dayjs('2000-01-01').isLeapYear(); // true ### 相对时间 -`.from`, `.to`, `.fromNow`, `.toNow` 获得相对时间 +`.from` `.to` `.fromNow` `.toNow` 获得相对时间 -插件 [`RelativeTime`](./Plugin.md#relativeTime) \ No newline at end of file +插件 [`RelativeTime`](./Plugin.md#relativetime) \ No newline at end of file diff --git a/docs/zh-cn/Plugin.md b/docs/zh-cn/Plugin.md index 54f3a458..810d2f2c 100644 --- a/docs/zh-cn/Plugin.md +++ b/docs/zh-cn/Plugin.md @@ -66,7 +66,7 @@ dayjs().format('Q Do k kk X x') | `x` | 1360013296123 | 毫秒单位的Unix时间戳 | ### RelativeTime - - RelativeTime 增加了 `.from`, `.to`, `.fromNow`, `.toNow` 4个 API 来展示相对的时间 (e.g. 3 小时以前). + - RelativeTime 增加了 `.from` `.to` `.fromNow` `.toNow` 4个 API 来展示相对的时间 (e.g. 3 小时以前). ```javascript import relativeTime from 'dayjs/plugin/relativeTime' From 96f7c8d82fbff8980cb6ccd3ff1d79a6322c0a3c Mon Sep 17 00:00:00 2001 From: andrewhood125ruhuc Date: Tue, 13 Aug 2024 00:28:12 +0800 Subject: [PATCH 18/18] test: update name --- test/plugin/relativeTime.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/plugin/relativeTime.js b/test/plugin/relativeTime.js index f572bfd7..2bc4a896 100644 --- a/test/plugin/relativeTime.js +++ b/test/plugin/relativeTime.js @@ -1,9 +1,9 @@ import MockDate from 'mockdate' import moment from 'moment' import dayjs from '../../src' -import distanceInWords from '../../src/plugin/relativeTime' +import relativeTime from '../../src/plugin/relativeTime' -dayjs.extend(distanceInWords) +dayjs.extend(relativeTime) beforeEach(() => { MockDate.set(new Date('2018-04-04T16:00:00.000Z'))