-
Notifications
You must be signed in to change notification settings - Fork 52
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
fix duration for workload #173
Conversation
/assign @samzong |
ui/apps/dashboard/src/utils/time.ts
Outdated
const startDate = dayjs(start); | ||
const endDate = dayjs(); // 当前时间 |
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.
The backend usually returns the server time, which should be UTC by default, and it may be necessary to handle the time zone differences; here, is it the browser time being obtained?
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.
it's a good question 🤔 , and dayjs(which we used in our project) use browser timezone in default, and if the timezone differs from local(here refer our personal computer) and server(which means the karmada-dashboard-api ), the calculation of duration may be wrong
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.
dayjs support plugin utc and timezone.
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.
dayjs support plugin utc and timezone.
yeah, but that's not key problem, key problem is the difference between client time for different regions. In fact the duration for workload is an absolute number, should be different across regions.
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.
maybe just convert it to the current time zone of the browser.
No need to consider multiple time zones. like this.
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
dayjs.extend(utc);
dayjs.extend(timezone);
export function calculateDuration(start: string | undefined) {
if (!start) return '-';
// Convert UTC server time to browser's local timezone
const startDate = dayjs.utc(start).local();
const endDate = dayjs();
const duration = dayjs.duration(endDate.diff(startDate));
return duration.humanize();
}
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.
+1, that's a good idea. Just now I still work on getting timezone from server and set defaut timezone for dayjs in frontend. Converting start(server time)
to client time is more simple than what i did just now, great~
I think we can squash the commits before moving this forward. |
2d161f6
to
a2e0189
Compare
thanks for your kindlly remind, 😄 |
Signed-off-by: warjiang <[email protected]>
a2e0189
to
4c6aa68
Compare
@samzong plz check it again~ |
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!
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: samzong The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind bug
What this PR does / why we need it:
The duration of workload is hard coded in the frontend code, just fix that.
Which issue(s) this PR fixes:
Fixes #169
Special notes for your reviewer:
Does this PR introduce a user-facing change?: