Premium support for our pure JavaScript UI components


Post by pmiklashevich »

Hello team, please see an example:
https://bryntum.com/products/schedulerpro/docs/api/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.

Attachments
Screen Shot 2024-03-24 at 17.49.18.png
Screen Shot 2024-03-24 at 17.49.18.png (268.87 KiB) Viewed 368 times

Pavlo Miklashevych
Sr. Frontend Developer


Post by pmiklashevich »

Here is my override to fix it:

if (unit === 'week') {
      const weekBasedOnSunday = [0, 1, 2, 3, 4, 5, 6]
      // For example week based on Monday is [1, 2, 3, 4, 5, 6, 0]
      const weekBasedOnWeekStartDay = [
        ...weekBasedOnSunday.slice(weekStartDay),
        ...weekBasedOnSunday.slice(0, weekStartDay)
      ]
      const currentDay = date.getDay()
      const delta = weekBasedOnWeekStartDay.indexOf(currentDay)

  date.setDate(date.getDate() - delta)
  date.setHours(0, 0, 0, 0)
  return date
}

Pavlo Miklashevych
Sr. Frontend Developer


Post by ghulam.ghous »

Hi Pavlo,

Thanks for reporting this issue. I have created a ticket here https://github.com/bryntum/support/issues/8875 to fix it.

Regards,
Ghous


Post Reply