Skip to content

Commit 11c9cd1

Browse files
authored
Merge pull request #2914 from iamkun/dev
d2m
2 parents 93c8fd0 + aea0221 commit 11c9cd1

File tree

5 files changed

+108
-40
lines changed

5 files changed

+108
-40
lines changed

.github/workflows/check.yml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
name: Lint & Unit Test
22
on:
33
push:
4-
branches: [ master, dev ]
4+
branches: [master, dev]
55
pull_request:
66
branches: [dev]
77
jobs:
88
check:
99
runs-on: ubuntu-latest
10-
strategy:
11-
matrix:
12-
node: [ 12, 14, 16, 18 ]
1310
steps:
14-
- name: Checkout
15-
uses: actions/checkout@v3
16-
- name: Setup node
17-
uses: actions/setup-node@v3
18-
with:
19-
node-version: ${{ matrix.node-version }}
20-
cache: 'npm'
21-
- name: Install dependencies
22-
run: npm install -g codecov && npm install
23-
- name: Run Lint
24-
run: npm run lint
25-
- name: Run tests
26-
run: npm test && codecov
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
- name: Setup Node.js
14+
uses: actions/setup-node@v3
15+
with:
16+
node-version: 'lts/*'
17+
cache: 'npm'
18+
- name: Install dependencies
19+
run: npm install -g codecov && npm install
20+
- name: Run Lint
21+
run: npm run lint
22+
- name: Run tests
23+
run: npm test
24+
- name: Upload coverage
25+
run: codecov || echo "Codecov upload failed, continuing..."

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,20 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
119119
<img width="70" src="https://avatars.githubusercontent.com/u/65305317?v=4">
120120
</a>
121121
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
122-
<a href="https://opencollective.com/sight-and-sound-ministries" target="_blank">
123-
<img width="70" src="https://user-images.githubusercontent.com/17680888/232316426-cb99b4cf-0ccb-4e73-a6ce-e16dba6aadf4.png">
122+
<a href="https://opencollective.com/sight-sound" target="_blank">
123+
<img width="70" src="https://images.opencollective.com/sight-sound/54f7220/logo/256.png?height=256">
124124
</a>
125125
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
126-
<a href="https://chudovo.com/" target="_blank">
127-
<img width="70" src="https://images.opencollective.com/chudovo/3c866f5/logo/256.png?height=256">
128-
</a>
129-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
130-
<a href="https://www.honrev.com" target="_blank">
131-
<img width="70" src="https://github.com/user-attachments/assets/b3203350-34c1-4637-b8b1-d9b8bab346d3">
126+
<a href="https://www.exoflare.com/open-source/?utm_source=dayjs&utm_campaign=open_source" target="_blank">
127+
<img width="70" src="https://user-images.githubusercontent.com/17680888/162761622-1407a849-0c41-4591-8aa9-f98114ec2092.png">
132128
</a>
133129
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
134-
<a href="https://github.com/alan-eu" target="_blank">
135-
<img width="70" src="https://avatars.githubusercontent.com/u/18175329?s=52&v=4">
130+
<a href="https://chudovo.com/front-end-development/" target="_blank">
131+
<img width="70" src="https://images.opencollective.com/chudovo/3c866f5/logo/256.png?height=256">
136132
</a>
137133
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
138-
<a href="https://www.exoflare.com/open-source/?utm_source=dayjs&utm_campaign=open_source" target="_blank">
139-
<img width="70" src="https://user-images.githubusercontent.com/17680888/162761622-1407a849-0c41-4591-8aa9-f98114ec2092.png">
134+
<a href="https://github.com/radioplusexperts" target="_blank">
135+
<img width="70" src="https://avatars.githubusercontent.com/u/188567998?v=4">
140136
</a>
141137
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
142138
<a href="https://github.com/storyblok" target="_blank">
@@ -147,9 +143,21 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
147143
<img width="70" src="https://avatars.githubusercontent.com/u/159320286" alt="BestKru">
148144
</a>
149145
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
146+
<a href="https://handsontable.com/docs/react-data-grid/?utm_source=Dayjs_GH&utm_medium=sponsorship&utm_campaign=library_sponsorship" target="_blank">
147+
<img width="70" src="https://github.com/user-attachments/assets/426c3476-dc34-44d1-a904-ed58dbd20dd6">
148+
</a>
149+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
150150
<a href="https://route4me.com/" target="_blank">
151151
<img width="70" src="https://github.com/user-attachments/assets/3fbc86c5-98a9-49c2-beae-1969026fcd76" alt="Route Optimizer and Route Planner Software">
152152
</a>
153+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
154+
<a href="https://github.com/Nftsworld007" target="_blank">
155+
<img width="70" src="https://avatars.githubusercontent.com/u/133202490">
156+
</a>
157+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
158+
<a href="https://github.com/sentdm" target="_blank">
159+
<img width="70" src="https://avatars.githubusercontent.com/u/153308555?s=200&v=4">
160+
</a>
153161

154162

155163
## Contributors

docs/demo/index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,42 @@ dayjs().format('YYYY-MM-DD')
1010

1111
// locale
1212
dayjs().locale('zh-cn').format()
13+
14+
// add
15+
dayjs().add(1, 'year').format()
16+
17+
// subtract
18+
dayjs().subtract(1, 'year').format()
19+
20+
// diff
21+
dayjs().diff(dayjs().add(1, 'year'), 'year')
22+
23+
// isBefore
24+
dayjs().isBefore(dayjs().add(1, 'year'))
25+
26+
// isAfter
27+
dayjs().isAfter(dayjs().subtract(1, 'year'))
28+
29+
// isSame
30+
dayjs().isSame(dayjs())
31+
32+
// isLeapYear
33+
dayjs().isLeapYear()
34+
35+
// isBetween
36+
dayjs().isBetween(dayjs().subtract(1, 'year'), dayjs().add(1, 'year'))
37+
38+
// isSameOrAfter
39+
dayjs().isSameOrAfter(dayjs().subtract(1, 'year'))
40+
41+
// isSameOrBefore
42+
dayjs().isSameOrBefore(dayjs().add(1, 'year'))
43+
44+
// startOf
45+
dayjs().startOf('year').format()
46+
47+
// endOf
48+
dayjs().endOf('year').format()
49+
50+
// week
51+
dayjs().week()

src/plugin/utc/index.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,25 @@ export default (option, Dayjs, dayjs) => {
8787
}
8888
}
8989
const offset = Math.abs(input) <= 16 ? input * 60 : input
90-
let ins = this
90+
91+
if (offset === 0) {
92+
return this.utc(keepLocalTime)
93+
}
94+
95+
let ins = this.clone()
96+
9197
if (keepLocalTime) {
9298
ins.$offset = offset
93-
ins.$u = input === 0
99+
ins.$u = false
94100
return ins
95101
}
96-
if (input !== 0) {
97-
const localTimezoneOffset = this.$u
98-
? this.toDate().getTimezoneOffset() : -1 * this.utcOffset()
99-
ins = this.local().add(offset + localTimezoneOffset, MIN)
100-
ins.$offset = offset
101-
ins.$x.$localOffset = localTimezoneOffset
102-
} else {
103-
ins = this.utc()
104-
}
102+
103+
const localTimezoneOffset = this.$u
104+
? this.toDate().getTimezoneOffset() : -1 * this.utcOffset()
105+
ins = this.local().add(offset + localTimezoneOffset, MIN)
106+
ins.$offset = offset
107+
ins.$x.$localOffset = localTimezoneOffset
108+
105109
return ins
106110
}
107111

test/plugin/utc-utcOffset.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,21 @@ test('utc startOf', () => {
149149
expect(d2d)
150150
.toBe(1500465600000)
151151
})
152+
153+
test('cloning dates modified with utcOffset', () => {
154+
const djs = dayjs('2023-10-29T00:00:00+03:00')
155+
156+
const tests = [
157+
djs,
158+
djs.utcOffset(-240),
159+
djs.utcOffset(-240, true),
160+
djs.utcOffset(120),
161+
djs.utcOffset(120, true),
162+
djs.utcOffset(0),
163+
djs.utcOffset(0, true)
164+
]
165+
166+
tests.forEach((d) => {
167+
expect(dayjs(d).format()).toEqual(d.format())
168+
})
169+
})

0 commit comments

Comments
 (0)