-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
refactor(moment): Replace Moment.js with DayJs #31310
Conversation
It sounds like Ant Design v4 is one hangup here. Pinging @geido since we're in the process of upgrading from v4 to v5, one component at a time. Would v5's Datepicker component mitigate this issue? If so, perhaps we can prioritize that, to get this PR through more easily. |
@rusackas This PR and the Datepicker PR kind of depend on each other since Ant design v4 uses Moment and v5 uses Dayjs. In my opinion finishing the Moment to Dayjs migration on datepicker PR is the most straightforward way. |
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.
Review by Korbit AI
Category | Issue |
---|---|
Incorrect Time Unit Documentation ▹ view | |
Missing Day.js Locale Plugin ▹ view | |
Incorrect Duration Calculation Method ▹ view | |
Redundant Timezone Conversion ▹ view |
Files scanned
File Path | Reviewed |
---|---|
superset-frontend/src/components/CachedLabel/TooltipContent.tsx | ✅ |
superset-frontend/src/components/Timer/Timer.stories.tsx | ✅ |
superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/utils.ts | ✅ |
superset-frontend/src/components/ListView/Filters/DateRange.tsx | ✅ |
superset-frontend/src/preamble.ts | ✅ |
superset-frontend/plugins/plugin-chart-handlebars/src/components/Handlebars/HandlebarsViewer.tsx | ✅ |
superset-frontend/src/explore/components/controls/DateFilterControl/utils/dateParser.ts | ✅ |
superset-frontend/src/components/LastUpdated/index.tsx | ✅ |
superset-frontend/src/utils/dates.ts | ✅ |
superset-frontend/src/features/allEntities/AllEntitiesTable.tsx | ✅ |
superset-frontend/src/pages/ExecutionLogList/index.tsx | ✅ |
superset-frontend/src/visualizations/TimeTable/SparklineCell.tsx | ✅ |
superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts | ✅ |
superset-frontend/src/features/home/ActivityTable.tsx | ✅ |
superset-frontend/src/dashboard/components/OverwriteConfirm/OverwriteConfirmModal.tsx | ✅ |
superset-frontend/src/features/datasets/AddDataset/EditDataset/UsageTab/index.tsx | ✅ |
superset-frontend/src/pages/AllEntities/index.tsx | ✅ |
superset-frontend/src/explore/components/controls/TimeOffsetControl.tsx | ✅ |
superset-frontend/src/components/TimezoneSelector/index.tsx | ✅ |
superset-frontend/src/features/annotations/AnnotationModal.tsx | ✅ |
superset-frontend/src/pages/AnnotationList/index.tsx | ✅ |
superset-frontend/src/SqlLab/components/QueryTable/index.tsx | ✅ |
superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx | ✅ |
superset-frontend/src/pages/QueryHistoryList/index.tsx | ✅ |
superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx | ✅ |
superset-frontend/src/pages/AlertReportList/index.tsx | ✅ |
superset-frontend/webpack.config.js | ✅ |
superset-frontend/src/components/Chart/chartAction.js | ✅ |
superset-frontend/src/dashboard/components/Header/index.jsx | ✅ |
superset-frontend/plugins/legacy-preset-chart-nvd3/src/NVD3Vis.js | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Need a new review? Comment
/korbit-review
on this PR and I'll review your latest changes.Korbit Guide: Usage and Customization
Interacting with Korbit
- You can manually ask Korbit to review your PR using the
/korbit-review
command in a comment at the root of your PR.- You can ask Korbit to generate a new PR description using the
/korbit-generate-pr-description
command in any comment on your PR.- Too many Korbit comments? I can resolve all my comment threads if you use the
/korbit-resolve
command in any comment on your PR.- Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
- Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.
Customizing Korbit
- Check out our docs on how you can make Korbit work best for you and your team.
- Customize Korbit for your organization through the Korbit Console.
Current Korbit Configuration
General Settings
Setting Value Review Schedule Automatic excluding drafts Max Issue Count 10 Automatic PR Descriptions ❌ Issue Categories
Category Enabled Naming ✅ Database Operations ✅ Documentation ✅ Logging ✅ Error Handling ✅ Systems and Environment ✅ Objects and Data Structures ✅ Readability and Maintainability ✅ Asynchronous Processing ✅ Design Patterns ✅ Third-Party Libraries ✅ Performance ✅ Security ✅ Functionality ✅ Feedback and Support
Note
Korbit Pro is free for open source projects 🎉
Looking to add Korbit to your team? Get started with a free 2 week trial here
export const now = function (): number { | ||
// seconds from EPOCH as a float | ||
return dayjs().utc().valueOf(); | ||
}; |
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.
Incorrect Time Unit Documentation
Tell me more
What is the issue?
The comment is incorrect as valueOf() returns milliseconds since epoch, not seconds
Why this matters
This misleading comment could cause integration issues if other developers rely on the comment's description of the return value being in seconds.
Suggested change
export const now = function (): number {
// milliseconds from EPOCH as a number
return dayjs().utc().valueOf();
};
Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.
@@ -44,7 +44,7 @@ const bootstrapData = getBootstrapData(); | |||
// Configure translation | |||
if (typeof window !== 'undefined') { | |||
configure({ languagePack: bootstrapData.common.language_pack }); | |||
moment.locale(bootstrapData.common.locale); | |||
dayjs.locale(bootstrapData.common.locale); |
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.
Missing Day.js Locale Plugin
Tell me more
What is the issue?
Day.js locale support requires loading the appropriate locale plugin before setting the locale.
Why this matters
Without loading the locale plugin first, the locale setting will have no effect, causing date formatting to fallback to default English locale regardless of user preferences.
Suggested change
Import and load the Day.js locale plugin before setting the locale:
import dayjs from 'dayjs';
import LocalizedFormat from 'dayjs/plugin/localizedFormat';
dayjs.extend(LocalizedFormat);
Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.
export const fDuration = function ( | ||
t1: number, | ||
t2: number, | ||
format = 'HH:mm:ss.SSS', | ||
): string { | ||
const diffSec = t2 - t1; | ||
const duration = dayjs(new Date(diffSec)); | ||
return duration.utc().format(format); | ||
}; |
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.
Incorrect Duration Calculation Method
Tell me more
What is the issue?
The fDuration function incorrectly calculates duration by creating a date from the difference in milliseconds instead of using dayjs.duration()
Why this matters
This will produce incorrect duration formatting as it treats the millisecond difference as an epoch timestamp rather than a duration, leading to unexpected results when formatting the time difference.
Suggested change
export const fDuration = function (
t1: number,
t2: number,
format = 'HH:mm:ss.SSS',
): string {
return dayjs.duration(t2 - t1).format(format);
};
Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.
@@ -82,43 +70,40 @@ export default function TimezoneSelector({ | |||
const getTimezoneName = (name: string) => { | |||
const offsets = getOffsetKey(name); | |||
return ( | |||
(currentDate.tz(name).isDST() | |||
(isDST(currentDate.tz(name), name) |
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.
Redundant Timezone Conversion
Tell me more
What is the issue?
Double timezone conversion might occur as the date is already converted to the timezone before being passed to isDST, which might also perform a timezone conversion.
Why this matters
Unnecessary timezone conversions can lead to edge case bugs around DST boundaries and increase the chance of timezone-related calculation errors.
Suggested change
Pass the unconverted currentDate to isDST and let it handle the timezone conversion: isDST(currentDate, name)
Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.
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.
Great job! A few nits
...ntend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts
Show resolved
Hide resolved
superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx
Outdated
Show resolved
Hide resolved
superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx
Outdated
Show resolved
Hide resolved
superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx
Outdated
Show resolved
Hide resolved
superset-frontend/src/features/alerts/AlertReportModal.test.tsx
Outdated
Show resolved
Hide resolved
@@ -119,7 +119,7 @@ function ExecutionLog({ | |||
original: { scheduled_dttm: scheduledDttm }, | |||
}, | |||
}: any) => |
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.
Can we now use a better type than any
?
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.
For this one i think keeping any is ok still
SUMMARY
This pr aims to replace Moment.js with Day.js as the former is a legacy project and is in maintenance mode. There were some design decisions made:
I decided on the last option since other two seemed overkill for a temporary hurdle.
Day.js object needed to be extended to support our usages. I centralized that in
extendedDayjs
to prevent confusion. Alternative to this is to extend where its used.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
Run the testing suite.
ADDITIONAL INFORMATION