Skip to content
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

DateHelper startOf week method does not return correct output for Sunday #8875

Closed
ghulamghousdev opened this issue Mar 25, 2024 · 1 comment
Assignees
Labels
bug Something isn't working forum Issues from forum large-account Reported by large customer premium resolved Fixed but not yet released (available in the nightly builds)
Milestone

Comments

@ghulamghousdev
Copy link
Member

Forum post

Hello team, please see an example:
Core.helper.DateHelper#function-startOf-static
Just run in console of the docs

oneWeek = [
    { day: 'Monday', date: new Date(2024, 2, 18) },
    { day: 'Tuesday', date: new Date(2024, 2, 19) },
    { day: 'Wednesday', date: new Date(2024, 2, 20) },
    { day: 'Thursday', date: new Date(2024, 2, 21) },
    { day: 'Friday', date: new Date(2024, 2, 22) },
    { day: 'Saturday', date: new Date(2024, 2, 23) },
    { day: 'Sunday', date: new Date(2024, 2, 24) }
]

firstDay = 1

oneWeek.map(item => {
    return DateHelper.startOf(item.date, 'week', true, firstDay)
})

I expect start of week for all days above is Monday, the March 18th. But for Sunday it returns the March 25th which is Monday next week.
Screen Shot 2024-03-24 at 17.49.18.png

@ghulamghousdev ghulamghousdev added bug Something isn't working premium forum Issues from forum large-account Reported by large customer labels Mar 25, 2024
@kronaemmanuel
Copy link

kronaemmanuel commented Mar 25, 2024

Untested solution....problem is in DateHelper.startOf in switch statement when it calculates delta, it should be:

            case 'week': {
                const delta = (date.getDay() < weekStartDay) ? date.getDay() - weekStartDay + 7 : date.getDay() - weekStartDay;
                date.setDate(date.getDate() - delta);
                date.setHours(0, 0, 0, 0);
                return date;
            }

Seems to solve:
image

Idk about other cases tho. Will have to check.

@kronaemmanuel kronaemmanuel self-assigned this Mar 25, 2024
@isglass isglass added resolved Fixed but not yet released (available in the nightly builds) and removed in progress labels Mar 26, 2024
@isglass isglass added this to the 5.6.9 milestone Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working forum Issues from forum large-account Reported by large customer premium resolved Fixed but not yet released (available in the nightly builds)
Projects
None yet
Development

No branches or pull requests

3 participants