From 669141cdca0468a04329ce7c723ad71e6f43c77d Mon Sep 17 00:00:00 2001
From: iamkun
Date: Tue, 15 May 2018 16:36:56 +0800
Subject: [PATCH 01/23] docs: change link
---
README.md | 6 +++---
README.zh-CN.md | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index 0b74d1a8c..d40721d30 100644
--- a/README.md
+++ b/README.md
@@ -6,8 +6,8 @@ English | [简体中文](./README.zh-CN.md)
Fast 2kB alternative to Moment.js with the same modern API
- 
@@ -64,7 +64,7 @@ dayjs().format();
* Via download and self-hosting:
-Just download the latest version of Day.js at [https://unpkg.com/dayjs/dist/](https://unpkg.com/dayjs/dist/)
+Just download the latest version of Day.js at [https://unpkg.com/dayjs/](https://unpkg.com/dayjs/)
## Getting Started
diff --git a/README.zh-CN.md b/README.zh-CN.md
index a9f18193e..c456ee934 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -5,8 +5,8 @@
Moment.js 的 2kB 轻量化方案,拥有同样强大的 API
- 
@@ -58,7 +58,7 @@ dayjs().format();
- 下载到您自己的服务器上:
-从 [https://unpkg.com/dayjs/dist/](https://unpkg.com/dayjs/dist/) 下载最新的 Dayjs 源文件,并自行部署到您的服务器上。
+从 [https://unpkg.com/dayjs/](https://unpkg.com/dayjs/) 下载最新的 Dayjs 源文件,并自行部署到您的服务器上。
## 开始
`Dayjs` 并没有改变或覆盖 Javascript 原生的 `Date.prototype`, 而是创造了一个全新的包含 `Javascript Date` 对象的 `Dayjs` 的对象。
From f89d70720da6628344bfd5bb2795eacfa51c2657 Mon Sep 17 00:00:00 2001
From: iamkun
Date: Tue, 15 May 2018 16:39:17 +0800
Subject: [PATCH 02/23] chore: update npmignore
---
.npmignore | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/.npmignore b/.npmignore
index 7b67ff777..95bbbcd06 100644
--- a/.npmignore
+++ b/.npmignore
@@ -15,4 +15,11 @@ coverage
# dev
src
test
-build
\ No newline at end of file
+build
+
+#doc
+CONTRIBUTING.md
+
+#other
+.travis.yml
+karma.sauce.conf.js
\ No newline at end of file
From f2cf2254ac9b20f7d9d6b0f279a8fb177c72b3ac Mon Sep 17 00:00:00 2001
From: iamkun
Date: Tue, 15 May 2018 17:50:29 +0800
Subject: [PATCH 03/23] docs: move api reference to docs folder
---
README.md | 445 +-----------------------------------
README.zh-CN.md | 312 +------------------------
docs/en/API-reference.md | 445 ++++++++++++++++++++++++++++++++++++
docs/zh-cn/API-reference.md | 313 +++++++++++++++++++++++++
4 files changed, 760 insertions(+), 755 deletions(-)
create mode 100644 docs/en/API-reference.md
create mode 100644 docs/zh-cn/API-reference.md
diff --git a/README.md b/README.md
index d40721d30..ef245c38c 100644
--- a/README.md
+++ b/README.md
@@ -73,450 +73,7 @@ Instead of modifying the native `Date.prototype`, Day.js creates a wrapper for t
## API
-API will always return a new `Dayjs` object if not specified.
-
-* [Parse](#parse)
- * [Now](#now)
- * [String](#string)
- * [Unix Timestamp (milliseconds)](#unix-timestamp-milliseconds)
- * [Date](#date)
- * [Clone](#clone)
- * [Validation](#validation)
-* [Get + Set](#get--set)
- * [Year](#year)
- * [Month](#month)
- * [Date of Month](#date-of-month)
- * [Day of Week](#day-of-week)
- * [Hour](#hour)
- * [Minute](#minute)
- * [Second](#second)
- * [Millisecond](#millisecond)
- * [Set](#set)
-* [Manipulate](#manipulate)
- * [Add](#add)
- * [Subtract](#subtract)
- * [Start of Time](#start-of-time)
- * [End of Time](#end-of-time)
-* [Display](#display)
- * [Format](#format)
- * [Difference](#difference)
- * [Unix Timestamp (milliseconds)](#unix-timestamp-milliseconds-1)
- * [Unix Timestamp (seconds)](#unix-timestamp-seconds)
- * [Days in Month](#days-in-month)
- * [As Javascript Date](#as-javascript-date)
- * [As Array](#as-array)
- * [As JSON](#as-json)
- * [As ISO 8601 String](#as-iso-8601-string)
- * [As Object](#as-object)
- * [As String](#as-string)
-* [Query](#query)
- * [Is Before](#is-before)
- * [Is Same](#is-same)
- * [Is After](#is-after)
- * [Is Leap Year](#is-leap-year)
-
----
-
-### Parse
-
-Simply call `dayjs()` with one of the supported input types.
-
-#### Now
-
-To get the current date and time, just call dayjs() with no parameters.
-
-```js
-dayjs();
-```
-
-### String
-
-Creating from a string matches [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
-
-```js
-dayjs(String);
-dayjs('1995-12-25');
-```
-
-### Unix Timestamp (milliseconds)
-
-Passing an integer value representing the number of milliseconds since the Unix Epoch (Jan 1 1970 12AM UTC).
-
-```js
-dayjs(Number);
-dayjs(1318781876406);
-```
-
-### Date
-
-Passing a pre-existing native Javascript Date object.
-
-```js
-dayjs(Date);
-dayjs(new Date(2018, 8, 18));
-```
-
-### Clone
-
-All `Dayjs` are immutable. If you want a copy of the object, just call `.clone()`.
-Calling dayjs() on a `Dayjs` object will also clone it.
-
-```js
-dayjs(Dayjs);
-dayjs().clone();
-```
-
-### Validation
-
-* returns a Boolean
-
-Check whether the `Dayjs` object considers the date invalid.
-
-```js
-dayjs().isValid();
-```
-
----
-
-### Get + Set
-
-Get and set date.
-
-#### Year
-
-* returns a Number
-
-Get year.
-
-```js
-dayjs().year();
-```
-
-#### Month
-
-* returns a Number
-
-Get month.
-
-```js
-dayjs().month();
-```
-
-#### Date of Month
-
-* returns a Number
-
-Get day of the month.
-
-```js
-dayjs().date();
-```
-
-#### Day of Week
-
-* returns a Number
-
-Get day of the week.
-
-```js
-dayjs().day();
-```
-
-#### Hour
-
-* returns a Number
-
-Get hour.
-
-```js
-dayjs().hour();
-```
-
-#### Minute
-
-* returns a Number
-
-Get minute.
-
-```js
-dayjs().minute();
-```
-
-#### Second
-
-* returns a Number
-
-Get second.
-
-```js
-dayjs().second();
-```
-
-#### Millisecond
-
-* returns a Number
-
-Get millisecond.
-
-```js
-dayjs().millisecond();
-```
-
-#### Set
-
-Date setter.
-Units are case insensitive
-
-```js
-dayjs().set((unit: String), (value: Int));
-dayjs().set('month', 3); // April
-dayjs().set('second', 30);
-```
-
----
-
-### Manipulate
-
-Once you have a `Dayjs` object, you may want to manipulate it in some way like this:
-
-```js
-dayjs()
- .startOf('month')
- .add(1, 'day')
- .subtract(1, 'year');
-```
-
-#### Add
-
-Returns a new `Dayjs` object by adding time.
-
-```js
-dayjs().add((value: Number), (unit: String));
-dayjs().add(7, 'day');
-```
-
-#### Subtract
-
-Returns a new `Dayjs` object by subtracting time. exactly the same as `dayjs#add`.
-
-```js
-dayjs().subtract((value: Number), (unit: String));
-dayjs().subtract(7, 'year');
-```
-
-#### Start of Time
-
-Returns a new `Dayjs` object by by setting it to the start of a unit of time.
-
-```js
-dayjs().startOf((unit: String));
-dayjs().startOf('year');
-```
-
-#### End of Time
-
-Returns a new `Dayjs` object by by setting it to the end of a unit of time.
-
-```js
-dayjs().endOf((unit: String));
-dayjs().endOf('month');
-```
-
----
-
-### Display
-
-Once parsing and manipulation are done, you need some way to display the `Dayjs` object.
-
-#### Format
-
-* returns a String
-
-Takes a string of tokens and replaces them with their corresponding date values.
-
-```js
-dayjs().format(String);
-dayjs().format(); // "2014-09-08T08:02:17-05:00" (ISO 8601, no fractional seconds)
-dayjs().format('{YYYY} MM-DDTHH:mm:ssZ[Z]'); // "{2014} 09-08T08:02:17-05:00Z"
-```
-
-* To escape characters in string, wrap the characters in square brackets (e.g. [Z]).
-
-List of all available formats:
-
-| Format | Output | Description |
-| ------ | ---------------- | ------------------------------------- |
-| `YY` | 18 | Two-digit year |
-| `YYYY` | 2018 | Four-digit year |
-| `M` | 1-12 | The month, beginning at 1 |
-| `MM` | 01-12 | The month, 2-digits |
-| `MMM` | Jan-Dec | The abbreviated month name |
-| `MMMM` | January-December | The full month name |
-| `D` | 1-31 | The day of the month |
-| `DD` | 01-31 | The day of the month, 2-digits |
-| `d` | 0-6 | The day of the week, with Sunday as 0 |
-| `dddd` | Sunday-Saturday | The name of the day of the week |
-| `H` | 0-23 | The hour |
-| `HH` | 00-23 | The hour, 2-digits |
-| `h` | 1-12 | The hour, 12-hour clock |
-| `hh` | 01-12 | The hour, 12-hour clock, 2-digits |
-| `m` | 0-59 | The minute |
-| `mm` | 00-59 | The minute, 2-digits |
-| `s` | 0-59 | The second |
-| `ss` | 00-59 | The second, 2-digits |
-| `SSS` | 000-999 | The millisecond, 3-digits |
-| `Z` | +5:00 | The offset from UTC |
-| `ZZ` | +0500 | The offset from UTC, 2-digits |
-| `A` | AM PM | |
-| `a` | am pm | |
-
-#### Difference
-
-* returns a Number
-
-Get the difference of two `Dayjs` objects in milliseconds or another unit.
-
-```js
-dayjs().diff(Dayjs, unit);
-dayjs().diff(dayjs(), 'years'); // 0
-```
-
-#### Unix Timestamp (milliseconds)
-
-* returns a Number
-
-Outputs the number of milliseconds since the Unix Epoch
-
-```js
-dayjs().valueOf();
-```
-
-#### Unix Timestamp (seconds)
-
-* returns a Number
-
-Outputs a Unix timestamp (the number of seconds since the Unix Epoch).
-
-```js
-dayjs().unix();
-```
-
-#### Days in Month
-
-* returns a Number
-
-Get the number of days in the current month.
-
-```js
-dayjs().daysInMonth();
-```
-
-#### As Javascript Date
-
-* returns a Javascript `Date` object
-
-Get copy of the native `Date` object from `Dayjs` object.
-
-```js
-dayjs().toDate();
-```
-
-#### As Array
-
-* returns an Array
-
-Returns an array that mirrors the parameters from new Date().
-
-```js
-dayjs().toArray(); //[2018, 8, 18, 00, 00, 00, 000];
-```
-
-#### As JSON
-
-* returns a JSON String
-
-Serializing a `Dayjs` object to JSON, will return an ISO8601 string.
-
-```js
-dayjs().toJSON(); //"2018-08-08T00:00:00.000Z"
-```
-
-#### As ISO 8601 String
-
-* returns a String
-
-Formats a string to the ISO8601 standard.
-
-```js
-dayjs().toISOString();
-```
-
-#### As Object
-
-* returns an Object
-
-Returns an object with year, month ... millisecond.
-
-```js
-dayjs().toObject(); // { years:2018, months:8, date:18, hours:0, minutes:0, seconds:0, milliseconds:0}
-```
-
-#### As String
-
-* returns a String
-
-```js
-dayjs().toString();
-```
-
----
-
-### Query
-
-#### Is Before
-
-* returns a Boolean
-
-Check if a `Dayjs` object is before another `Dayjs` object.
-
-```js
-dayjs().isBefore(Dayjs);
-dayjs().isBefore(dayjs()); // false
-```
-
-#### Is Same
-
-* returns a Boolean
-
-Check if a `Dayjs` object is same as another `Dayjs` object.
-
-```js
-dayjs().isSame(Dayjs);
-dayjs().isSame(dayjs()); // true
-```
-
-#### Is After
-
-* returns a Boolean
-
-Check if a `Dayjs` object is after another `Dayjs` object.
-
-```js
-dayjs().isAfter(Dayjs);
-dayjs().isAfter(dayjs()); // false
-```
-
-#### Is Leap Year
-
-* returns a Boolean
-
-Check if a year is a leap year.
-
-```js
-dayjs().isLeapYear();
-dayjs('2000-01-01').isLeapYear(); // true
-```
-
+[API Reference](./docs/en/API-reference.md)
---
## License
diff --git a/README.zh-CN.md b/README.zh-CN.md
index c456ee934..42fa62b1c 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -67,318 +67,8 @@ dayjs().format();
## API
-如果没有特别说明,API 的返回值都是新的 `Dayjs` 对象。
-* [解析](#解析)
- * [当前时间](#当前时间)
- * [时间字符串](#时间字符串)
- * [Unix 时间戳 (毫秒)](#unix-时间戳-毫秒)
- * [Date 对象](#date-对象)
- * [复制](#复制)
- * [验证](#验证)
-* [获取+设置](#获取设置)
- * [年](#年)
- * [月](#月)
- * [日](#日)
- * [时](#时)
- * [分](#分)
- * [秒](#秒)
- * [毫秒](#毫秒)
- * [设置](#设置)
-* [操作](#操作)
- * [增加](#增加)
- * [减少](#减少)
- * [开头时间](#开头时间)
- * [末尾时间](#末尾时间)
-* [显示](#显示)
- * [格式化](#格式化)
- * [时间差](#时间差)
- * [Unix 时间戳 (毫秒)](#unix-时间戳-毫秒-1)
- * [Unix 时间戳 (秒)](#unix-时间戳-秒)
- * [天数 (月)](#天数-月)
- * [Date 对象](#date-对象-1)
- * [数组](#数组)
- * [JSON](#as-json)
- * [ISO 8601 字符串](#iso-8601-字符串)
- * [对象](#对象)
- * [字符串](#字符串)
-* [查询](#查询)
- * [是否之前](#是否之前)
- * [是否相同](#是否相同)
- * [是否之后](#是否之后)
- * [是否闰年](#是否闰年)
-
----
-### 解析
-在 `dayjs()` 中传入支持的格式
-#### 当前时间
-直接运行 `dayjs()`,得到包含当前时间和日期的 `Dayjs` 对象。
-```js
-dayjs();
-```
-### 时间字符串
-可以解析传入的一个标准的[ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)时间字符串。
-```js
-dayjs(String);
-dayjs("1995-12-25");
-```
-### Unix 时间戳 (毫秒)
-可以解析传入的一个 Unix 时间戳 (13位数字)。
-```js
-dayjs(Number);
-dayjs(1318781876406);
-```
-### Date 对象
-可以解析传入的一个 Javascript Date 对象。
-```js
-dayjs(Date);
-dayjs(new Date(2018, 8, 18));
-```
-### 复制
-`Dayjs` 对象是不可变的,如果你想获得一个对象的拷贝,请执行 `.clone()`。
-向 `dayjs()` 里传入一个 `Dayjs` 对象也能实现同样的效果。
-```js
-dayjs(Dayjs);
-dayjs().clone();
-```
-### 验证
-- return Boolean
-
-检测当前 `Dayjs` 对象是否是一个有效的时间。
-```js
-dayjs().isValid();
-```
----
-### 获取+设置
-获取和改变日期。
-#### 年
-- return Number
-
-获取年份。
-```js
-dayjs().year();
-```
-#### 月
-- return Number
-
-获取月份。
-```js
-dayjs().month();
-```
-#### 日
-- return Number
-
-获取日期。
-```js
-dayjs().date();
-```
-#### 时
-- return Number
-
-获取小时。
-```js
-dayjs().hour();
-```
-#### 分
-- return Number
-
-获取分钟。
-```js
-dayjs().minute();
-```
-#### 秒
-- return Number
-
-获取秒。
-```js
-dayjs().second();
-```
-#### 毫秒
-- return Number
-
-获取毫秒。
-```js
-dayjs().millisecond();
-```
-#### 设置
-设置时间
-传入的单位 (unit) 对大小写不敏感。
-```js
-dayjs().set(unit : String, value : Int);
-dayjs().set('month', 3); // April
-dayjs().set('second', 30);
-```
----
-### 操作
-你可以对 `Dayjs` 对象如下增加减少之类的操作:
-```js
-dayjs().startOf('month').add(1, 'day').subtract(1, 'year')
-```
-#### 增加
-增加时间并返回一个新的 `Dayjs()` 对象。
-```js
-dayjs().add(value : Number, unit : String);
-dayjs().add(7, 'day');
-```
-#### 减少
-减少时间并返回一个新的 `Dayjs()` 对象,使用方法和 `dayjs#add` 相同。
-```js
-dayjs().subtract(value : Number, unit : String);
-dayjs().subtract(7, 'year');
-```
-#### 开头时间
-返回当前时间的开头时间的 `Dayjs()` 对象,如月份的第一天。
-```js
-dayjs().startOf(unit : String);
-dayjs().startOf('year');
-```
-#### 末尾时间
-返回当前时间的末尾时间的 `Dayjs()` 对象,如月份的最后一天。
-```js
-dayjs().endOf(unit : String);
-dayjs().endOf('month');
-```
----
-### 显示
-格式化 `Dayjs` 对象并展示。
-#### 格式化
-- return String
-
-接收一系列的时间日期字符串并替换成相应的值。
-
-```js
-dayjs().format(String);
-dayjs().format(); // "2014-09-08T08:02:17-05:00" (ISO 8601, no fractional seconds)
-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 |
-
-#### 时间差
-- return Number
-
-获取两个 `Dayjs` 对象的时间差,默认毫秒。
-```js
-dayjs().diff(Dayjs, unit);
-dayjs().diff(dayjs(), 'years'); // 0
-```
-#### Unix 时间戳 (毫秒)
-- return Number
-
-返回 Unix 时间戳 (毫秒)
-```js
-dayjs().valueOf();
-```
-#### Unix 时间戳 (秒)
-- return Number
-
-返回 Unix 时间戳 (秒)。
-```js
-dayjs().unix();
-```
-#### 天数 (月)
-- return Number
-
-返回月份的天数。
-```js
-dayjs().daysInMonth();
-```
-#### Date 对象
-- return Javascript `Date` object
-
-返回原生的 `Date` 对象。
-```js
-dayjs().toDate();
-```
-#### 数组
-- return Array
-
-返回包含时间数值的数组。
-```js
-dayjs().toArray(); //[2018, 8, 18, 00, 00, 00, 000];
-```
-#### As JSON
-- return JSON String
-
-当序列化 `Dayjs` 对象时,会返回 ISO8601 格式的字符串。
-```js
-dayjs().toJSON(); //"2018-08-08T00:00:00.000Z"
-```
-#### ISO 8601 字符串
-- return String
-
-返回 ISO8601 格式的字符串。
-```js
-dayjs().toISOString();
-```
-#### 对象
-- return Object
-
-返回包含时间数值的对象。
-```js
-dayjs().toObject();// { years:2018, months:8, date:18, hours:0, minutes:0, seconds:0, milliseconds:0}
-```
-#### 字符串
-- return String
-
-```js
-dayjs().toString();
-```
----
-### 查询
-#### 是否之前
-- return Boolean
-
-检查一个 `Dayjs` 对象是否在另一个 `Dayjs` 对象时间之前。
-```js
-dayjs().isBefore(Dayjs);
-dayjs().isBefore(dayjs()); // false
-```
-#### 是否相同
-- return Boolean
-
-检查一个 `Dayjs` 对象是否和另一个 `Dayjs` 对象时间相同。
-```js
-dayjs().isSame(Dayjs);
-dayjs().isSame(dayjs()); // true
-```
-#### 是否之后
-- return Boolean
-
-检查一个 `Dayjs` 对象是否在另一个 `Dayjs` 对象时间之后。
-```js
-dayjs().isAfter(Dayjs);
-dayjs().isAfter(dayjs()); // false
-```
-#### 是否闰年
-- return Boolean
-
-是否闰年。
-```js
-dayjs().isLeapYear();
-dayjs('2000-01-01').isLeapYear(); // true
-```
+[API 文档](./docs/zh-cn/API-reference.md)
---
## 开源协议
diff --git a/docs/en/API-reference.md b/docs/en/API-reference.md
new file mode 100644
index 000000000..876aa4499
--- /dev/null
+++ b/docs/en/API-reference.md
@@ -0,0 +1,445 @@
+## API Reference
+
+Day.js will always return a new `Dayjs` object if not specified.
+
+* [Parse](#parse)
+ * [Now](#now)
+ * [String](#string)
+ * [Unix Timestamp (milliseconds)](#unix-timestamp-milliseconds)
+ * [Date](#date)
+ * [Clone](#clone)
+ * [Validation](#validation)
+* [Get + Set](#get--set)
+ * [Year](#year)
+ * [Month](#month)
+ * [Date of Month](#date-of-month)
+ * [Day of Week](#day-of-week)
+ * [Hour](#hour)
+ * [Minute](#minute)
+ * [Second](#second)
+ * [Millisecond](#millisecond)
+ * [Set](#set)
+* [Manipulate](#manipulate)
+ * [Add](#add)
+ * [Subtract](#subtract)
+ * [Start of Time](#start-of-time)
+ * [End of Time](#end-of-time)
+* [Display](#display)
+ * [Format](#format)
+ * [Difference](#difference)
+ * [Unix Timestamp (milliseconds)](#unix-timestamp-milliseconds-1)
+ * [Unix Timestamp (seconds)](#unix-timestamp-seconds)
+ * [Days in Month](#days-in-month)
+ * [As Javascript Date](#as-javascript-date)
+ * [As Array](#as-array)
+ * [As JSON](#as-json)
+ * [As ISO 8601 String](#as-iso-8601-string)
+ * [As Object](#as-object)
+ * [As String](#as-string)
+* [Query](#query)
+ * [Is Before](#is-before)
+ * [Is Same](#is-same)
+ * [Is After](#is-after)
+ * [Is Leap Year](#is-leap-year)
+
+---
+
+### Parse
+
+Simply call `dayjs()` with one of the supported input types.
+
+#### Now
+
+To get the current date and time, just call dayjs() with no parameters.
+
+```js
+dayjs();
+```
+
+### String
+
+Creating from a string matches [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
+
+```js
+dayjs(String);
+dayjs('1995-12-25');
+```
+
+### Unix Timestamp (milliseconds)
+
+Passing an integer value representing the number of milliseconds since the Unix Epoch (Jan 1 1970 12AM UTC).
+
+```js
+dayjs(Number);
+dayjs(1318781876406);
+```
+
+### Date
+
+Passing a pre-existing native Javascript Date object.
+
+```js
+dayjs(Date);
+dayjs(new Date(2018, 8, 18));
+```
+
+### Clone
+
+All `Dayjs` are immutable. If you want a copy of the object, just call `.clone()`.
+Calling dayjs() on a `Dayjs` object will also clone it.
+
+```js
+dayjs(Dayjs);
+dayjs().clone();
+```
+
+### Validation
+
+* returns a Boolean
+
+Check whether the `Dayjs` object considers the date invalid.
+
+```js
+dayjs().isValid();
+```
+
+---
+
+### Get + Set
+
+Get and set date.
+
+#### Year
+
+* returns a Number
+
+Get year.
+
+```js
+dayjs().year();
+```
+
+#### Month
+
+* returns a Number
+
+Get month.
+
+```js
+dayjs().month();
+```
+
+#### Date of Month
+
+* returns a Number
+
+Get day of the month.
+
+```js
+dayjs().date();
+```
+
+#### Day of Week
+
+* returns a Number
+
+Get day of the week.
+
+```js
+dayjs().day();
+```
+
+#### Hour
+
+* returns a Number
+
+Get hour.
+
+```js
+dayjs().hour();
+```
+
+#### Minute
+
+* returns a Number
+
+Get minute.
+
+```js
+dayjs().minute();
+```
+
+#### Second
+
+* returns a Number
+
+Get second.
+
+```js
+dayjs().second();
+```
+
+#### Millisecond
+
+* returns a Number
+
+Get millisecond.
+
+```js
+dayjs().millisecond();
+```
+
+#### Set
+
+Date setter.
+Units are case insensitive
+
+```js
+dayjs().set((unit: String), (value: Int));
+dayjs().set('month', 3); // April
+dayjs().set('second', 30);
+```
+
+---
+
+### Manipulate
+
+Once you have a `Dayjs` object, you may want to manipulate it in some way like this:
+
+```js
+dayjs()
+ .startOf('month')
+ .add(1, 'day')
+ .subtract(1, 'year');
+```
+
+#### Add
+
+Returns a new `Dayjs` object by adding time.
+
+```js
+dayjs().add((value: Number), (unit: String));
+dayjs().add(7, 'day');
+```
+
+#### Subtract
+
+Returns a new `Dayjs` object by subtracting time. exactly the same as `dayjs#add`.
+
+```js
+dayjs().subtract((value: Number), (unit: String));
+dayjs().subtract(7, 'year');
+```
+
+#### Start of Time
+
+Returns a new `Dayjs` object by by setting it to the start of a unit of time.
+
+```js
+dayjs().startOf((unit: String));
+dayjs().startOf('year');
+```
+
+#### End of Time
+
+Returns a new `Dayjs` object by by setting it to the end of a unit of time.
+
+```js
+dayjs().endOf((unit: String));
+dayjs().endOf('month');
+```
+
+---
+
+### Display
+
+Once parsing and manipulation are done, you need some way to display the `Dayjs` object.
+
+#### Format
+
+* returns a String
+
+Takes a string of tokens and replaces them with their corresponding date values.
+
+```js
+dayjs().format(String);
+dayjs().format(); // "2014-09-08T08:02:17-05:00" (ISO 8601, no fractional seconds)
+dayjs().format('{YYYY} MM-DDTHH:mm:ssZ[Z]'); // "{2014} 09-08T08:02:17-05:00Z"
+```
+
+* To escape characters in string, wrap the characters in square brackets (e.g. [Z]).
+
+List of all available formats:
+
+| Format | Output | Description |
+| ------ | ---------------- | ------------------------------------- |
+| `YY` | 18 | Two-digit year |
+| `YYYY` | 2018 | Four-digit year |
+| `M` | 1-12 | The month, beginning at 1 |
+| `MM` | 01-12 | The month, 2-digits |
+| `MMM` | Jan-Dec | The abbreviated month name |
+| `MMMM` | January-December | The full month name |
+| `D` | 1-31 | The day of the month |
+| `DD` | 01-31 | The day of the month, 2-digits |
+| `d` | 0-6 | The day of the week, with Sunday as 0 |
+| `dddd` | Sunday-Saturday | The name of the day of the week |
+| `H` | 0-23 | The hour |
+| `HH` | 00-23 | The hour, 2-digits |
+| `h` | 1-12 | The hour, 12-hour clock |
+| `hh` | 01-12 | The hour, 12-hour clock, 2-digits |
+| `m` | 0-59 | The minute |
+| `mm` | 00-59 | The minute, 2-digits |
+| `s` | 0-59 | The second |
+| `ss` | 00-59 | The second, 2-digits |
+| `SSS` | 000-999 | The millisecond, 3-digits |
+| `Z` | +5:00 | The offset from UTC |
+| `ZZ` | +0500 | The offset from UTC, 2-digits |
+| `A` | AM PM | |
+| `a` | am pm | |
+
+#### Difference
+
+* returns a Number
+
+Get the difference of two `Dayjs` objects in milliseconds or another unit.
+
+```js
+dayjs().diff(Dayjs, unit);
+dayjs().diff(dayjs(), 'years'); // 0
+```
+
+#### Unix Timestamp (milliseconds)
+
+* returns a Number
+
+Outputs the number of milliseconds since the Unix Epoch
+
+```js
+dayjs().valueOf();
+```
+
+#### Unix Timestamp (seconds)
+
+* returns a Number
+
+Outputs a Unix timestamp (the number of seconds since the Unix Epoch).
+
+```js
+dayjs().unix();
+```
+
+#### Days in Month
+
+* returns a Number
+
+Get the number of days in the current month.
+
+```js
+dayjs().daysInMonth();
+```
+
+#### As Javascript Date
+
+* returns a Javascript `Date` object
+
+Get copy of the native `Date` object from `Dayjs` object.
+
+```js
+dayjs().toDate();
+```
+
+#### As Array
+
+* returns an Array
+
+Returns an array that mirrors the parameters from new Date().
+
+```js
+dayjs().toArray(); //[2018, 8, 18, 00, 00, 00, 000];
+```
+
+#### As JSON
+
+* returns a JSON String
+
+Serializing a `Dayjs` object to JSON, will return an ISO8601 string.
+
+```js
+dayjs().toJSON(); //"2018-08-08T00:00:00.000Z"
+```
+
+#### As ISO 8601 String
+
+* returns a String
+
+Formats a string to the ISO8601 standard.
+
+```js
+dayjs().toISOString();
+```
+
+#### As Object
+
+* returns an Object
+
+Returns an object with year, month ... millisecond.
+
+```js
+dayjs().toObject(); // { years:2018, months:8, date:18, hours:0, minutes:0, seconds:0, milliseconds:0}
+```
+
+#### As String
+
+* returns a String
+
+```js
+dayjs().toString();
+```
+
+---
+
+### Query
+
+#### Is Before
+
+* returns a Boolean
+
+Check if a `Dayjs` object is before another `Dayjs` object.
+
+```js
+dayjs().isBefore(Dayjs);
+dayjs().isBefore(dayjs()); // false
+```
+
+#### Is Same
+
+* returns a Boolean
+
+Check if a `Dayjs` object is same as another `Dayjs` object.
+
+```js
+dayjs().isSame(Dayjs);
+dayjs().isSame(dayjs()); // true
+```
+
+#### Is After
+
+* returns a Boolean
+
+Check if a `Dayjs` object is after another `Dayjs` object.
+
+```js
+dayjs().isAfter(Dayjs);
+dayjs().isAfter(dayjs()); // false
+```
+
+#### Is Leap Year
+
+* returns a Boolean
+
+Check if a year is a leap year.
+
+```js
+dayjs().isLeapYear();
+dayjs('2000-01-01').isLeapYear(); // true
+```
diff --git a/docs/zh-cn/API-reference.md b/docs/zh-cn/API-reference.md
new file mode 100644
index 000000000..119c6c515
--- /dev/null
+++ b/docs/zh-cn/API-reference.md
@@ -0,0 +1,313 @@
+## API
+如果没有特别说明,Day.js 的返回值都是新的 `Dayjs` 对象。
+
+* [解析](#解析)
+ * [当前时间](#当前时间)
+ * [时间字符串](#时间字符串)
+ * [Unix 时间戳 (毫秒)](#unix-时间戳-毫秒)
+ * [Date 对象](#date-对象)
+ * [复制](#复制)
+ * [验证](#验证)
+* [获取+设置](#获取设置)
+ * [年](#年)
+ * [月](#月)
+ * [日](#日)
+ * [时](#时)
+ * [分](#分)
+ * [秒](#秒)
+ * [毫秒](#毫秒)
+ * [设置](#设置)
+* [操作](#操作)
+ * [增加](#增加)
+ * [减少](#减少)
+ * [开头时间](#开头时间)
+ * [末尾时间](#末尾时间)
+* [显示](#显示)
+ * [格式化](#格式化)
+ * [时间差](#时间差)
+ * [Unix 时间戳 (毫秒)](#unix-时间戳-毫秒-1)
+ * [Unix 时间戳 (秒)](#unix-时间戳-秒)
+ * [天数 (月)](#天数-月)
+ * [Date 对象](#date-对象-1)
+ * [数组](#数组)
+ * [JSON](#as-json)
+ * [ISO 8601 字符串](#iso-8601-字符串)
+ * [对象](#对象)
+ * [字符串](#字符串)
+* [查询](#查询)
+ * [是否之前](#是否之前)
+ * [是否相同](#是否相同)
+ * [是否之后](#是否之后)
+ * [是否闰年](#是否闰年)
+
+---
+### 解析
+在 `dayjs()` 中传入支持的格式
+#### 当前时间
+直接运行 `dayjs()`,得到包含当前时间和日期的 `Dayjs` 对象。
+```js
+dayjs();
+```
+### 时间字符串
+可以解析传入的一个标准的[ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)时间字符串。
+```js
+dayjs(String);
+dayjs("1995-12-25");
+```
+### Unix 时间戳 (毫秒)
+可以解析传入的一个 Unix 时间戳 (13位数字)。
+```js
+dayjs(Number);
+dayjs(1318781876406);
+```
+### Date 对象
+可以解析传入的一个 Javascript Date 对象。
+```js
+dayjs(Date);
+dayjs(new Date(2018, 8, 18));
+```
+### 复制
+`Dayjs` 对象是不可变的,如果你想获得一个对象的拷贝,请执行 `.clone()`。
+向 `dayjs()` 里传入一个 `Dayjs` 对象也能实现同样的效果。
+```js
+dayjs(Dayjs);
+dayjs().clone();
+```
+### 验证
+- return Boolean
+
+检测当前 `Dayjs` 对象是否是一个有效的时间。
+```js
+dayjs().isValid();
+```
+---
+### 获取+设置
+获取和改变日期。
+#### 年
+- return Number
+
+获取年份。
+```js
+dayjs().year();
+```
+#### 月
+- return Number
+
+获取月份。
+```js
+dayjs().month();
+```
+#### 日
+- return Number
+
+获取日期。
+```js
+dayjs().date();
+```
+#### 时
+- return Number
+
+获取小时。
+```js
+dayjs().hour();
+```
+#### 分
+- return Number
+
+获取分钟。
+```js
+dayjs().minute();
+```
+#### 秒
+- return Number
+
+获取秒。
+```js
+dayjs().second();
+```
+#### 毫秒
+- return Number
+
+获取毫秒。
+```js
+dayjs().millisecond();
+```
+#### 设置
+设置时间
+传入的单位 (unit) 对大小写不敏感。
+```js
+dayjs().set(unit : String, value : Int);
+dayjs().set('month', 3); // April
+dayjs().set('second', 30);
+```
+---
+### 操作
+你可以对 `Dayjs` 对象如下增加减少之类的操作:
+```js
+dayjs().startOf('month').add(1, 'day').subtract(1, 'year')
+```
+#### 增加
+增加时间并返回一个新的 `Dayjs()` 对象。
+```js
+dayjs().add(value : Number, unit : String);
+dayjs().add(7, 'day');
+```
+#### 减少
+减少时间并返回一个新的 `Dayjs()` 对象,使用方法和 `dayjs#add` 相同。
+```js
+dayjs().subtract(value : Number, unit : String);
+dayjs().subtract(7, 'year');
+```
+#### 开头时间
+返回当前时间的开头时间的 `Dayjs()` 对象,如月份的第一天。
+```js
+dayjs().startOf(unit : String);
+dayjs().startOf('year');
+```
+#### 末尾时间
+返回当前时间的末尾时间的 `Dayjs()` 对象,如月份的最后一天。
+```js
+dayjs().endOf(unit : String);
+dayjs().endOf('month');
+```
+---
+### 显示
+格式化 `Dayjs` 对象并展示。
+#### 格式化
+- return String
+
+接收一系列的时间日期字符串并替换成相应的值。
+
+```js
+dayjs().format(String);
+dayjs().format(); // "2014-09-08T08:02:17-05:00" (ISO 8601, no fractional seconds)
+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 |
+
+#### 时间差
+- return Number
+
+获取两个 `Dayjs` 对象的时间差,默认毫秒。
+```js
+dayjs().diff(Dayjs, unit);
+dayjs().diff(dayjs(), 'years'); // 0
+```
+#### Unix 时间戳 (毫秒)
+- return Number
+
+返回 Unix 时间戳 (毫秒)
+```js
+dayjs().valueOf();
+```
+#### Unix 时间戳 (秒)
+- return Number
+
+返回 Unix 时间戳 (秒)。
+```js
+dayjs().unix();
+```
+#### 天数 (月)
+- return Number
+
+返回月份的天数。
+```js
+dayjs().daysInMonth();
+```
+#### Date 对象
+- return Javascript `Date` object
+
+返回原生的 `Date` 对象。
+```js
+dayjs().toDate();
+```
+#### 数组
+- return Array
+
+返回包含时间数值的数组。
+```js
+dayjs().toArray(); //[2018, 8, 18, 00, 00, 00, 000];
+```
+#### As JSON
+- return JSON String
+
+当序列化 `Dayjs` 对象时,会返回 ISO8601 格式的字符串。
+```js
+dayjs().toJSON(); //"2018-08-08T00:00:00.000Z"
+```
+#### ISO 8601 字符串
+- return String
+
+返回 ISO8601 格式的字符串。
+```js
+dayjs().toISOString();
+```
+#### 对象
+- return Object
+
+返回包含时间数值的对象。
+```js
+dayjs().toObject();// { years:2018, months:8, date:18, hours:0, minutes:0, seconds:0, milliseconds:0}
+```
+#### 字符串
+- return String
+
+```js
+dayjs().toString();
+```
+---
+### 查询
+#### 是否之前
+- return Boolean
+
+检查一个 `Dayjs` 对象是否在另一个 `Dayjs` 对象时间之前。
+```js
+dayjs().isBefore(Dayjs);
+dayjs().isBefore(dayjs()); // false
+```
+#### 是否相同
+- return Boolean
+
+检查一个 `Dayjs` 对象是否和另一个 `Dayjs` 对象时间相同。
+```js
+dayjs().isSame(Dayjs);
+dayjs().isSame(dayjs()); // true
+```
+#### 是否之后
+- return Boolean
+
+检查一个 `Dayjs` 对象是否在另一个 `Dayjs` 对象时间之后。
+```js
+dayjs().isAfter(Dayjs);
+dayjs().isAfter(dayjs()); // false
+```
+#### 是否闰年
+- return Boolean
+
+是否闰年。
+```js
+dayjs().isLeapYear();
+dayjs('2000-01-01').isLeapYear(); // true
+```
\ No newline at end of file
From bc3f41e1d4730f672ac9d68a34210568eb7d2115 Mon Sep 17 00:00:00 2001
From: Steven
Date: Tue, 15 May 2018 22:33:23 -0400
Subject: [PATCH 04/23] Fix typescript declarations
---
index.d.ts | 163 +++++++++++++++++++++++++++--------------------------
1 file changed, 82 insertions(+), 81 deletions(-)
diff --git a/index.d.ts b/index.d.ts
index f94444ff7..007608105 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,82 +1,83 @@
-
-type ConfigType = string | number | Date | Dayjs
-
-type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date'
-
-interface DayjsObject {
- years: number
- months: number
- date: number
- hours: number
- minutes: number
- seconds: number
- milliseconds: number
+export = dayjs;
+
+declare function dayjs (config?: dayjs.ConfigType): dayjs.Dayjs
+
+declare namespace dayjs {
+ type ConfigType = string | number | Date | Dayjs
+
+ type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date'
+
+ interface DayjsObject {
+ years: number
+ months: number
+ date: number
+ hours: number
+ minutes: number
+ seconds: number
+ milliseconds: number
+ }
+
+ class Dayjs {
+ constructor (config?: ConfigType)
+
+ clone(): Dayjs
+
+ isValid(): boolean
+
+ year(): number
+
+ month(): number
+
+ date(): number
+
+ day(): number
+
+ hour(): number
+
+ minute(): number
+
+ second(): number
+
+ millisecond(): number
+
+ set(unit: UnitType, value: number): Dayjs
+
+ add(value: number, unit: UnitType): Dayjs
+
+ subtract(value: number, unit: UnitType): Dayjs
+
+ startOf(unit: UnitType): Dayjs
+
+ endOf(unit: UnitType): Dayjs
+
+ format(template?: string): string
+
+ diff(dayjs: Dayjs, unit: UnitType, float?: boolean): number
+
+ valueOf(): number
+
+ unix(): number
+
+ daysInMonth(): number
+
+ toDate(): Date
+
+ toArray(): number[]
+
+ toJSON(): string
+
+ toISOString(): string
+
+ toObject(): Object
+
+ toString(): string
+
+ isBefore(dayjs: Dayjs): boolean
+
+ isSame(dayjs: Dayjs): boolean
+
+ isAfter(dayjs: Dayjs): boolean
+
+ isLeapYear(): boolean
+ }
}
-
-declare class Dayjs {
- constructor (config?: ConfigType)
-
- clone(): Dayjs
-
- isValid(): boolean
-
- year(): number
-
- month(): number
-
- date(): number
-
- day(): number
-
- hour(): number
-
- minute(): number
-
- second(): number
-
- millisecond(): number
-
- set(unit: UnitType, value: number): Dayjs
-
- add(value: number, unit: UnitType): Dayjs
-
- subtract(value: number, unit: UnitType): Dayjs
-
- startOf(unit: UnitType): Dayjs
-
- endOf(unit: UnitType): Dayjs
-
- format(template?: string): string
-
- diff(dayjs: Dayjs, unit: UnitType, float?: boolean): number
-
- valueOf(): number
-
- unix(): number
-
- daysInMonth(): number
-
- toDate(): Date
-
- toArray(): number[]
-
- toJSON(): string
-
- toISOString(): string
-
- toObject(): Object
-
- toString(): string
-
- isBefore(dayjs: Dayjs): boolean
-
- isSame(dayjs: Dayjs): boolean
-
- isAfter(dayjs: Dayjs): boolean
-
- isLeapYear(): boolean
-}
-
-declare function dayjs (config?: ConfigType): Dayjs
-
-export default dayjs
From 106c1bee5a817bffbe0d152e7b4ced3b3321a6a2 Mon Sep 17 00:00:00 2001
From: Jorge Galat
Date: Tue, 15 May 2018 19:45:34 -0300
Subject: [PATCH 05/23] Add Brazilian Portuguese locale
---
src/locale/pt-br.js | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 src/locale/pt-br.js
diff --git a/src/locale/pt-br.js b/src/locale/pt-br.js
new file mode 100644
index 000000000..aad030bf6
--- /dev/null
+++ b/src/locale/pt-br.js
@@ -0,0 +1,12 @@
+import dayjs from 'dayjs'
+
+const locale = {
+ name: 'pt-br',
+ weekdays: 'Domingo_Segunda-feira_Terça-feira_Quarta-feira_Quinta-feira_Sexta-feira_Sábado'.split('_'),
+ months: 'Janeiro_Fevereiro_Março_Abril_Maio_Junho_Julho_Agosto_Setembro_Outubro_Novembro_Dezembro'.split('_'),
+ ordinal: n => `${n}º`
+}
+
+dayjs.locale(locale, null, true)
+
+export default locale
From 1f1c20cb2290c18849f1b6d1a7eb24192eeb767b Mon Sep 17 00:00:00 2001
From: Steven
Date: Wed, 16 May 2018 14:12:54 -0400
Subject: [PATCH 06/23] Add extend() and locale()
---
index.d.ts | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/index.d.ts b/index.d.ts
index 007608105..fca4601d4 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,11 +1,13 @@
export = dayjs;
-declare function dayjs (config?: dayjs.ConfigType): dayjs.Dayjs
+declare function dayjs (config?: dayjs.ConfigType, option?: dayjs.OptionType): dayjs.Dayjs
declare namespace dayjs {
- type ConfigType = string | number | Date | Dayjs
+ export type ConfigType = string | number | Date | Dayjs
- type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date'
+ export type OptionType = { locale: string }
+
+ export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date'
interface DayjsObject {
years: number
@@ -79,5 +81,13 @@ declare namespace dayjs {
isAfter(dayjs: Dayjs): boolean
isLeapYear(): boolean
+
+ locale(arg1: any, arg2?: any): void
}
+
+ export type PluginFunc = (option: ConfigType, d1: Dayjs, d2: Dayjs) => void
+
+ export function extend(plugin: PluginFunc, option: ConfigType): Dayjs
+
+ export function local(arg1: any, arg2?: any): void
}
From a1edb29530cac7c29bcbd2a386b909aa61886cd1 Mon Sep 17 00:00:00 2001
From: huruji <594613537@qq.com>
Date: Thu, 17 May 2018 22:23:47 +0800
Subject: [PATCH 07/23] fixes #152
---
src/constant.js | 2 +-
src/index.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/constant.js b/src/constant.js
index fc6c079bc..da0661d44 100644
--- a/src/constant.js
+++ b/src/constant.js
@@ -24,7 +24,7 @@ export const DATE = 'date'
export const FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ'
// regex
-export const REGEX_PARSE = /^(\d{4})-?(\d{1,2})-?(\d{1,2})(.*?(\d{1,2}):(\d{1,2}):(\d{1,2}))?.?(\d{1,3})?$/
+export const REGEX_PARSE = /^(\d{4})-?(\d{0,2})-?(\d{0,2})(.*?(\d{1,2}):(\d{1,2}):(\d{1,2}))?.?(\d{1,3})?$/
export const REGEX_FORMAT = /\[.*?\]|Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g
export const en = {
diff --git a/src/index.js b/src/index.js
index 37dad9eb9..1984e4805 100644
--- a/src/index.js
+++ b/src/index.js
@@ -52,7 +52,7 @@ const parseDate = (date) => {
if ((typeof date === 'string') && (reg = date.match(C.REGEX_PARSE))) {
// 2018-08-08 or 20180808
return new Date(
- reg[1], reg[2] - 1, reg[3],
+ reg[1], (reg[2] - 1) || 0, reg[3] || 1,
reg[5] || 0, reg[6] || 0, reg[7] || 0, reg[8] || 0
)
}
From c806caf0f8170f9eb27a73864661f812862db246 Mon Sep 17 00:00:00 2001
From: huruji <594613537@qq.com>
Date: Thu, 17 May 2018 23:40:36 +0800
Subject: [PATCH 08/23] update README.zh-CN.md
---
README.zh-CN.md | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/README.zh-CN.md b/README.zh-CN.md
index c456ee934..b0863d485 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -80,6 +80,7 @@ dayjs().format();
* [年](#年)
* [月](#月)
* [日](#日)
+ * [星期](#星期)
* [时](#时)
* [分](#分)
* [秒](#秒)
@@ -172,6 +173,13 @@ dayjs().month();
```js
dayjs().date();
```
+#### 星期
+- return Number
+
+获取星期。
+```js
+dayjs().day();
+```
#### 时
- return Number
From 6a6f94bc9da97dda021504c0a2b543cc394ee7c8 Mon Sep 17 00:00:00 2001
From: huruji <594613537@qq.com>
Date: Fri, 18 May 2018 01:04:43 +0800
Subject: [PATCH 09/23] fixes bug: dayjs().add()
---
src/index.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/index.js b/src/index.js
index 37dad9eb9..6515811a2 100644
--- a/src/index.js
+++ b/src/index.js
@@ -236,7 +236,9 @@ class Dayjs {
return date
}
if (['y', C.Y].indexOf(unit) > -1) {
- return this.set(C.Y, this.$y + number)
+ let date = this.set(C.DATE, 1).set(C.Y, this.$y + number)
+ date = date.set(C.DATE, Math.min(this.$D, date.daysInMonth()))
+ return date
}
let step
switch (unit) {
From feb3b69a1cd8c7d873c91f8b3f9496be4d9d9f73 Mon Sep 17 00:00:00 2001
From: Korbinian Kuhn
Date: Thu, 17 May 2018 21:55:52 +0200
Subject: [PATCH 10/23] Add german locale
---
src/locale/de.js | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 src/locale/de.js
diff --git a/src/locale/de.js b/src/locale/de.js
new file mode 100644
index 000000000..6a93171af
--- /dev/null
+++ b/src/locale/de.js
@@ -0,0 +1,12 @@
+import dayjs from 'dayjs'
+
+const locale = {
+ name: 'de',
+ weekdays: 'Sonntag_Montag_Dienstag_Mittwoch_Donnerstag_Freitag_Samstag'.split('_'),
+ months: 'Januar_Februar_März_April_Mai_Juni_Juli_August_September_Oktober_November_Dezember'.split('_'),
+ ordinal: n => `${n}.`
+}
+
+dayjs.locale(locale, null, true)
+
+export default locale
From 43fd984bba134f4629247de7570fbc7af24e31d1 Mon Sep 17 00:00:00 2001
From: iamkun
Date: Fri, 18 May 2018 11:26:57 +0800
Subject: [PATCH 11/23] docs: update readme [skip ci]
---
README.md | 68 +++++++++++++++++++++++++++++++++++--------------------
1 file changed, 43 insertions(+), 25 deletions(-)
diff --git a/README.md b/README.md
index ef245c38c..4371ce515 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ English | [简体中文](./README.zh-CN.md)
-> Day.js is a minimalist JavaScript library that parse, validate, manipulate, and display dates and times for modern browsers with a largely Moment.js-compatible API. If you use Moment.js, you already know how to use Day.js.
+> Day.js is a minimalist JavaScript library that parses, validates, manipulates, and displays dates and times for modern browsers with a largely Moment.js-compatible API. If you use Moment.js, you already know how to use Day.js.
```js
dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss');
@@ -32,50 +32,68 @@ dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:m
* 🕒 Familiar Moment.js API & patterns
* 💪 Immutable
* 🔥 Chainable
+* 🌐 I18n support
* 📦 2kb mini library
* 👫 All browsers supported
---
-## Installation
-
-You have multiple ways of getting Day.js:
+## Getting Started
-* Via NPM:
+### Installation
```console
npm install dayjs --save
```
-```js
-var dayjs = require('dayjs');
-dayjs().format();
-```
+📚[Installation Guide](./docs/en/Installation.md)
+
+### API
-* Via CDN:
+It's easy to use Day.js APIs to parse, validate, manipulate, and display dates and times.
-```html
-
-
-
+```javascript
+dayjs('2018-08-08') // parse
+
+dayjs().format('{YYYY} MM-DDTHH:mm:ss SSS [Z] A') // display
+
+dayjs().set('month', 3).month() // get & set
+
+dayjs().add(1, 'year') // manipulate
+
+dayjs().isBefore(dayjs()) // query
```
-* Via download and self-hosting:
+📚[API Reference](./docs/en/API-reference.md)
-Just download the latest version of Day.js at [https://unpkg.com/dayjs/](https://unpkg.com/dayjs/)
+### I18n
-## Getting Started
+Day.js has great support for internationalization.
-Instead of modifying the native `Date.prototype`, Day.js creates a wrapper for the Date object, called `Dayjs` object.
-`Dayjs` object is immutable, that is to say, all API operation will return a new `Dayjs` object.
+But none of them will be included in your build unless you use it.
-## API
+```javascript
+import 'dayjs/locale/es' // load on demand
-[API Reference](./docs/en/API-reference.md)
----
+dayjs.locale('es') // use Spanish locale globally
+
+dayjs('2018-05-05').locale('zh-cn').format() // use Chinese Simplified locale in a specific instance
+```
+📚[Internationalization](./docs/en/I18n.md)
+
+### Plugin
+
+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
+
+dayjs.extend(AdvancedFormat) // use plugin
+
+dayjs().format('Q Do k kk X x') // more available formats
+```
+📚[Plugin List](./docs/en/Plugin.md)
## License
-[MIT](./LICENSE)
+Day.js is licensed under a [MIT License](./LICENSE).
\ No newline at end of file
From 5f3efe3c34327b83b9f31017b7cdab6e0d9633a8 Mon Sep 17 00:00:00 2001
From: iamkun
Date: Fri, 18 May 2018 11:28:17 +0800
Subject: [PATCH 12/23] docs: add sub docs [skip ci]
---
docs/en/API-reference.md | 5 +-
docs/en/I18n.md | 104 +++++++++++++++++++++++++++++++++++++++
docs/en/Installation.md | 30 +++++++++++
docs/en/Plugin.md | 94 +++++++++++++++++++++++++++++++++++
4 files changed, 232 insertions(+), 1 deletion(-)
create mode 100644 docs/en/I18n.md
create mode 100644 docs/en/Installation.md
create mode 100644 docs/en/Plugin.md
diff --git a/docs/en/API-reference.md b/docs/en/API-reference.md
index 876aa4499..2f0a0e4f7 100644
--- a/docs/en/API-reference.md
+++ b/docs/en/API-reference.md
@@ -1,6 +1,8 @@
## API Reference
-Day.js will always return a new `Dayjs` object if not specified.
+Instead of modifying the native `Date.prototype`, Day.js creates a wrapper for the Date object, called `Dayjs` object.
+
+`Dayjs` object is immutable, that is to say, all API operation will return a new `Dayjs` object.
* [Parse](#parse)
* [Now](#now)
@@ -43,6 +45,7 @@ Day.js will always return a new `Dayjs` object if not specified.
* [Is Leap Year](#is-leap-year)
---
+Day.js will always return a new `Dayjs` object if not specified.
### Parse
diff --git a/docs/en/I18n.md b/docs/en/I18n.md
new file mode 100644
index 000000000..564786233
--- /dev/null
+++ b/docs/en/I18n.md
@@ -0,0 +1,104 @@
+## Internationalization
+
+Day.js has great support for internationalization.
+
+But none of them will be included in your build unless you use that.
+
+By default, Day.js comes with English (United States) locale.
+
+You can load multiple locales and switch between them easily.
+
+[List of supported locales](../src/locale)
+
+You are super welcome to add a locale by opening a pull request :+1:
+
+## API
+
+#### Changing locale globally
+
+* Returns locale string
+
+```js
+import 'dayjs/locale/es'
+import de from 'dayjs/locale/de'
+dayjs.locale('es') // use loaded locale globally
+dayjs.locale('de-german', de) // use locale and update default name string
+const customizedLocaleObject = { ... } // More details can be found in Customize section below.
+dayjs.locale(customizedLocaleObject) // use customize locale
+```
+
+* Changing the global locale doesn't affect existing instances.
+
+#### Changing locales locally
+
+* Returns CURRENT `Dayjs` object.
+
+Exactly the same as `dayjs#locale`, but only use locale in a specific instance.
+
+```js
+import 'dayjs/locale/es'
+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:
+
+```javascript
+import 'dayjs/locale/es' // load on demand
+// require('dayjs/locale/es') // CommonJS
+// import locale_es from 'dayjs/locale/es' -> load and get locale_es locale object
+
+dayjs.locale('es') // use locale globally
+dayjs().locale('es').format() // use locale in a specific instance
+```
+
+* Via CDN:
+```html
+
+
+
+
+```
+
+## Customize
+
+You could create your own locale.
+
+Feel free to open a pull request to share your locale.
+
+Template of a Day.js locale Object.
+```javascript
+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
+}
+```
+
+Template of a Day.js locale file.
+```javascript
+import dayjs from 'dayjs'
+
+const locale = { ... } // Your Day.js locale Object.
+
+dayjs.locale(locale, null, true) // load locale for later use
+
+export default locale
+```
\ No newline at end of file
diff --git a/docs/en/Installation.md b/docs/en/Installation.md
new file mode 100644
index 000000000..b67f032e8
--- /dev/null
+++ b/docs/en/Installation.md
@@ -0,0 +1,30 @@
+## Installation Guide
+
+You have multiple ways of getting Day.js:
+
+* Via NPM:
+
+```console
+npm install dayjs --save
+```
+
+```js
+import dayjs from 'dayjs'
+// Or CommonJS
+// var dayjs = require('dayjs');
+dayjs().format();
+```
+
+* Via CDN:
+
+```html
+
+
+
+```
+
+* Via download and self-hosting:
+
+Just download the latest version of Day.js at [https://unpkg.com/dayjs/](https://unpkg.com/dayjs/)
\ No newline at end of file
diff --git a/docs/en/Plugin.md b/docs/en/Plugin.md
new file mode 100644
index 000000000..66e7430ed
--- /dev/null
+++ b/docs/en/Plugin.md
@@ -0,0 +1,94 @@
+# Plugin List
+
+A plugin is an independent module that can be added to Day.js to extend functionality or add new features.
+
+By default, Day.js comes with core code only and no installed plugin.
+
+You can load multiple plugins based on your need.
+
+## API
+
+#### Extend
+
+* Returns dayjs
+
+Use a plugin.
+
+```js
+import plugin
+dayjs.extend(plugin)
+dayjs.extend(plugin, options) // with plugin options
+```
+
+## Installation
+
+* Via NPM:
+
+```javascript
+import dayjs from 'dayjs'
+import AdvancedFormat from 'dayjs/plugin/AdvancedFormat' // load on demand
+
+dayjs.extend(AdvancedFormat) // use plugin
+```
+
+* Via CDN:
+```html
+
+
+
+
+```
+
+## List of official plugins
+
+### AdvancedFormat
+ - AdvancedFormat extends `dayjs().format` API to supply more format options.
+
+```javascript
+import AdvancedFormat from 'dayjs/plugin/AdvancedFormat'
+
+dayjs.extend(AdvancedFormat)
+
+dayjs().format('Q Do k kk X x')
+```
+
+List of added formats:
+
+| Format | Output | Description |
+| ------ | ---------------- | ------------------------------------- |
+| `Q` | 1-4 | Quarter |
+| `Do` | 1st 2nd ... 31st | Day of Month with ordinal |
+| `k` | 1-23 | The hour, beginning at 1 |
+| `kk` | 01-23 | The hour, 2-digits, beginning at 1 |
+| `X` | 1360013296 | Unix Timestamp in second |
+| `x` | 1360013296123 | Unix Timestamp in millisecond |
+
+## Customize
+
+You could build your own Day.js plugin to meet different needs.
+
+Feel free to open a pull request to share your plugin.
+
+Template of a Day.js plugin.
+```javascript
+export default (option, dayjsClass, dayjsFactory) => {
+ // extend dayjs()
+ // e.g. add dayjs().isSameOrBefore()
+ dayjsClass.prototype.isSameOrBefore = function (arguments) {}
+
+ // extend dayjs
+ // e.g. add dayjs.utc()
+ dayjsFactory.utc = (arguments) => {}
+
+ // overriding existing API
+ // e.g. extend dayjs().format()
+ const oldFormat = dayjsClass.prototype.format
+ dayjsClass.prototype.format = function (arguments) {
+ // original format result
+ const result = oldFormat(arguments)
+ // return modified result
+ }
+}
+```
\ No newline at end of file
From 2a5dd699bd64ad1bd09d857bf413ea10983804ce Mon Sep 17 00:00:00 2001
From: iamkun
Date: Fri, 18 May 2018 11:30:25 +0800
Subject: [PATCH 13/23] docs: update chinese docs [skip ci]
---
docs/zh-cn/API-reference.md | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/docs/zh-cn/API-reference.md b/docs/zh-cn/API-reference.md
index 119c6c515..468e6630e 100644
--- a/docs/zh-cn/API-reference.md
+++ b/docs/zh-cn/API-reference.md
@@ -12,6 +12,7 @@
* [年](#年)
* [月](#月)
* [日](#日)
+ * [星期](#星期)
* [时](#时)
* [分](#分)
* [秒](#秒)
@@ -104,6 +105,13 @@ dayjs().month();
```js
dayjs().date();
```
+#### 星期
+- return Number
+
+获取星期。
+```js
+dayjs().day();
+```
#### 时
- return Number
From c98cba51893b66de4f6441137582722739c6134a Mon Sep 17 00:00:00 2001
From: iamkun
Date: Fri, 18 May 2018 13:31:10 +0800
Subject: [PATCH 14/23] docs: update chinese docs
---
README.zh-CN.md | 80 +++++++++++++++++----------
docs/zh-cn/API-reference.md | 7 ++-
docs/zh-cn/I18n.md | 104 ++++++++++++++++++++++++++++++++++++
docs/zh-cn/Installation.md | 24 +++++++++
docs/zh-cn/Plugin.md | 94 ++++++++++++++++++++++++++++++++
5 files changed, 280 insertions(+), 29 deletions(-)
create mode 100644 docs/zh-cn/I18n.md
create mode 100644 docs/zh-cn/Installation.md
create mode 100644 docs/zh-cn/Plugin.md
diff --git a/README.zh-CN.md b/README.zh-CN.md
index a5784306d..02ecb4949 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -1,4 +1,5 @@
[English](./README.md) | 简体中文
+

@@ -22,53 +23,76 @@
-> Day.js 是一个轻量的 JavaScript 时间日期处理库,和 Moment.js 的 API 设计保持完全一样. 如果你曾经用过 Moment.js, 那么你已经知道如何使用 Day.js
+> Day.js 是一个轻量的处理时间和日期的 JavaScript 库,和 Moment.js 的 API 设计保持完全一样. 如果你曾经用过 Moment.js, 那么你已经知道如何使用 Day.js
```js
dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss');
```
-- 🕒 和 Moment.js 相同的 API 和用法
-- 💪 不可变数据 (Immutable)
-- 🔥 支持链式操作 (Chainable)
-- 📦 仅 2kb 大小的微型库
-- 👫 全浏览器兼容
+* 🕒 和 Moment.js 相同的 API 和用法
+* 💪 不可变数据 (Immutable)
+* 🔥 支持链式操作 (Chainable)
+* 🌐 国际化 I18n
+* 📦 仅 2kb 大小的微型库
+* 👫 全浏览器兼容
---
-## 安装
+## 快速开始
-可以有如下多种方法安装使用 Day.js:
+### 安装
-- NPM:
```console
npm install dayjs --save
```
-```js
-var dayjs = require('dayjs');
-dayjs().format();
-```
-- CDN:
-```html
-
-
-
+
+📚[安装指南](./docs/zh-cn/Installation.md)
+
+### API
+
+Day.js 有很多 API 来解析、处理、校验、增减、展示时间和日期
+
+```javascript
+dayjs('2018-08-08') // 解析
+
+dayjs().format('{YYYY} MM-DDTHH:mm:ss SSS [Z] A') // 展示
+
+dayjs().set('month', 3).month() // 获取
+
+dayjs().add(1, 'year') // 处理
+
+dayjs().isBefore(dayjs()) // 查询
```
-- 下载到您自己的服务器上:
+📚[API 参考](./docs/zh-cn/API-reference.md)
-从 [https://unpkg.com/dayjs/](https://unpkg.com/dayjs/) 下载最新的 Dayjs 源文件,并自行部署到您的服务器上。
+### 国际化 I18n
-## 开始
-`Dayjs` 并没有改变或覆盖 Javascript 原生的 `Date.prototype`, 而是创造了一个全新的包含 `Javascript Date` 对象的 `Dayjs` 的对象。
+Day.js 支持国际化
-`Dayjs` 对象是不可变的, 所有的 API 操作都将返回一个新的 `Dayjs` 对象。
+但除非手动加载,多国语言默认是不会被打包到工程里的
+```javascript
+import 'dayjs/locale/es' // 按需加载
-## API
+dayjs.locale('es') // 全局使用西班牙语
+
+dayjs('2018-05-05').locale('zh-cn').format() // 在这个实例上使用简体中文
+```
+📚[国际化 I18n](./docs/zh-cn/I18n.md)
+
+### 插件
+
+插件可以给 Day.js 增加新功能和扩展已有功能
+
+```javascript
+import AdvancedFormat from 'dayjs/plugin/AdvancedFormat' // 按需加载插件
+
+dayjs.extend(AdvancedFormat) // 使用插件
+
+dayjs().format('Q Do k kk X x') // 使用扩展后的API
+```
+📚[插件列表](./docs/zh-cn/Plugin.md)
----
## 开源协议
-MIT
+Day.js 遵循 [MIT 开源协议](./LICENSE).
diff --git a/docs/zh-cn/API-reference.md b/docs/zh-cn/API-reference.md
index 468e6630e..0c2c7f62e 100644
--- a/docs/zh-cn/API-reference.md
+++ b/docs/zh-cn/API-reference.md
@@ -1,5 +1,8 @@
## API
-如果没有特别说明,Day.js 的返回值都是新的 `Dayjs` 对象。
+
+`Dayjs` 并没有改变或覆盖 Javascript 原生的 `Date.prototype`, 而是创造了一个全新的包含 `Javascript Date` 对象的 `Dayjs` 的对象。
+
+`Dayjs` 对象是不可变的, 所有的 API 操作都将返回一个新的 `Dayjs` 对象。
* [解析](#解析)
* [当前时间](#当前时间)
@@ -42,6 +45,8 @@
* [是否闰年](#是否闰年)
---
+如果没有特别说明,Day.js 的返回值都是新的 `Dayjs` 对象。
+
### 解析
在 `dayjs()` 中传入支持的格式
#### 当前时间
diff --git a/docs/zh-cn/I18n.md b/docs/zh-cn/I18n.md
new file mode 100644
index 000000000..6b121ad55
--- /dev/null
+++ b/docs/zh-cn/I18n.md
@@ -0,0 +1,104 @@
+## 国际化 I18n
+
+Day.js has great support for internationalization.
+
+But none of them will be included in your build unless you use that.
+
+By default, Day.js comes with English (United States) locale.
+
+You can load multiple locales and switch between them easily.
+
+[List of supported locales](../src/locale)
+
+You are super welcome to add a locale by opening a pull request :+1:
+
+## API
+
+#### Changing locale globally
+
+* Returns locale string
+
+```js
+import 'dayjs/locale/es'
+import de from 'dayjs/locale/de'
+dayjs.locale('es') // use loaded locale globally
+dayjs.locale('de-german', de) // use locale and update default name string
+const customizedLocaleObject = { ... } // More details can be found in Customize section below.
+dayjs.locale(customizedLocaleObject) // use customize locale
+```
+
+* Changing the global locale doesn't affect existing instances.
+
+#### Changing locales locally
+
+* Returns CURRENT `Dayjs` object.
+
+Exactly the same as `dayjs#locale`, but only use locale in a specific instance.
+
+```js
+import 'dayjs/locale/es'
+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:
+
+```javascript
+import 'dayjs/locale/es' // load on demand
+// require('dayjs/locale/es') // CommonJS
+// import locale_es from 'dayjs/locale/es' -> load and get locale_es locale object
+
+dayjs.locale('es') // use locale globally
+dayjs().locale('es').format() // use locale in a specific instance
+```
+
+* Via CDN:
+```html
+
+
+
+
+```
+
+## Customize
+
+You could create your own locale.
+
+Feel free to open a pull request to share your locale.
+
+Template of a Day.js locale Object.
+```javascript
+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
+}
+```
+
+Template of a Day.js locale file.
+```javascript
+import dayjs from 'dayjs'
+
+const locale = { ... } // Your Day.js locale Object.
+
+dayjs.locale(locale, null, true) // load locale for later use
+
+export default locale
+```
\ No newline at end of file
diff --git a/docs/zh-cn/Installation.md b/docs/zh-cn/Installation.md
new file mode 100644
index 000000000..d9218078d
--- /dev/null
+++ b/docs/zh-cn/Installation.md
@@ -0,0 +1,24 @@
+## 安装指南
+
+可以有如下多种方法安装使用 Day.js:
+
+- NPM:
+```console
+npm install dayjs --save
+```
+```js
+var dayjs = require('dayjs');
+dayjs().format();
+```
+- CDN:
+```html
+
+
+
+```
+
+- 下载到您自己的服务器上:
+
+从 [https://unpkg.com/dayjs/](https://unpkg.com/dayjs/) 下载最新的 Dayjs 源文件,并自行部署到您的服务器上。
\ No newline at end of file
diff --git a/docs/zh-cn/Plugin.md b/docs/zh-cn/Plugin.md
new file mode 100644
index 000000000..8fa322f05
--- /dev/null
+++ b/docs/zh-cn/Plugin.md
@@ -0,0 +1,94 @@
+# 插件列表
+
+A plugin is an independent module that can be added to Day.js to extend functionality or add new features.
+
+By default, Day.js comes with core code only and no installed plugin.
+
+You can load multiple plugins based on your need.
+
+## API
+
+#### Extend
+
+* Returns dayjs
+
+Use a plugin.
+
+```js
+import plugin
+dayjs.extend(plugin)
+dayjs.extend(plugin, options) // with plugin options
+```
+
+## Installation
+
+* Via NPM:
+
+```javascript
+import dayjs from 'dayjs'
+import AdvancedFormat from 'dayjs/plugin/AdvancedFormat' // load on demand
+
+dayjs.extend(AdvancedFormat) // use plugin
+```
+
+* Via CDN:
+```html
+
+
+
+
+```
+
+## List of official plugins
+
+### AdvancedFormat
+ - AdvancedFormat extends `dayjs().format` API to supply more format options.
+
+```javascript
+import AdvancedFormat from 'dayjs/plugin/AdvancedFormat'
+
+dayjs.extend(AdvancedFormat)
+
+dayjs().format('Q Do k kk X x')
+```
+
+List of added formats:
+
+| Format | Output | Description |
+| ------ | ---------------- | ------------------------------------- |
+| `Q` | 1-4 | Quarter |
+| `Do` | 1st 2nd ... 31st | Day of Month with ordinal |
+| `k` | 1-23 | The hour, beginning at 1 |
+| `kk` | 01-23 | The hour, 2-digits, beginning at 1 |
+| `X` | 1360013296 | Unix Timestamp in second |
+| `x` | 1360013296123 | Unix Timestamp in millisecond |
+
+## Customize
+
+You could build your own Day.js plugin to meet different needs.
+
+Feel free to open a pull request to share your plugin.
+
+Template of a Day.js plugin.
+```javascript
+export default (option, dayjsClass, dayjsFactory) => {
+ // extend dayjs()
+ // e.g. add dayjs().isSameOrBefore()
+ dayjsClass.prototype.isSameOrBefore = function (arguments) {}
+
+ // extend dayjs
+ // e.g. add dayjs.utc()
+ dayjsFactory.utc = (arguments) => {}
+
+ // overriding existing API
+ // e.g. extend dayjs().format()
+ const oldFormat = dayjsClass.prototype.format
+ dayjsClass.prototype.format = function (arguments) {
+ // original format result
+ const result = oldFormat(arguments)
+ // return modified result
+ }
+}
+```
\ No newline at end of file
From ce4b8c133dbb621ca6cdddaf2c36496ebff48b70 Mon Sep 17 00:00:00 2001
From: iamkun
Date: Fri, 18 May 2018 13:33:05 +0800
Subject: [PATCH 15/23] docs: fix doc link
---
docs/en/I18n.md | 2 +-
docs/zh-cn/I18n.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/en/I18n.md b/docs/en/I18n.md
index 564786233..c5203f8f2 100644
--- a/docs/en/I18n.md
+++ b/docs/en/I18n.md
@@ -8,7 +8,7 @@ By default, Day.js comes with English (United States) locale.
You can load multiple locales and switch between them easily.
-[List of supported locales](../src/locale)
+[List of supported locales](../../src/locale)
You are super welcome to add a locale by opening a pull request :+1:
diff --git a/docs/zh-cn/I18n.md b/docs/zh-cn/I18n.md
index 6b121ad55..33b29b9a8 100644
--- a/docs/zh-cn/I18n.md
+++ b/docs/zh-cn/I18n.md
@@ -8,7 +8,7 @@ By default, Day.js comes with English (United States) locale.
You can load multiple locales and switch between them easily.
-[List of supported locales](../src/locale)
+[List of supported locales](../../src/locale)
You are super welcome to add a locale by opening a pull request :+1:
From 0e14a3fbc15de83128fc1f46fb8c36be805fa11b Mon Sep 17 00:00:00 2001
From: iamkun
Date: Fri, 18 May 2018 13:56:44 +0800
Subject: [PATCH 16/23] docs: chinese docs update [skip ci]
---
README.zh-CN.md | 4 ++--
docs/zh-cn/API-reference.md | 4 ++--
docs/zh-cn/I18n.md | 28 ++++++++++++++--------------
docs/zh-cn/Installation.md | 7 +++++--
docs/zh-cn/Plugin.md | 6 +++---
5 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 02ecb4949..74022fc7b 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -23,7 +23,7 @@
-> Day.js 是一个轻量的处理时间和日期的 JavaScript 库,和 Moment.js 的 API 设计保持完全一样. 如果你曾经用过 Moment.js, 那么你已经知道如何使用 Day.js
+> Day.js 是一个轻量的处理时间和日期的 JavaScript 库,和 Moment.js 的 API 设计保持完全一样. 如果您曾经用过 Moment.js, 那么您已经知道如何使用 Day.js
```js
dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss');
@@ -82,7 +82,7 @@ dayjs('2018-05-05').locale('zh-cn').format() // 在这个实例上使用简体
### 插件
-插件可以给 Day.js 增加新功能和扩展已有功能
+插件是一些独立的程序,可以给 Day.js 增加新功能和扩展已有功能
```javascript
import AdvancedFormat from 'dayjs/plugin/AdvancedFormat' // 按需加载插件
diff --git a/docs/zh-cn/API-reference.md b/docs/zh-cn/API-reference.md
index 0c2c7f62e..f21edf1ee 100644
--- a/docs/zh-cn/API-reference.md
+++ b/docs/zh-cn/API-reference.md
@@ -73,7 +73,7 @@ dayjs(Date);
dayjs(new Date(2018, 8, 18));
```
### 复制
-`Dayjs` 对象是不可变的,如果你想获得一个对象的拷贝,请执行 `.clone()`。
+`Dayjs` 对象是不可变的,如果您想获得一个对象的拷贝,请执行 `.clone()`。
向 `dayjs()` 里传入一个 `Dayjs` 对象也能实现同样的效果。
```js
dayjs(Dayjs);
@@ -155,7 +155,7 @@ dayjs().set('second', 30);
```
---
### 操作
-你可以对 `Dayjs` 对象如下增加减少之类的操作:
+您可以对 `Dayjs` 对象如下增加减少之类的操作:
```js
dayjs().startOf('month').add(1, 'day').subtract(1, 'year')
```
diff --git a/docs/zh-cn/I18n.md b/docs/zh-cn/I18n.md
index 33b29b9a8..73d9e3300 100644
--- a/docs/zh-cn/I18n.md
+++ b/docs/zh-cn/I18n.md
@@ -1,33 +1,33 @@
## 国际化 I18n
-Day.js has great support for internationalization.
+Day.js 支持国际化
-But none of them will be included in your build unless you use that.
+但除非手动加载,多国语言默认是不会被打包到工程里的
-By default, Day.js comes with English (United States) locale.
+Day.js 内置的是英语(English - United States)语言
-You can load multiple locales and switch between them easily.
+您可以加载多个其他语言并自由切换
-[List of supported locales](../../src/locale)
+[支持的语言列表](../../src/locale)
-You are super welcome to add a locale by opening a pull request :+1:
+欢迎给我们提交 Pull Request 来增加新的语言
## API
-#### Changing locale globally
+#### 改变全局语言
-* Returns locale string
+* 返回使用语言的字符串
```js
-import 'dayjs/locale/es'
+import 'dayjs/locale/zh-cn'
import de from 'dayjs/locale/de'
-dayjs.locale('es') // use loaded locale globally
-dayjs.locale('de-german', de) // use locale and update default name string
-const customizedLocaleObject = { ... } // More details can be found in Customize section below.
-dayjs.locale(customizedLocaleObject) // use customize locale
+dayjs.locale('zh-cn') // 全局使用简体中文
+dayjs.locale('de-german', de) // 使用并更新语言包的名字
+const customizedLocaleObject = { ... } // 更多细节请参考下方的自定义语言对象
+dayjs.locale(customizedLocaleObject) // 使用自定义语言
```
-* Changing the global locale doesn't affect existing instances.
+* 改变全局语言并不会影响在此之前生成的实例
#### Changing locales locally
diff --git a/docs/zh-cn/Installation.md b/docs/zh-cn/Installation.md
index d9218078d..8384c51ce 100644
--- a/docs/zh-cn/Installation.md
+++ b/docs/zh-cn/Installation.md
@@ -6,13 +6,16 @@
```console
npm install dayjs --save
```
+
```js
-var dayjs = require('dayjs');
+import dayjs from 'dayjs'
+// 或者 CommonJS
+// var dayjs = require('dayjs');
dayjs().format();
```
- CDN:
```html
-
+