From 9a03252bc2d363142abc7385349560d3f37fc48d Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 09:49:54 +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 2598369e9..58312ea33 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 2b0e0b39d..da05f219e 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 6480ebd23..29c79e11c 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 fc1aa9c04..ac890d762 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 43b4aa6c57876154a9884d3c3bd7ae45cf42cc1b Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 11:05:23 +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 0820ee25a..1af94b053 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 a909cd258..1ac51e431 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 2e8ca364a..df3709fae 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 fc3ec3d6ed56bfd8c5d1072d5f0fcbac3e695e1e Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 11:08:24 +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 65b5bc75e..c8a3fea52 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 af302ee39ce6b54e63d2243e595f57357e839a85 Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 11:11:01 +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 50b7d275c..c3f1cb83d 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 968ab63b3..fff7f3124 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 edef5e479..8fe610a74 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 a13b87272..73a0a0612 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 646e5095fb0f686c15b01f9e5f53aea4d485fc28 Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 11:17:40 +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 c8a3fea52..a5e08fda6 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 c09adeb04709ffbdba6f68e4dba80fcaf824fbca Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 11:28:59 +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 df3709fae..f572bfd7e 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 e2ac2895cbde5e2a5ddfc6fe001af6cbe7831456 Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 13:51:04 +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 66e7430ed..2d6504589 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 0c28fa194..c82de8684 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 3a140eed7..a24528565 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 bbb351e09..b14b5475d 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 ac445c618c3968eaadc30340c8d34d67f6a022cf Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 13:54:05 +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 fb91e5cfb..399dd4a42 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 2d6504589..06ac5d26f 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 23b71fce2..aaf1fb895 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 5cf73613e..1d01f2db4 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 224a84772..b110642dd 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 732b7a21dfb55bd5ba4336fbc98ec7d00ed8f8c4 Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 13:58:02 +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 f21edf1ee..59ac77f3d 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 562ea13fe3120501c1905282eee3bbdd1fd3a4c3 Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 13:59:41 +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 f896be9ae..491be003d 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 5bc49bc6c58d7f701b44a22abb4108b4cddd02fa Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 14:02:02 +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 491be003d..2bd566789 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 6f16f3446..a97d94df3 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 ca3f125e3..e9f5e5144 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 59ac77f3d..9618a116a 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 eecbdd9ffa72820830a308a62529c9e5ffa1d995 Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 14:18:15 +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 c3f1cb83d..fe440702e 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 947e076193188604f83300c3585323b4ad222f57 Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 14:20:19 +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 fff7f3124..bbc0eff33 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 8fe610a74..6846061e4 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 73a0a0612..ce0aada2c 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 637d7273ea7922d1157229042b137d93283c891d Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 14:28:41 +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 06ac5d26f..0ce511e01 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 b8b9f581600525643b8079baf8e18b6ae25966c6 Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 14:38:51 +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 0ce511e01..9912aaff5 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 c82de8684..d2face278 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 a24528565..f61f8f8c1 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 b14b5475d..54f3a4585 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 3267660e3b691105535d1c97eaaaa615621704d9 Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 14:44:26 +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 2bd566789..04f5b21bb 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 a97d94df3..65d6bf9a3 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 e9f5e5144..2072f1a9e 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 9618a116a..e060c2d4b 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 65ad74869f0addfa82e1944570aa87c77ea8849a Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 14:51:58 +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 04f5b21bb..a5420977f 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 9912aaff5..c76f33182 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 65d6bf9a3..f86061e87 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 d2face278..1c3836f1e 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 2072f1a9e..ec54d62b2 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 f61f8f8c1..f67d2c67e 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 e060c2d4b..525194024 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 54f3a4585..810d2f2c9 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 930cf3c5e5c764fbc72100eeb37fcf3bf6b90796 Mon Sep 17 00:00:00 2001 From: iamkun Date: Fri, 25 May 2018 14:54:04 +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 f572bfd7e..2bc4a896e 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'))