You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Awaiting checklist completion] [$500] Request money - Calendar is showing the wrong date #31416
Version Number: 1.4.0-0 Reproducible in staging?: Y Reproducible in production?: Y 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: Applause - Internal Team Slack conversation:
Action Performed:
Go to staging.new.expensify.com
Go to + > Request money > Manual
Enter an amount and click Next
Select a participant and proceed to the next page
Click Show more
Click Date
Expected Result:
The calendar is accurate
Actual Result:
The calendar is inaccurate. The dates are one day ahead. The week on the calendar starts from Monday to Sunday instead of Sunday to Saturday
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
changed the title [-]Request money - Calendar is showing the wrong date[/-][+][$500] Request money - Calendar is showing the wrong date[/+]on Nov 16, 2023
While the matrix of days assume it starts on Sunday (technically it checks it ends on Saturday by checking if day == 6 before starting a new week)
What changes do you think we should make in order to solve the problem?
conststartOfCurrentWeek=startOfWeek(newDate(),{weekStartsOn: 0});// Assuming Sunday is the start of the weekconstendOfCurrentWeek=endOfWeek(newDate(),{weekStartsOn: 0});// Assuming Sunday is the start of the week
Update the start of the week to Sunday.
Before:
After:
Or update the matrix to use Monday as the start date:
// Add null values for days before the first day of the monthfor(leti=1;i<getDay(firstDayOfMonth);i++){// changed starting value for I to 1currentWeek.push(null);}// Start a new row when the current week is fullif(getDay(currentDate)===0){// changed to 0matrix.push(currentWeek);currentWeek=[];}
After:
This should align both elements of the calendar on when the week starts.
Another proposal below if we want to adapt to user's preferences, which might be better as people are used to different things depending on where they are.
What alternative solutions did you explore? (Optional)
The confusion here is because certain places in the world the week starts on Sunday while others on Monday. The matrix of days always assume Sunday as the start of the day and the header assumes Monday, that's why the disconnect. Another option would be to actually determine what's the first day of the week based on user's locale (preferredLocale: Locale) and adjust accordingly.
new Intl.Locale('en-us').weekInfo.firstDay could potentially be used, although might not be always available, which case we fallback to starting Sunday.
Something like this (code need polishing, just for illustration purposes):
letweekStartsOn=0;// Assuming Sunday is the default start of the weekif(Intl&&Intl.Locale){constweekInfo=newIntl.Locale(preferredLocale).weekInfo;if(weekInfo&&weekInfo.firstDay){weekStartsOn=weekInfo.firstDay===7 ? 0 : weekInfo.firstDay;}}
We could also hardcode the rules as the list of available Locales are hardcoded as well with only a few options. Basically en = Sunday, es = Monday.
We an extract this logic into a function on DateUtils.js and use it when generating the calendar header and date matrix. Once we determine the start of the week we could shift the days matrix accordingly.
Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.
Please re-state the problem that we are trying to solve in this issue.
The calendar is inaccurate. The dates are one day ahead. The week on the calendar starts from Monday to Sunday instead of Sunday to Saturday
What is the root cause of that problem?
In here, we're configuring for the week to start on Monday (1), but when generate the calendar day matrix, we still use utils getDay from date-fns in here which assumes the week starts on Sunday.
So for example, first day of November is a Wednesday, and getDay will return 3 (which is the index of Wed in week-start-at-Sunday-based date system, 0 - Sun, 1 - Mon, 2 - Tue, 3 - Wed), according to this we'll push 3 null values in the first week. Which is wrong since if the week starts on Mon, only Mon and Tue should be null.
What changes do you think we should make in order to solve the problem?
Configure date-fns methods that are used to generate date matrix to assume the week starts on Monday.
For getDay inside here, we need to add a new method
To explain more on that method, if the week starts on Monday, then:
Sunday will become index 6, aka (0 + 6) % 7 (0 is the result of getDay(date) based on week-start-on-Sunday calendar system, will be converted to 6 in the week-start-on-Monday-calendar system)
Monday will become index 0, aka (1 + 6) % 7
Tuesday will become index 1, aka (2 + 6) % 7
...
What alternative solutions did you explore? (Optional)
The number 6 above seems a bit random because we're assuming Monday. A more general implementation that will work for any weekStartsOn value is
I will review the date calculation logic in your code and will ensure that the dates are being calculated accurately. If the dates are consistently one day ahead, there might be an offset in your date calculations.
Verify that your application is handling time zones correctly. Inconsistencies in time zone handling can lead to date discrepancies. I I I will ensure that the server and client are configured to use the same time zone.
If you're using any third-party calendar libraries, make sure they are up to date
Steps:
step 1 -> we have to find calendarView in project
step 2 -> In calendarView we have to set US locale (US locale start from Sunday to Saturday ) because in android device Calendar depends on Locale and in your case may be locale working automatically according to location
📣 @techdevelopers08! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:
Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
changed the title [-][HOLD for payment 2024-01-05] [$500] Request money - Calendar is showing the wrong date[/-][+][Awaiting checklist completion] [$500] Request money - Calendar is showing the wrong date[/+]on Jan 5, 2024
A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: N/A
Determine if we should create a regression test for this bug.
If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
No need regression test because this was reported by QA team and we added automated tests to prevent this bug further.
Let @Carlos Barros implement this. Also give @Tienifr bonus for raising this discussion because without them, we could have implemented locale based solution
If it's a better middle ground, we can also not process the $250 refund and just pay out $250 for @tienifr.
@twisterdotcom yeah, the conversation was a little vague and not super clear. Ultimately we should do what’s right based on defined internal process (if any) for these cases. If it means I get to keep the full payment, great. If it means I should process the refund, that’s totally fine as well. Just let me know how to proceed and I’ll act accordingly.
@barros001 made good efforts for making complete PR so it seems not fair to me to split equal compensation between them. So I suggest to cancel refund (just my opinion. Final decision will be from internal team ofc)
Activity
[-]Request money - Calendar is showing the wrong date[/-][+][$500] Request money - Calendar is showing the wrong date[/+]melvin-bot commentedon Nov 16, 2023
Triggered auto assignment to @twisterdotcom (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.melvin-bot commentedon Nov 16, 2023
Job added to Upwork: https://www.upwork.com/jobs/~0135c08e4c75c14697
melvin-bot commentedon Nov 16, 2023
Bug0 Triage Checklist (Main S/O)
Platformsin OP are ✅)melvin-bot commentedon Nov 16, 2023
Triggered auto assignment to Contributor-plus team member for initial proposal review - @0xmiroslav (
External)barros001 commentedon Nov 16, 2023
Proposal
Please re-state the problem that we are trying to solve in this issue.
Calendar / DatePicker weekdays header is off, ahead by one day.
What is the root cause of that problem?
App/src/libs/DateUtils.ts
Lines 148 to 151 in 5e01376
Code assumes week starts on Monday when rendering the weekdays header (I starts at 0)
App/src/components/NewDatePicker/CalendarPicker/generateMonthMatrix.js
Lines 35 to 38 in 69a3358
App/src/components/NewDatePicker/CalendarPicker/generateMonthMatrix.js
Lines 45 to 50 in 69a3358
While the matrix of days assume it starts on Sunday (technically it checks it ends on Saturday by checking if day == 6 before starting a new week)
What changes do you think we should make in order to solve the problem?
Update the start of the week to Sunday.
Before:

