generated from react-component/footer
-
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(getNow): improve the current time acquisition method (#878)
- Loading branch information
Showing
5 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import MockDate from 'mockdate'; | ||
import dayjsGenerateConfig from '../src/generate/dayjs'; | ||
|
||
import dayjs from 'dayjs'; | ||
import utc from 'dayjs/plugin/utc'; | ||
import timezone from 'dayjs/plugin/timezone'; | ||
import moment from 'moment-timezone'; | ||
|
||
dayjs.extend(utc); | ||
dayjs.extend(timezone); | ||
|
||
const CN = 'Asia/Shanghai'; | ||
const JP = 'Asia/Tokyo'; | ||
|
||
beforeEach(() => { | ||
MockDate.set(new Date()); | ||
dayjs.tz.setDefault(CN); | ||
moment.tz.setDefault(CN); | ||
}); | ||
|
||
afterEach(() => { | ||
dayjs.tz.setDefault(); | ||
moment.tz.setDefault(); | ||
MockDate.reset(); | ||
}); | ||
|
||
describe('dayjs: getNow', () => { | ||
it('normal', () => { | ||
const D_now = dayjsGenerateConfig.getNow(); | ||
const M_now = moment(); | ||
|
||
expect(D_now.format()).toEqual(M_now.format()); | ||
}); | ||
|
||
it('should work normally in timezone', async () => { | ||
dayjs.tz.setDefault(JP); | ||
const D_now = dayjsGenerateConfig.getNow(); | ||
const M_now = moment().tz(JP); | ||
|
||
expect(D_now.format()).toEqual(M_now.format()); | ||
expect(D_now.get('hour') - D_now.utc().get('hour')).toEqual(9); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
"src/**/*.tsx", | ||
"docs/examples/*.tsx", | ||
"tests/**/*.ts", | ||
"tests/**/*.tsx" | ||
"tests/**/*.tsx", | ||
"typings.d.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import 'dayjs/plugin/timezone'; | ||
|
||
export {}; |