Skip to content

[Awaiting checklist completion] [$500] Request money - Calendar is showing the wrong date #31416

Closed

Description

@lanitochka17

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


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:

  1. Go to staging.new.expensify.com
  2. Go to + > Request money > Manual
  3. Enter an amount and click Next
  4. Select a participant and proceed to the next page
  5. Click Show more
  6. 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?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

cal

Bug6278477_1700100895903.bandicam_2023-11-16_09-41-03-104.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0135c08e4c75c14697
  • Upwork Job ID: 1724983985857425408
  • Last Price Increase: 2023-11-16
  • Automatic offers:
    • 0xmiroslav | Reviewer | 27749707
    • barros001 | Contributor | 27749708

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 16, 2023
  2. changed the title [-]Request money - Calendar is showing the wrong date[/-] [+][$500] Request money - Calendar is showing the wrong date[/+] on Nov 16, 2023
  3. melvin-bot commented on Nov 16, 2023

    @melvin-bot

    Triggered auto assignment to @twisterdotcom (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

  4. melvin-bot commented on Nov 16, 2023

    @melvin-bot
  5. melvin-bot commented on Nov 16, 2023

    @melvin-bot

    Bug0 Triage Checklist (Main S/O)

    • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
    • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
      • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
    • This bug is reproducible using the reproduction steps in the OP. S/O
      • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
      • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
    • This issue is filled out as thoroughly and clearly as possible
      • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
    • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync
  6. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Nov 16, 2023
  7. melvin-bot commented on Nov 16, 2023

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @0xmiroslav (External)

  8. barros001 commented on Nov 16, 2023

    @barros001
    Contributor

    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

    const startOfCurrentWeek = startOfWeek(new Date(), {weekStartsOn: 1}); // Assuming Monday is the start of the week
    const endOfCurrentWeek = endOfWeek(new Date(), {weekStartsOn: 1}); // Assuming Monday is the start of the week

    Code assumes week starts on Monday when rendering the weekdays header (I starts at 0)

    // Add null values for days before the first day of the month
    for (let i = 0; i < getDay(firstDayOfMonth); i++) {
    currentWeek.push(null);
    }

    // Start a new row when the current week is full
    if (getDay(currentDate) === 6) {
    matrix.push(currentWeek);
    currentWeek = [];
    }
    }

    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?

        const startOfCurrentWeek = startOfWeek(new Date(), {weekStartsOn: 0}); // Assuming Sunday is the start of the week
        const endOfCurrentWeek = endOfWeek(new Date(), {weekStartsOn: 0}); // Assuming Sunday is the start of the week

    Update the start of the week to Sunday.

    Before:
    Screenshot 2023-11-15 at 10 11 29 PM

    After:
    Screenshot 2023-11-15 at 10 10 46 PM

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

        // Add null values for days before the first day of the month
        for (let i = 1; i < getDay(firstDayOfMonth); i++) { // changed starting value for I to 1
            currentWeek.push(null);
        }
    
            // Start a new row when the current week is full
            if (getDay(currentDate) === 0) { // changed to 0
                matrix.push(currentWeek);
                currentWeek = [];
            }

    After:
    Screenshot 2023-11-16 at 6 37 41 AM

    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):

        let weekStartsOn = 0; // Assuming Sunday is the default start of the week
        if (Intl && Intl.Locale) {
            const weekInfo = new Intl.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.

  9. tienifr commented on Nov 16, 2023

    @tienifr
    Contributor

    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 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

    const getDayWithWeekStartOnMonday = (date) => (getDay(date) + 6) % 7;
    

    And use it in instead of getDay.

    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

    const getDayWithWeekStartsOn = (date, weekStartsOn) => (getDay(date) - weekStartsOn + 7) % 7;
    

    That might be more consistent with our implementation here, we can put 1 to a WEEK_STARTS_ON constant 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

  10. apptechies commented on Nov 16, 2023

    @apptechies

    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

  11. melvin-bot commented on Nov 16, 2023

    @melvin-bot

    📣 @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:

    1. Make sure you've read and understood the contributing guidelines.
    2. 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.
    3. 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.
    4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
      Screen Shot 2022-11-16 at 4 42 54 PM
      Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
    
  12. 47 remaining items

  13. 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
  14. 0xmiroslav commented on Jan 5, 2024

    @0xmiroslav
    Contributor
    • The PR that introduced the bug has been identified. Link to the PR: DateUtils refactor, remove moment from the code, timezone fixes. #24446
    • The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: https://github.com/Expensify/App/pull/24446/files#r1443022863
    • 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.

  15. tienifr commented on Jan 6, 2024

    @tienifr
    Contributor

    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!

  16. tienifr commented on Jan 11, 2024

    @tienifr
    Contributor

    @twisterdotcom friendly bump on this, thanks!

  17. twisterdotcom commented on Jan 11, 2024

    @twisterdotcom
    Contributor

    Refund of $250 from @barros001 here.

    Payment of $250 for @tienifr here.

  18. barros001 commented on Jan 11, 2024

    @barros001
    Contributor

    @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 solution

  19. tienifr commented on Jan 12, 2024

    @tienifr
    Contributor

    Payment of $250 for @tienifr here.

    @twisterdotcom I accepted, thanks!

  20. twisterdotcom commented on Jan 12, 2024

    @twisterdotcom
    Contributor

    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
    image

    If it's a better middle ground, we can also not process the $250 refund and just pay out $250 for @tienifr.

  21. barros001 commented on Jan 12, 2024

    @barros001
    Contributor

    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 image

    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.

  22. 0xmiroslav commented on Jan 12, 2024

    @0xmiroslav
    Contributor

    @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)

  23. twisterdotcom commented on Jan 15, 2024

    @twisterdotcom
    Contributor

    Okay, I'm happy for you to reject the refund request @barros001. Sorry for the confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions