Skip to content

Commit 60b6325

Browse files
authored
fix: update set week logic
chore: update set week logic Merge pull request #276 from iamkun/feature/iamkun
2 parents f483c66 + 27103f5 commit 60b6325

8 files changed

+67
-17
lines changed

docs/en/API-reference.md

+13
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,19 @@ dayjs().set('month', 3); // April
173173
dayjs().set('second', 30);
174174
```
175175

176+
#### List of all available units
177+
178+
| Unit | Shorthand | Description |
179+
| ------------- | --------- | ---------------------------------------- |
180+
| `date` | | Date of Month |
181+
| `day` | `d` | Day of Week (Sunday as 0, Saturday as 6) |
182+
| `month` | `M` | Month |
183+
| `year` | `y` | Year |
184+
| `hour` | `h` | Hour |
185+
| `minute` | `m` | Minute |
186+
| `second` | `s` | Second |
187+
| `millisecond` | `ms` | Millisecond |
188+
176189
## Manipulating
177190

178191
`Dayjs` objects can be manipulated in many ways.

docs/ja/API-reference.md

+13
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,19 @@ dayjs().set('month', 3); // 4月
209209
dayjs().set('second', 30);
210210
```
211211

212+
#### List of all available units
213+
214+
| Unit | Shorthand | Description |
215+
| ------------- | --------- | ---------------------------------------- |
216+
| `date` | | Date of Month |
217+
| `day` | `d` | Day of Week (Sunday as 0, Saturday as 6) |
218+
| `month` | `M` | Month |
219+
| `year` | `y` | Year |
220+
| `hour` | `h` | Hour |
221+
| `minute` | `m` | Minute |
222+
| `second` | `s` | Second |
223+
| `millisecond` | `ms` | Millisecond |
224+
212225
---
213226

214227
### Manipulate

docs/ko/API-reference.md

+13
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,19 @@ dayjs().set('month', 3); // April
173173
dayjs().set('second', 30);
174174
```
175175

176+
#### List of all available units
177+
178+
| Unit | Shorthand | Description |
179+
| ------------- | --------- | ---------------------------------------- |
180+
| `date` | | Date of Month |
181+
| `day` | `d` | Day of Week (Sunday as 0, Saturday as 6) |
182+
| `month` | `M` | Month |
183+
| `year` | `y` | Year |
184+
| `hour` | `h` | Hour |
185+
| `minute` | `m` | Minute |
186+
| `second` | `s` | Second |
187+
| `millisecond` | `ms` | Millisecond |
188+
176189
## Manipulating
177190

178191
`Dayjs` 오브젝트는 여러 방법으로 처리할 수 있습니다.

docs/pt-br/API-reference.md

+13
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,19 @@ dayjs().set('month', 3); // April
192192
dayjs().set('second', 30);
193193
```
194194

195+
#### List of all available units
196+
197+
| Unit | Shorthand | Description |
198+
| ------------- | --------- | ---------------------------------------- |
199+
| `date` | | Date of Month |
200+
| `day` | `d` | Day of Week (Sunday as 0, Saturday as 6) |
201+
| `month` | `M` | Month |
202+
| `year` | `y` | Year |
203+
| `hour` | `h` | Hour |
204+
| `minute` | `m` | Minute |
205+
| `second` | `s` | Second |
206+
| `millisecond` | `ms` | Millisecond |
207+
195208
---
196209

197210
### Manipulação

docs/zh-cn/API-reference.md

+14
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ dayjs().set('date', 1);
158158
dayjs().set('month', 3); // 四月
159159
dayjs().set('second', 30);
160160
```
161+
162+
#### 可用单位
163+
164+
| 单位 | 缩写 | 描述 |
165+
| ------------- | ---- | --------------------------- |
166+
| `date` | | 日期 |
167+
| `day` | `d` | 星期几 (星期天 0, 星期六 6) |
168+
| `month` | `M` ||
169+
| `year` | `y` ||
170+
| `hour` | `h` ||
171+
| `minute` | `m` ||
172+
| `second` | `s` ||
173+
| `millisecond` | `ms` | 毫秒 |
174+
161175
---
162176
### 操作
163177
您可以对 `Dayjs` 对象如下增加减少之类的操作:

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class Dayjs {
196196
const unit = Utils.prettyUnit(units)
197197
switch (unit) {
198198
case C.D:
199-
Utils.setDay(this.$d, int)
199+
this.$d.setDate(this.$D + (int - this.$W))
200200
break
201201
case C.DATE:
202202
this.$d.setDate(int)

src/utils.js

-10
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,7 @@ const prettyUnit = (u) => {
4040

4141
const isUndefined = s => s === undefined
4242

43-
const setDay = (date, day) => {
44-
const currentDay = date.getDay()
45-
const distance = day - currentDay
46-
47-
date.setDate(date.getDate() + distance)
48-
49-
return date
50-
}
51-
5243
export default {
53-
setDay,
5444
padStart,
5545
padZoneStr,
5646
monthDiff,

test/utils.test.js

-6
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,3 @@ it('PadStart', () => {
2626
expect(padStart(1, 2, '0')).toBe('01')
2727
expect(padStart(0, 2, '0')).toBe('00')
2828
})
29-
30-
it('SetDate', () => {
31-
const day = Math.floor((Math.random() * 7) % 6)
32-
33-
expect(Utils.setDay((new Date()), day).getDay()).toBe(day)
34-
})

0 commit comments

Comments
 (0)