Skip to content
Merged

d2m #2914

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
name: Lint & Unit Test
on:
push:
branches: [ master, dev ]
branches: [master, dev]
pull_request:
branches: [dev]
jobs:
check:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 12, 14, 16, 18 ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm install -g codecov && npm install
- name: Run Lint
run: npm run lint
- name: Run tests
run: npm test && codecov
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
cache: 'npm'
- name: Install dependencies
run: npm install -g codecov && npm install
- name: Run Lint
run: npm run lint
- name: Run tests
run: npm test
- name: Upload coverage
run: codecov || echo "Codecov upload failed, continuing..."
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,20 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
<img width="70" src="https://avatars.githubusercontent.com/u/65305317?v=4">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://opencollective.com/sight-and-sound-ministries" target="_blank">
<img width="70" src="https://user-images.githubusercontent.com/17680888/232316426-cb99b4cf-0ccb-4e73-a6ce-e16dba6aadf4.png">
<a href="https://opencollective.com/sight-sound" target="_blank">
<img width="70" src="https://images.opencollective.com/sight-sound/54f7220/logo/256.png?height=256">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://chudovo.com/" target="_blank">
<img width="70" src="https://images.opencollective.com/chudovo/3c866f5/logo/256.png?height=256">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://www.honrev.com" target="_blank">
<img width="70" src="https://github.com/user-attachments/assets/b3203350-34c1-4637-b8b1-d9b8bab346d3">
<a href="https://www.exoflare.com/open-source/?utm_source=dayjs&utm_campaign=open_source" target="_blank">
<img width="70" src="https://user-images.githubusercontent.com/17680888/162761622-1407a849-0c41-4591-8aa9-f98114ec2092.png">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://github.com/alan-eu" target="_blank">
<img width="70" src="https://avatars.githubusercontent.com/u/18175329?s=52&v=4">
<a href="https://chudovo.com/front-end-development/" target="_blank">
<img width="70" src="https://images.opencollective.com/chudovo/3c866f5/logo/256.png?height=256">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://www.exoflare.com/open-source/?utm_source=dayjs&utm_campaign=open_source" target="_blank">
<img width="70" src="https://user-images.githubusercontent.com/17680888/162761622-1407a849-0c41-4591-8aa9-f98114ec2092.png">
<a href="https://github.com/radioplusexperts" target="_blank">
<img width="70" src="https://avatars.githubusercontent.com/u/188567998?v=4">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://github.com/storyblok" target="_blank">
Expand All @@ -147,9 +143,21 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
<img width="70" src="https://avatars.githubusercontent.com/u/159320286" alt="BestKru">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://handsontable.com/docs/react-data-grid/?utm_source=Dayjs_GH&utm_medium=sponsorship&utm_campaign=library_sponsorship" target="_blank">
<img width="70" src="https://github.com/user-attachments/assets/426c3476-dc34-44d1-a904-ed58dbd20dd6">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://route4me.com/" target="_blank">
<img width="70" src="https://github.com/user-attachments/assets/3fbc86c5-98a9-49c2-beae-1969026fcd76" alt="Route Optimizer and Route Planner Software">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://github.com/Nftsworld007" target="_blank">
<img width="70" src="https://avatars.githubusercontent.com/u/133202490">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://github.com/sentdm" target="_blank">
<img width="70" src="https://avatars.githubusercontent.com/u/153308555?s=200&v=4">
</a>


## Contributors
Expand Down
39 changes: 39 additions & 0 deletions docs/demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,42 @@ dayjs().format('YYYY-MM-DD')

// locale
dayjs().locale('zh-cn').format()

// add
dayjs().add(1, 'year').format()

// subtract
dayjs().subtract(1, 'year').format()

// diff
dayjs().diff(dayjs().add(1, 'year'), 'year')

// isBefore
dayjs().isBefore(dayjs().add(1, 'year'))

// isAfter
dayjs().isAfter(dayjs().subtract(1, 'year'))

// isSame
dayjs().isSame(dayjs())

// isLeapYear
dayjs().isLeapYear()

// isBetween
dayjs().isBetween(dayjs().subtract(1, 'year'), dayjs().add(1, 'year'))

// isSameOrAfter
dayjs().isSameOrAfter(dayjs().subtract(1, 'year'))

// isSameOrBefore
dayjs().isSameOrBefore(dayjs().add(1, 'year'))

// startOf
dayjs().startOf('year').format()

// endOf
dayjs().endOf('year').format()

// week
dayjs().week()
26 changes: 15 additions & 11 deletions src/plugin/utc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,25 @@ export default (option, Dayjs, dayjs) => {
}
}
const offset = Math.abs(input) <= 16 ? input * 60 : input
let ins = this

if (offset === 0) {
return this.utc(keepLocalTime)
}

let ins = this.clone()

if (keepLocalTime) {
ins.$offset = offset
ins.$u = input === 0
ins.$u = false
return ins
}
if (input !== 0) {
const localTimezoneOffset = this.$u
? this.toDate().getTimezoneOffset() : -1 * this.utcOffset()
ins = this.local().add(offset + localTimezoneOffset, MIN)
ins.$offset = offset
ins.$x.$localOffset = localTimezoneOffset
} else {
ins = this.utc()
}

const localTimezoneOffset = this.$u
? this.toDate().getTimezoneOffset() : -1 * this.utcOffset()
ins = this.local().add(offset + localTimezoneOffset, MIN)
ins.$offset = offset
ins.$x.$localOffset = localTimezoneOffset

return ins
}

Expand Down
18 changes: 18 additions & 0 deletions test/plugin/utc-utcOffset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,21 @@ test('utc startOf', () => {
expect(d2d)
.toBe(1500465600000)
})

test('cloning dates modified with utcOffset', () => {
const djs = dayjs('2023-10-29T00:00:00+03:00')

const tests = [
djs,
djs.utcOffset(-240),
djs.utcOffset(-240, true),
djs.utcOffset(120),
djs.utcOffset(120, true),
djs.utcOffset(0),
djs.utcOffset(0, true)
]

tests.forEach((d) => {
expect(dayjs(d).format()).toEqual(d.format())
})
})
Loading