Compare commits

...

3 Commits

Author SHA1 Message Date
Kemal Zebari a388167c3d
Merge 4c6b196902 into bb0e4ce581 2024-05-04 00:41:41 -07:00
Kemal Zebari 4c6b196902 Have `firstStartDateAfterDate()` use UTC-related methods 2024-05-03 22:39:42 -07:00
Sam Fisher 44ad644df8 Have time.js use UTC-related getters/setters when working with `Date` 2024-05-03 20:24:00 -07:00
1 changed files with 4 additions and 4 deletions

View File

@ -4,8 +4,8 @@ import {getCurrentLocale} from '../utils.js';
// Returns an array of millisecond-timestamps of start-of-week days (Sundays)
export function startDaysBetween(startDate, endDate) {
// Ensure the start date is a Sunday
while (startDate.getDay() !== 0) {
startDate.setDate(startDate.getDate() + 1);
while (startDate.getUTCDay() !== 0) {
startDate.setUTCDate(startDate.getUTCDate() + 1);
}
const start = dayjs(startDate);
@ -29,10 +29,10 @@ export function firstStartDateAfterDate(inputDate) {
if (!(inputDate instanceof Date)) {
throw new Error('Invalid date');
}
const dayOfWeek = inputDate.getDay();
const dayOfWeek = inputDate.getUTCDay();
const daysUntilSunday = 7 - dayOfWeek;
const resultDate = new Date(inputDate.getTime());
resultDate.setDate(resultDate.getDate() + daysUntilSunday);
resultDate.setUTCDate(resultDate.getUTCDate() + daysUntilSunday);
return resultDate.valueOf();
}