generated from react-component/footer
-
-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(getNow): improve the current time acquisition method #878
Merged
afc163
merged 6 commits into
react-component:master
from
Wxh16144-forks:wuxh/try-fix-antd_50934
Sep 24, 2024
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
292eb69
feat(getNow): Improve the current time acquisition method
Wxh16144 cfa83ea
test: add unit test
Wxh16144 1d6b65a
fix: unit test
Wxh16144 8c8d083
chore: update?
Wxh16144 7930087
test: CI
Wxh16144 2f31f29
chore: update logic
Wxh16144 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,40 @@ | ||
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()); | ||
}); | ||
|
||
afterEach(() => { | ||
dayjs.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 {}; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议移除空的导出语句。
空的导出语句在这里是不必要的,因为文件已经有了一个导入语句。移除它可以使代码更简洁。
建议应用以下更改:
import 'dayjs/plugin/timezone'; - export {};
Committable suggestion
Tools
Biome