After:

Or update the matrix to use Monday as the start date:
After:

This should align both elements of the calendar on when the week starts.
Another proposal below if we want to adapt to user's preferences, which might be better as people are used to different things depending on where they are.
What alternative solutions did you explore? (Optional)
The confusion here is because certain places in the world the week starts on Sunday while others on Monday. The matrix of days always assume Sunday as the start of the day and the header assumes Monday, that's why the disconnect. Another option would be to actually determine what's the first day of the week based on user's locale (
preferredLocale: Locale) and adjust accordingly.new Intl.Locale('en-us').weekInfo.firstDaycould potentially be used, although might not be always available, which case we fallback to starting Sunday.Something like this (code need polishing, just for illustration purposes):
We could also hardcode the rules as the list of available Locales are hardcoded as well with only a few options. Basically
en = Sunday, es = Monday.We an extract this logic into a function on
DateUtils.jsand use it when generating the calendar header and date matrix. Once we determine the start of the week we could shift the days matrix accordingly.Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.
tienifr commentedon Nov 16, 2023
Proposal
Please re-state the problem that we are trying to solve in this issue.
The calendar is inaccurate. The dates are one day ahead. The week on the calendar starts from Monday to Sunday instead of Sunday to Saturday
What is the root cause of that problem?
In here, we're configuring for the week to start on Monday (1), but when generate the calendar day matrix, we still use utils
getDayfrom date-fns in here which assumes the week starts on Sunday.So for example, first day of November is a Wednesday, and
getDaywill return 3 (which is the index of Wed in week-start-at-Sunday-based date system, 0 - Sun, 1 - Mon, 2 - Tue, 3 - Wed), according to this we'll push 3 null values in the first week. Which is wrong since if the week starts on Mon, only Mon and Tue should be null.What changes do you think we should make in order to solve the problem?
Configure
date-fnsmethods that are used to generate date matrix to assume the week starts on Monday.For
getDayinside here, we need to add a new methodAnd use it in instead of
getDay.To explain more on that method, if the week starts on Monday, then:
...
What alternative solutions did you explore? (Optional)
The number 6 above seems a bit random because we're assuming Monday. A more general implementation that will work for any
weekStartsOnvalue isThat might be more consistent with our implementation here, we can put 1 to a
WEEK_STARTS_ONconstant and reuse in both places for consistency.If we're ok to let the week start on Sunday instead, we can remove the Monday customization here
apptechies commentedon Nov 16, 2023
I will review the date calculation logic in your code and will ensure that the dates are being calculated accurately. If the dates are consistently one day ahead, there might be an offset in your date calculations.
Verify that your application is handling time zones correctly. Inconsistencies in time zone handling can lead to date discrepancies. I I I will ensure that the server and client are configured to use the same time zone.
If you're using any third-party calendar libraries, make sure they are up to date
Steps:
step 1 -> we have to find calendarView in project
step 2 -> In calendarView we have to set US locale (US locale start from Sunday to Saturday ) because in android device Calendar depends on Locale and in your case may be locale working automatically according to location
Contributor details
Your Expensify account email: ajay@techangouts.com
Upwork Profile Link: https://www.upwork.com/freelancers/ajaychaudhary11
melvin-bot commentedon Nov 16, 2023
📣 @techdevelopers08! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:
Format:
47 remaining items
[-][HOLD for payment 2024-01-05] [$500] Request money - Calendar is showing the wrong date[/-][+][Awaiting checklist completion] [$500] Request money - Calendar is showing the wrong date[/+]0xmiroslav commentedon Jan 5, 2024
No need regression test because this was reported by QA team and we added automated tests to prevent this bug further.
tienifr commentedon Jan 6, 2024
Hi @twisterdotcom, according to the discussion here on this issue, I and @barros001 will be sharing compensation, and @barros001 also agreed with it by reacting here
Could you send me an Upwork job, thanks!
tienifr commentedon Jan 11, 2024
@twisterdotcom friendly bump on this, thanks!
twisterdotcom commentedon Jan 11, 2024
Refund of $250 from @barros001 here.
Payment of $250 for @tienifr here.
barros001 commentedon Jan 11, 2024
@twisterdotcom I was under the impression that @tienifr would get a separate payment instead of splitting the payment?
https://expensify.slack.com/archives/C01GTK53T8Q/p1700754871079609?thread_ts=1700483443.288289&cid=C01GTK53T8Q
Let @Carlos Barros implement this. Also give @Tienifr bonus for raising this discussion because without them, we could have implemented locale based solutiontienifr commentedon Jan 12, 2024
@twisterdotcom I accepted, thanks!
twisterdotcom commentedon Jan 12, 2024
Apologies @barros001 I am going off the comment you 👍 in Slack here about agreeing to split: https://expensify.slack.com/archives/C01GTK53T8Q/p1700757642008119?thread_ts=1700483443.288289&cid=C01GTK53T8Q

If it's a better middle ground, we can also not process the $250 refund and just pay out $250 for @tienifr.
barros001 commentedon Jan 12, 2024
@twisterdotcom yeah, the conversation was a little vague and not super clear. Ultimately we should do what’s right based on defined internal process (if any) for these cases. If it means I get to keep the full payment, great. If it means I should process the refund, that’s totally fine as well. Just let me know how to proceed and I’ll act accordingly.
0xmiroslav commentedon Jan 12, 2024
@barros001 made good efforts for making complete PR so it seems not fair to me to split equal compensation between them. So I suggest to cancel refund (just my opinion. Final decision will be from internal team ofc)
twisterdotcom commentedon Jan 15, 2024
Okay, I'm happy for you to reject the refund request @barros001. Sorry for the confusion.