Skip to content

Commit 9007cc5

Browse files
authored
fix: Add weekday (locale aware day of the week) plugin (#569)
fix #559
1 parent ffffacf commit 9007cc5

15 files changed

+231
-61
lines changed

docs/en/API-reference.md

+6
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,12 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear)
455455

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

458+
### WeekDay
459+
460+
`.weekday` to get or set locale aware day of the week
461+
462+
plugin [`WeekDay`](./Plugin.md#weekday)
463+
458464
### IsoWeeksInYear
459465

460466
`.isoWeeksInYear` to get the number of weeks in year

docs/en/Plugin.md

+13
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,19 @@ dayjs('2018-06-27').week() // 26
286286
dayjs('2018-06-27').week(5) // set week
287287
```
288288

289+
### WeekDay
290+
291+
- WeekDay adds `.weekday()` API to get or set locale aware day of the week.
292+
293+
```javascript
294+
import weekDay from 'dayjs/plugin/weekDay'
295+
296+
dayjs.extend(weekDay)
297+
// when Monday is the first day of the week
298+
dayjs().weekday(-7) // last Monday
299+
dayjs().weekday(7) // next Monday
300+
```
301+
289302
### IsoWeeksInYear
290303

291304
- IsoWeeksInYear adds `.isoWeeksInYear()` API to return a `number` to get the number of weeks in year, according to ISO weeks.

docs/es-es/API-reference.md

+6
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,12 @@ complemento [`IsLeapYear`](./Plugin.md#isleapyear)
455455

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

458+
### WeekDay
459+
460+
`.weekday` to get or set locale aware day of the week
461+
462+
plugin [`WeekDay`](./Plugin.md#weekday)
463+
458464
### IsoWeeksInYear
459465

460466
`.isoWeeksInYear` to get the number of weeks in year

docs/es-es/Plugin.md

+13
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@ dayjs('2018-06-27').week() // 26
282282
dayjs('2018-06-27').week(5) // set week
283283
```
284284

285+
### WeekDay
286+
287+
- WeekDay adds `.weekday()` API to get or set locale aware day of the week.
288+
289+
```javascript
290+
import weekDay from 'dayjs/plugin/weekDay'
291+
292+
dayjs.extend(weekDay)
293+
// when Monday is the first day of the week
294+
dayjs().weekday(-7) // last Monday
295+
dayjs().weekday(7) // next Monday
296+
```
297+
285298
### IsoWeeksInYear
286299

287300
- IsoWeeksInYear adds `.isoWeeksInYear()` API to return a `number` to get the number of weeks in year, according to ISO weeks.

docs/ja/API-reference.md

+55-61
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ Day.js は組み込みの `Date.prototype` を変更する代わりに `Dayjs`
5050
- [Is a Dayjs `.isDayjs(compared: any)`](#is-a-dayjs-isdayjscompared-any)
5151
- [UTC](#utc)
5252
- [Plugin APIs](#plugin-apis)
53-
- [RelativeTime](#relativetime)
54-
- [IsLeapYear](#isleapyear)
55-
- [WeekOfYear](#weekofyear)
56-
- [IsoWeeksInYear](#isoweeksinyear)
57-
- [IsSameOrAfter](#issameorafter)
58-
- [IsSameOrBefore](#issameorbefore)
59-
- [IsBetween](#isbetween)
60-
- [QuarterOfYear](#quarterofyear)
61-
- [ToArray](#toarray)
62-
- [ToObject](#toobject)
63-
- [MinMax](#minmax)
64-
- [Calendar](#calendar)
6553

6654
## Parsing
6755

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

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

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

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

9078
#### Unix Timestamp (milliseconds)
9179

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

9482
```js
9583
dayjs(1318781876406)
9684
```
9785

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

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

10290
```js
10391
dayjs.unix(1318781876)
@@ -210,16 +198,16 @@ dayjs().get('day')
210198

211199
#### List of all available units
212200

213-
| 単位 | ショートハンド | 説明 |
214-
| ---- | ---- | ---- |
215-
| `date` | | 月の日ひち |
216-
| `day` | `d` | 曜日(日曜日は`0`、土曜日は`6`|
217-
| `month` | `M` | 月(1月は`0`12月は`11`|
218-
| `year` | `y` ||
219-
| `hour` | `h` ||
220-
| `minute` | `m` ||
221-
| `second` | `s` ||
222-
| `millisecond` | `ms` | ミリ秒 |
201+
| 単位 | ショートハンド | 説明 |
202+
| ------------- | -------------- | -------------------------------- |
203+
| `date` | | 月の日ひち |
204+
| `day` | `d` | 曜日(日曜日は`0`、土曜日は`6`|
205+
| `month` | `M` | 月(1 月は`0`12 月は`11` |
206+
| `year` | `y` | |
207+
| `hour` | `h` | |
208+
| `minute` | `m` | |
209+
| `second` | `s` | |
210+
| `millisecond` | `ms` | ミリ秒 |
223211

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

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

292280
#### List of all available formats
293281

294-
| フォーマット | 出力 | 説明 |
295-
| ------ | ---------------- | ------------------------------------- |
296-
| `YY` | 18 | 2桁の年 |
297-
| `YYYY` | 2018 | 4桁の年 |
298-
| `M` | 1-12 | 1始まりの月 |
299-
| `MM` | 01-12 | 1始まりの2桁の月 |
300-
| `MMM` | Jan-Dec | 月の略称 |
301-
| `MMMM` | January-December | 月の正式名 |
302-
| `D` | 1-31 | 月ごとの日にち |
303-
| `DD` | 01-31 | 月ごとの2桁の日にち |
304-
| `d` | 0-6 | `0`で日曜日から始まる曜日 |
305-
| `dd` | Su-Sa | 最も短い曜日の略称 |
306-
| `ddd` | Sun-Sat | 曜日の略称 |
307-
| `dddd` | Sunday-Saturday | 曜日名 |
308-
| `H` | 0-23 | 時間 |
309-
| `HH` | 00-23 | 2桁の時間 |
310-
| `h` | 1-12 | 12時制の時間 |
311-
| `hh` | 01-12 | 12時制で2桁の時間 |
312-
| `m` | 0-59 ||
313-
| `mm` | 00-59 | 2桁の分 |
314-
| `s` | 0-59 ||
315-
| `ss` | 00-59 | 2桁の秒 |
316-
| `SSS` | 000-999 | 3桁のミリ秒 |
317-
| `Z` | +5:00 | UTCからのオフセット |
318-
| `ZZ` | +0500 | UTCからの2桁のオフセット |
319-
| `A` | AM PM | 午前と午後(大文字) |
320-
| `a` | am pm | 午前と午後(小文字) |
282+
| フォーマット | 出力 | 説明 |
283+
| ------------ | ---------------- | --------------------------- |
284+
| `YY` | 18 | 2 桁の年 |
285+
| `YYYY` | 2018 | 4 桁の年 |
286+
| `M` | 1-12 | 1 始まりの月 |
287+
| `MM` | 01-12 | 1 始まりの 2 桁の月 |
288+
| `MMM` | Jan-Dec | 月の略称 |
289+
| `MMMM` | January-December | 月の正式名 |
290+
| `D` | 1-31 | 月ごとの日にち |
291+
| `DD` | 01-31 | 月ごとの 2 桁の日にち |
292+
| `d` | 0-6 | `0`で日曜日から始まる曜日 |
293+
| `dd` | Su-Sa | 最も短い曜日の略称 |
294+
| `ddd` | Sun-Sat | 曜日の略称 |
295+
| `dddd` | Sunday-Saturday | 曜日名 |
296+
| `H` | 0-23 | 時間 |
297+
| `HH` | 00-23 | 2 桁の時間 |
298+
| `h` | 1-12 | 12 時制の時間 |
299+
| `hh` | 01-12 | 12 時制で 2 桁の時間 |
300+
| `m` | 0-59 | |
301+
| `mm` | 00-59 | 2 桁の分 |
302+
| `s` | 0-59 | |
303+
| `ss` | 00-59 | 2 桁の秒 |
304+
| `SSS` | 000-999 | 3 桁のミリ秒 |
305+
| `Z` | +5:00 | UTC からのオフセット |
306+
| `ZZ` | +0500 | UTC からの 2 桁のオフセット |
307+
| `A` | AM PM | 午前と午後(大文字) |
308+
| `a` | am pm | 午前と午後(小文字) |
321309

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

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

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

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

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

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

342330
```js
343331
dayjs('2019-01-25').valueOf() // 1548381600000
344332
```
345333

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

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

350338
```js
351339
dayjs('2019-01-25').unix() // 1548381600
352340
```
353341

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

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

358346
```js
359347
dayjs().utcOffset()
@@ -377,15 +365,15 @@ dayjs('2019-01-25').toDate()
377365

378366
### As JSON `.toJSON()`
379367

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

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

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

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

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

446434
## UTC
447435

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

450438
## Plugin APIs
451439

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

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

458+
### WeekDay
459+
460+
`.weekday` to get or set locale aware day of the week
461+
462+
plugin [`WeekDay`](./Plugin.md#weekday)
463+
470464
### IsoWeeksInYear
471465

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

488482
### IsBetween
489483

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

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

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

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

522-
プラグイン [`Calendar`](./Plugin.md#calendar)
516+
プラグイン [`Calendar`](./Plugin.md#calendar)

docs/ja/Plugin.md

+13
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,19 @@ dayjs('06/27/2018').week() // 26
291291
dayjs('2018-06-27').week(5) // set week
292292
```
293293

294+
### WeekDay
295+
296+
- WeekDay adds `.weekday()` API to get or set locale aware day of the week.
297+
298+
```javascript
299+
import weekDay from 'dayjs/plugin/weekDay'
300+
301+
dayjs.extend(weekDay)
302+
// when Monday is the first day of the week
303+
dayjs().weekday(-7) // last Monday
304+
dayjs().weekday(7) // next Monday
305+
```
306+
294307
### IsoWeeksInYear
295308

296309
- IsoWeeksInYear adds `.isoWeeksInYear()` API to return a `number` to get the number of weeks in year, according to ISO weeks.

docs/ko/API-reference.md

+6
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,12 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear)
454454

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

457+
### WeekDay
458+
459+
`.weekday` to get or set locale aware day of the week
460+
461+
plugin [`WeekDay`](./Plugin.md#weekday)
462+
457463
### IsoWeeksInYear
458464

459465
`.isoWeeksInYear` to get the number of weeks in year

docs/ko/Plugin.md

+13
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,19 @@ dayjs('06/27/2018').week() // 26
283283
dayjs('2018-06-27').week(5) // set week
284284
```
285285

286+
### WeekDay
287+
288+
- WeekDay adds `.weekday()` API to get or set locale aware day of the week.
289+
290+
```javascript
291+
import weekDay from 'dayjs/plugin/weekDay'
292+
293+
dayjs.extend(weekDay)
294+
// when Monday is the first day of the week
295+
dayjs().weekday(-7) // last Monday
296+
dayjs().weekday(7) // next Monday
297+
```
298+
286299
### IsoWeeksInYear
287300

288301
- IsoWeeksInYear adds `.isoWeeksInYear()` API to return a `number` to get the number of weeks in year, according to ISO weeks.

docs/pt-br/API-reference.md

+6
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ plugin [`IsLeapYear`](./Plugin.md#isleapyear)
453453

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

456+
### WeekDay
457+
458+
`.weekday` to get or set locale aware day of the week
459+
460+
plugin [`WeekDay`](./Plugin.md#weekday)
461+
456462
### IsoWeeksInYear
457463

458464
`.isoWeeksInYear` to get the number of weeks in year

docs/pt-br/Plugin.md

+13
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@ dayjs('06/27/2018').week() // 26
282282
dayjs('2018-06-27').week(5) // set week
283283
```
284284

285+
### WeekDay
286+
287+
- WeekDay adds `.weekday()` API to get or set locale aware day of the week.
288+
289+
```javascript
290+
import weekDay from 'dayjs/plugin/weekDay'
291+
292+
dayjs.extend(weekDay)
293+
// when Monday is the first day of the week
294+
dayjs().weekday(-7) // last Monday
295+
dayjs().weekday(7) // next Monday
296+
```
297+
285298
### IsoWeeksInYear
286299

287300
- IsoWeeksInYear adds `.isoWeeksInYear()` API to return a `number` to get the number of weeks in year, according to ISO weeks.

docs/zh-cn/API-reference.md

+6
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,12 @@ dayjs() instanceof dayjs // true
505505

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

508+
### 星期
509+
510+
`.weekday` 来获取或设置当前语言的星期
511+
512+
plugin [`WeekDay`](./Plugin.md#weekday)
513+
508514
### 年中有几周 ISO
509515

510516
`.isoWeeksInYear` 获得年中有几周

0 commit comments

Comments
 (0)