-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[HOLD for payment 2024-03-19] [$500] Video duration is displayed incorrectly #37216
Comments
Job added to Upwork: https://www.upwork.com/jobs/~01c4ec8be79be38a61 |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat ( |
Triggered auto assignment to @abekkala ( |
ProposalPlease re-state the problem that we are trying to solve in this issue.For non-UTC timezones the video duration values aren't shown correctly What is the root cause of that problem?A new date gets created in the below function App/src/components/VideoPlayer/utils.ts Lines 4 to 7 in 03c81a6
What changes do you think we should make in order to solve the problem?Instead of using Date we can use the straight logic to convert milliseconds into the minutes and seconds like below. const minutes = Math.floor(milliseconds / 60000);
const seconds = String(((milliseconds % 60000) / 1000).toFixed(0)).padStart(2, '0');
return `${minutes}:${seconds}`; For including hours optionally we can do like below return hours > 0 ?
`${hours}:${String(minutes).padStart(2, '0')}:${seconds}` : `${minutes}:${seconds}`; |
ProposalPlease re-state the problem that we are trying to solve in this issue.Video duration is displayed incorrectly What is the root cause of that problem?In the function convertMillisecondsToTime, a new date is generated using the local timezone. The formatting applied to this date results in the representation of time in minutes, accounting for the respective timezone. What changes do you think we should make in order to solve the problem?We need to use import { formatDuration, intervalToDuration, utcToZonedTime } from 'date-fns-tz';
// Converts milliseconds to 'hours:minutes:seconds' or 'minutes:seconds' format in UTC
const convertMillisecondsToTime = (milliseconds: number) => {
// Create a new Date object with milliseconds since epoch
const date = new Date(0);
// Set the milliseconds
date.setUTCMilliseconds(milliseconds);
// Get the duration object
const duration = intervalToDuration({ start: 0, end: milliseconds });
// Format the duration in UTC timezone with hours, minutes, and seconds if applicable
const formattedDuration = formatDuration(duration, {
format: ['hours', 'minutes', 'seconds'],
});
// Format the date in UTC timezone with hours, minutes, and seconds if applicable
if (formattedDuration.hours > 0) {
return format(utcToZonedTime(date, 'UTC'), 'HH:mm:ss');
} else {
return format(utcToZonedTime(date, 'UTC'), 'mm:ss');
}
};
export default convertMillisecondsToTime; Result:simplescreenrecorder-2024-02-26_23.24.14.mp4Note:We already use App/tests/unit/DateUtilsTest.js Line 2 in 066d6c8
App/tests/actions/ReportTest.js Line 2 in 066d6c8
Note:We shouldn't use Where my proposal use of App/src/libs/actions/Report.ts Line 2075 in ba135b3
App/tests/actions/ReportTest.js Line 329 in ba135b3
|
This comment was marked as outdated.
This comment was marked as outdated.
Triggered auto assignment to @francoisl, see https://stackoverflow.com/c/expensify/questions/7972 for more details. |
@parasharrajat I think the selected proposal won't work as |
I think I will have to run this myself. Give me few minutes. |
If this is so then i guess we need to create a condition for the start condition and set the starting to 0 :) IMO, this should work, but again, i will also test the original proposal and get back. Update: Let me update a new proposal accordingly |
My bad, looks like the proposal is not working fine. I always see the same value for both start and end time. I will revisit the proposals in some time. |
I am not seeing the |
That too is a problem. |
ProposalPlease re-state the problem that we are trying to solve in this issue.Start and end time are using local timezone because of which it is using 30:00 for IST. What is the root cause of that problem?
What changes do you think we should make in order to solve the problem?We can ensure that it picks 00:00 for starting time and is based on UTC.
|
ProposalPlease re-state the problem that we are trying to solve in this issue.Wrong time on video What is the root cause of that problem?Calculation on What changes do you think we should make in order to solve the problem?We need to use a functioin that calculate without the need to the Date object. This will prevent all time zone issues. The function below will handle all cases. function convertMillisecondsToTime(milliseconds) {
// Return 00:00 if milliseconds is 0 or negative
if (milliseconds <= 0) {
return '00:00';
}
// Calculate minutes and seconds
const totalSeconds = Math.floor(milliseconds / 1000);
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
// Format minutes and seconds
const formattedMinutes = minutes < 10 ? `0${minutes}` : `${minutes}`;
const formattedSeconds = seconds < 10 ? `0${seconds}` : `${seconds}`;
// If less than one hour, return only minutes and seconds
if (minutes < 60) {
return `${formattedMinutes}:${formattedSeconds}`;
}
// If one hour or more, include hours, minutes, and seconds
const hours = Math.floor(minutes / 60);
const remainingMinutes = minutes % 60;
const formattedHours = hours < 10 ? `0${hours}` : `${hours}`;
// Return formatted time with hours, minutes, and seconds
return `${formattedHours}:${remainingMinutes}:${formattedSeconds}`;
}
export default MillisecondsToTime; With this adjustment, the function calculates hours, minutes and seconds directly from milliseconds without involving any timezone-dependent operations. This ensures the output is consistent regardless of the timezone. It also displat |
Updated proposal:@parasharrajat , updated my proposal to use |
ProposalPlease re-state the problem that we are trying to solve in this issue.For IST timezone(UTC + 5:30), It starts with 30:00 minutes What is the root cause of that problem?The duration is being formatted in a local time, which has minutes offset What changes do you think we should make in order to solve the problem?We can simply format the time in UTC timezone by updating this to
The Later once we support the
we can optionally use FYI: The What alternative solutions did you explore? (Optional)NA |
ProposalPlease re-state the problem that we are trying to solve in this issue.When adding a video attachment in the chat page, the preview of the video has the start duration at 30:00 instead of the expected 00:00 for the IST time zone. This issue does not exist for EST or PST time zones. What is the root cause of that problem?We are trying to convert duration into a Date object which is incompatible. A Date consists of a month, date, year, hour, minute, second and millisecond. The duration of a video does not and should not have month, date, year. The approach to convert duration in milliseconds to a Date object is flawed. What changes do you think we should make in order to solve the problem?Completely remove the
What alternative solutions did you explore? (Optional)n/a |
Having straight forward way to convert milliseconds to time is good.
then we can go with proposal from @dragnoir with little modifications for hours as well.
to
Along with including hours in formatted string. Sorry @Pujan92 actually missed your proposal of similar kind. ✔️ |
📣 @webbdays! 📣
|
ProposalPlease re-state the problem that we are trying to solve in this issue.Video duration is displayed incorrectly What is the root cause of that problem?The Date object constructor and formatting functions consider local time zone when creating and formatting the date. This leads to inconsistency if the local time zone differs from UTC.
What changes do you think we should make in order to solve the problem?We can simply pass const convertMillisecondsToTime = (milliseconds: number) => {
const date = new Date(0, 0, 0, 0, 0, 0, milliseconds);
return format(date, 'mm:ss');
}; Resulttime_stamp_bug.mp4AlternativeWe can get const convertMillisecondsToTime = (milliseconds: number) => {
// Convert milliseconds to hours, minutes, and seconds
const seconds = Math.floor(milliseconds / 1000);
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const remainingSeconds = seconds % 60;
// Format the time using date-fns
const formattedTime = format(new Date(0, 0, 0, hours, minutes, remainingSeconds), hours ? 'hh:mm:ss' : 'mm:ss');
return formattedTime;
}; |
@webbdays please note, the dependency on date-fns is not a new dependency. the old code imported date-fns. |
📣 @Pujan92 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app! Offer link |
@francoisl, @abekkala, @Pujan92, @parasharrajat Uh oh! This issue is overdue by 2 days. Don't forget to update your issues! |
Not overdue, PR has been created and linked |
|
The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.50-5 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue: If no regressions arise, payment will be issued on 2024-03-19. 🎊 For reference, here are some details about the assignees on this issue:
|
BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:
|
PAYMENT SUMMARY FOR MAR 19
|
BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:
Regression Test Steps
Do you agree 👍 or 👎 ? |
Regression Test Steps
|
@Pujan92 payment sent and contract ended - thank you! 🎉 |
PAYMENT SUMMARY FOR MAR 19
|
Payment requested as per #37216 (comment) |
$500 approved for @parasharrajat |
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number:
Reproducible in staging?: repro for IST timezone
Reproducible in production?: repro for IST timezone
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @MonilBhavsar
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1708409401548339
Action Performed:
Expected Result:
It should start with 00:00
##Actual Result:
For IST timezone(UTC + 5:30), It starts with 30:00 minutes
Workaround:
unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Screenshots/Videos
Add any screenshot/video evidence
View all open jobs on GitHub
Upwork Automation - Do Not Edit
The text was updated successfully, but these errors were encountered: