Skip to content

Commit

Permalink
fix: Add weekday (locale aware day of the week) plugin (#569)
Browse files Browse the repository at this point in the history
fix #559
  • Loading branch information
iamkun committed Apr 15, 2019
1 parent ffffacf commit 9007cc5
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 61 deletions.
6 changes: 6 additions & 0 deletions docs/en/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,12 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear)

plugin [`WeekOfYear`](./Plugin.md#weekofyear)

### WeekDay

`.weekday` to get or set locale aware day of the week

plugin [`WeekDay`](./Plugin.md#weekday)

### IsoWeeksInYear

`.isoWeeksInYear` to get the number of weeks in year
Expand Down
13 changes: 13 additions & 0 deletions docs/en/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,19 @@ dayjs('2018-06-27').week() // 26
dayjs('2018-06-27').week(5) // set week
```

### WeekDay

- WeekDay adds `.weekday()` API to get or set locale aware day of the week.

```javascript
import weekDay from 'dayjs/plugin/weekDay'

dayjs.extend(weekDay)
// when Monday is the first day of the week
dayjs().weekday(-7) // last Monday
dayjs().weekday(7) // next Monday
```

### IsoWeeksInYear

- IsoWeeksInYear adds `.isoWeeksInYear()` API to return a `number` to get the number of weeks in year, according to ISO weeks.
Expand Down
6 changes: 6 additions & 0 deletions docs/es-es/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,12 @@ complemento [`IsLeapYear`](./Plugin.md#isleapyear)

complemento [`WeekOfYear`](./Plugin.md#weekofyear)

### WeekDay

`.weekday` to get or set locale aware day of the week

plugin [`WeekDay`](./Plugin.md#weekday)

### IsoWeeksInYear

`.isoWeeksInYear` to get the number of weeks in year
Expand Down
13 changes: 13 additions & 0 deletions docs/es-es/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ dayjs('2018-06-27').week() // 26
dayjs('2018-06-27').week(5) // set week
```

### WeekDay

- WeekDay adds `.weekday()` API to get or set locale aware day of the week.

```javascript
import weekDay from 'dayjs/plugin/weekDay'

dayjs.extend(weekDay)
// when Monday is the first day of the week
dayjs().weekday(-7) // last Monday
dayjs().weekday(7) // next Monday
```

### IsoWeeksInYear

- IsoWeeksInYear adds `.isoWeeksInYear()` API to return a `number` to get the number of weeks in year, according to ISO weeks.
Expand Down
116 changes: 55 additions & 61 deletions docs/ja/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ Day.js は組み込みの `Date.prototype` を変更する代わりに `Dayjs`
- [Is a Dayjs `.isDayjs(compared: any)`](#is-a-dayjs-isdayjscompared-any)
- [UTC](#utc)
- [Plugin APIs](#plugin-apis)
- [RelativeTime](#relativetime)
- [IsLeapYear](#isleapyear)
- [WeekOfYear](#weekofyear)
- [IsoWeeksInYear](#isoweeksinyear)
- [IsSameOrAfter](#issameorafter)
- [IsSameOrBefore](#issameorbefore)
- [IsBetween](#isbetween)
- [QuarterOfYear](#quarterofyear)
- [ToArray](#toarray)
- [ToObject](#toobject)
- [MinMax](#minmax)
- [Calendar](#calendar)

## Parsing

Expand All @@ -73,7 +61,7 @@ Day.js は組み込みの `Date.prototype` を変更する代わりに `Dayjs`
dayjs()
```

Day.jsは他の日付フォーマットもパースします
Day.js は他の日付フォーマットもパースします

#### [ISO 8601](https://ja.wikipedia.org/wiki/ISO_8601) 形式

Expand All @@ -89,15 +77,15 @@ dayjs(new Date(2018, 8, 18))

#### Unix Timestamp (milliseconds)

Unixタイムスタンプ(Unixエポックのミリ秒)から`Dayjs`オブジェクトを返します。
Unix タイムスタンプ(Unix エポックのミリ秒)から`Dayjs`オブジェクトを返します。

```js
dayjs(1318781876406)
```

### Unix Timestamp (seconds) `.unix(value: number)`

Unixタイムスタンプ(Unixエポックの秒)から`Dayjs`オブジェクトを返します。
Unix タイムスタンプ(Unix エポックの秒)から`Dayjs`オブジェクトを返します。

```js
dayjs.unix(1318781876)
Expand Down Expand Up @@ -210,16 +198,16 @@ dayjs().get('day')

#### List of all available units

| 単位 | ショートハンド | 説明 |
| ---- | ---- | ---- |
| `date` | | 月の日ひち |
| `day` | `d` | 曜日(日曜日は`0`、土曜日は`6`|
| `month` | `M` | 月(1月は`0`12月は`11`|
| `year` | `y` ||
| `hour` | `h` ||
| `minute` | `m` ||
| `second` | `s` ||
| `millisecond` | `ms` | ミリ秒 |
| 単位 | ショートハンド | 説明 |
| ------------- | -------------- | -------------------------------- |
| `date` | | 月の日ひち |
| `day` | `d` | 曜日(日曜日は`0`、土曜日は`6`|
| `month` | `M` | 月(1 月は`0`12 月は`11` |
| `year` | `y` | |
| `hour` | `h` | |
| `minute` | `m` | |
| `second` | `s` | |
| `millisecond` | `ms` | ミリ秒 |

### Set `.set(unit: string, value: number)`

Expand Down Expand Up @@ -291,40 +279,40 @@ dayjs('2019-01-25').format('DD/MM/YYYY') // '25/01/2019'

#### List of all available formats

| フォーマット | 出力 | 説明 |
| ------ | ---------------- | ------------------------------------- |
| `YY` | 18 | 2桁の年 |
| `YYYY` | 2018 | 4桁の年 |
| `M` | 1-12 | 1始まりの月 |
| `MM` | 01-12 | 1始まりの2桁の月 |
| `MMM` | Jan-Dec | 月の略称 |
| `MMMM` | January-December | 月の正式名 |
| `D` | 1-31 | 月ごとの日にち |
| `DD` | 01-31 | 月ごとの2桁の日にち |
| `d` | 0-6 | `0`で日曜日から始まる曜日 |
| `dd` | Su-Sa | 最も短い曜日の略称 |
| `ddd` | Sun-Sat | 曜日の略称 |
| `dddd` | Sunday-Saturday | 曜日名 |
| `H` | 0-23 | 時間 |
| `HH` | 00-23 | 2桁の時間 |
| `h` | 1-12 | 12時制の時間 |
| `hh` | 01-12 | 12時制で2桁の時間 |
| `m` | 0-59 ||
| `mm` | 00-59 | 2桁の分 |
| `s` | 0-59 ||
| `ss` | 00-59 | 2桁の秒 |
| `SSS` | 000-999 | 3桁のミリ秒 |
| `Z` | +5:00 | UTCからのオフセット |
| `ZZ` | +0500 | UTCからの2桁のオフセット |
| `A` | AM PM | 午前と午後(大文字) |
| `a` | am pm | 午前と午後(小文字) |
| フォーマット | 出力 | 説明 |
| ------------ | ---------------- | --------------------------- |
| `YY` | 18 | 2 桁の年 |
| `YYYY` | 2018 | 4 桁の年 |
| `M` | 1-12 | 1 始まりの月 |
| `MM` | 01-12 | 1 始まりの 2 桁の月 |
| `MMM` | Jan-Dec | 月の略称 |
| `MMMM` | January-December | 月の正式名 |
| `D` | 1-31 | 月ごとの日にち |
| `DD` | 01-31 | 月ごとの 2 桁の日にち |
| `d` | 0-6 | `0`で日曜日から始まる曜日 |
| `dd` | Su-Sa | 最も短い曜日の略称 |
| `ddd` | Sun-Sat | 曜日の略称 |
| `dddd` | Sunday-Saturday | 曜日名 |
| `H` | 0-23 | 時間 |
| `HH` | 00-23 | 2 桁の時間 |
| `h` | 1-12 | 12 時制の時間 |
| `hh` | 01-12 | 12 時制で 2 桁の時間 |
| `m` | 0-59 | |
| `mm` | 00-59 | 2 桁の分 |
| `s` | 0-59 | |
| `ss` | 00-59 | 2 桁の秒 |
| `SSS` | 000-999 | 3 桁のミリ秒 |
| `Z` | +5:00 | UTC からのオフセット |
| `ZZ` | +0500 | UTC からの 2 桁のオフセット |
| `A` | AM PM | 午前と午後(大文字) |
| `a` | am pm | 午前と午後(小文字) |

- 利用可能な他のフォーマット `Q Do k kk X x ...` in plugin [`AdvancedFormat`](./Plugin.md#advancedformat)
- ローカライズのフォーマットオプション `L LT LTS ...` in plugin [`LocalizedFormat`](./Plugin.md#localizedFormat)

### Difference `.diff(compared: Dayjs, unit: string (default: 'milliseconds'), float?: boolean)`

2つの`Dayjs`オブジェクトの差分を指定した単位で数値で返します。
2 つの`Dayjs`オブジェクトの差分を指定した単位で数値で返します。

```js
const date1 = dayjs('2019-01-25')
Expand All @@ -337,23 +325,23 @@ date1.diff(date2, 'day') // 233

### Unix Timestamp (milliseconds) `.valueOf()`

`Dayjs`オブジェクトのUnixエポックからのミリ秒を数値で返します
`Dayjs`オブジェクトの Unix エポックからのミリ秒を数値で返します

```js
dayjs('2019-01-25').valueOf() // 1548381600000
```

### Unix Timestamp (seconds) `.unix()`

`Dayjs`オブジェクトのUnixエポックからの秒を数値で返します
`Dayjs`オブジェクトの Unix エポックからの秒を数値で返します

```js
dayjs('2019-01-25').unix() // 1548381600
```

### UTC Offset (minutes) `.utcOffset()`

`Dayjs`オブジェクトのUTCオフセットを分単位の数値で返します
`Dayjs`オブジェクトの UTC オフセットを分単位の数値で返します

```js
dayjs().utcOffset()
Expand All @@ -377,15 +365,15 @@ dayjs('2019-01-25').toDate()

### As JSON `.toJSON()`

`Dayjs`オブジェクトの日付をISO8601形式にして文字列で返します
`Dayjs`オブジェクトの日付を ISO8601 形式にして文字列で返します

```js
dayjs('2019-01-25').toJSON() // '2019-01-25T02:00:00.000Z'
```

### As ISO 8601 String `.toISOString()`

`Dayjs`オブジェクトの日付をISO8601形式にして文字列で返します
`Dayjs`オブジェクトの日付を ISO8601 形式にして文字列で返します

```js
dayjs('2019-01-25').toISOString() // '2019-01-25T02:00:00.000Z'
Expand Down Expand Up @@ -445,7 +433,7 @@ dayjs() instanceof dayjs // true

## UTC

UTCでパースや表示をしたい場合は[`UTC`](./Plugin.md#utc)プラグインの`.utc` `.local` `.isUTC` で行えます。
UTC でパースや表示をしたい場合は[`UTC`](./Plugin.md#utc)プラグインの`.utc` `.local` `.isUTC` で行えます。

## Plugin APIs

Expand All @@ -467,6 +455,12 @@ UTCでパースや表示をしたい場合は、[`UTC`](./Plugin.md#utc)プラ

プラグイン [`WeekOfYear`](./Plugin.md#weekofyear)

### WeekDay

`.weekday` to get or set locale aware day of the week

plugin [`WeekDay`](./Plugin.md#weekday)

### IsoWeeksInYear

`.isoWeeksInYear` でその年の週数が得られます。
Expand All @@ -487,7 +481,7 @@ UTCでパースや表示をしたい場合は、[`UTC`](./Plugin.md#utc)プラ

### IsBetween

`.isBetween`で他の2つの日付の間であるかどうかを得られます
`.isBetween`で他の 2 つの日付の間であるかどうかを得られます

プラグイン [`IsBetween`](./Plugin.md#isbetween)

Expand Down Expand Up @@ -519,4 +513,4 @@ UTCでパースや表示をしたい場合は、[`UTC`](./Plugin.md#utc)プラ

`.calendar`で与えた日付のカレンダー上の情報が得られます。

プラグイン [`Calendar`](./Plugin.md#calendar)
プラグイン [`Calendar`](./Plugin.md#calendar)
13 changes: 13 additions & 0 deletions docs/ja/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,19 @@ dayjs('06/27/2018').week() // 26
dayjs('2018-06-27').week(5) // set week
```

### WeekDay

- WeekDay adds `.weekday()` API to get or set locale aware day of the week.

```javascript
import weekDay from 'dayjs/plugin/weekDay'

dayjs.extend(weekDay)
// when Monday is the first day of the week
dayjs().weekday(-7) // last Monday
dayjs().weekday(7) // next Monday
```

### IsoWeeksInYear

- IsoWeeksInYear adds `.isoWeeksInYear()` API to return a `number` to get the number of weeks in year, according to ISO weeks.
Expand Down
6 changes: 6 additions & 0 deletions docs/ko/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,12 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear)

plugin [`WeekOfYear`](./Plugin.md#weekofyear)

### WeekDay

`.weekday` to get or set locale aware day of the week

plugin [`WeekDay`](./Plugin.md#weekday)

### IsoWeeksInYear

`.isoWeeksInYear` to get the number of weeks in year
Expand Down
13 changes: 13 additions & 0 deletions docs/ko/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ dayjs('06/27/2018').week() // 26
dayjs('2018-06-27').week(5) // set week
```

### WeekDay

- WeekDay adds `.weekday()` API to get or set locale aware day of the week.

```javascript
import weekDay from 'dayjs/plugin/weekDay'

dayjs.extend(weekDay)
// when Monday is the first day of the week
dayjs().weekday(-7) // last Monday
dayjs().weekday(7) // next Monday
```

### IsoWeeksInYear

- IsoWeeksInYear adds `.isoWeeksInYear()` API to return a `number` to get the number of weeks in year, according to ISO weeks.
Expand Down
6 changes: 6 additions & 0 deletions docs/pt-br/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear)

plugin [`WeekOfYear`](./Plugin.md#weekofyear)

### WeekDay

`.weekday` to get or set locale aware day of the week

plugin [`WeekDay`](./Plugin.md#weekday)

### IsoWeeksInYear

`.isoWeeksInYear` to get the number of weeks in year
Expand Down
13 changes: 13 additions & 0 deletions docs/pt-br/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ dayjs('06/27/2018').week() // 26
dayjs('2018-06-27').week(5) // set week
```

### WeekDay

- WeekDay adds `.weekday()` API to get or set locale aware day of the week.

```javascript
import weekDay from 'dayjs/plugin/weekDay'

dayjs.extend(weekDay)
// when Monday is the first day of the week
dayjs().weekday(-7) // last Monday
dayjs().weekday(7) // next Monday
```

### IsoWeeksInYear

- IsoWeeksInYear adds `.isoWeeksInYear()` API to return a `number` to get the number of weeks in year, according to ISO weeks.
Expand Down
6 changes: 6 additions & 0 deletions docs/zh-cn/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ dayjs() instanceof dayjs // true

插件 [`WeekOfYear`](./Plugin.md#weekofyear)

### 星期

`.weekday` 来获取或设置当前语言的星期

plugin [`WeekDay`](./Plugin.md#weekday)

### 年中有几周 ISO

`.isoWeeksInYear` 获得年中有几周
Expand Down
Loading

0 comments on commit 9007cc5

Please sign in to comment.