fix: timezone conversion dayOffset month-boundary bug and overnight endDayIdx calculation
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -140,15 +140,10 @@ function computeShowPlacement(
|
|||||||
let startMin = convertedStart.hour * 60 + convertedStart.minute;
|
let startMin = convertedStart.hour * 60 + convertedStart.minute;
|
||||||
let endMin = convertedEnd.hour * 60 + convertedEnd.minute;
|
let endMin = convertedEnd.hour * 60 + convertedEnd.minute;
|
||||||
|
|
||||||
const endDayIdx = (sourceDayIdx + convertedEnd.dayOffset + 7) % 7;
|
const endBaseDayIdx = isOvernightSource ? sourceDayIdx + 1 : sourceDayIdx;
|
||||||
if (isOvernightSource || endDayIdx !== displayDayIdx || endMin <= startMin) {
|
const endDayIdx = (endBaseDayIdx + convertedEnd.dayOffset + 7) % 7;
|
||||||
if (endDayIdx === displayDayIdx && endMin <= startMin) {
|
if (endDayIdx !== displayDayIdx || endMin <= startMin) {
|
||||||
endMin += 24 * 60;
|
endMin += 24 * 60;
|
||||||
} else if (endDayIdx !== displayDayIdx) {
|
|
||||||
endMin += 24 * 60;
|
|
||||||
} else if (isOvernightSource) {
|
|
||||||
endMin += 24 * 60;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const startDisplay = formatTime12(convertedStart.hour, convertedStart.minute);
|
const startDisplay = formatTime12(convertedStart.hour, convertedStart.minute);
|
||||||
|
|||||||
@@ -60,11 +60,17 @@ export function convertTime(
|
|||||||
const toHour = parseInt(toParts.find((p) => p.type === "hour")!.value);
|
const toHour = parseInt(toParts.find((p) => p.type === "hour")!.value);
|
||||||
const toMin = parseInt(toParts.find((p) => p.type === "minute")!.value);
|
const toMin = parseInt(toParts.find((p) => p.type === "minute")!.value);
|
||||||
const toDay = parseInt(toParts.find((p) => p.type === "day")!.value);
|
const toDay = parseInt(toParts.find((p) => p.type === "day")!.value);
|
||||||
|
const toMonth = parseInt(toParts.find((p) => p.type === "month")!.value);
|
||||||
|
const toYear = parseInt(toParts.find((p) => p.type === "year")!.value);
|
||||||
|
|
||||||
const fromCorrectedParts = fromFormatter.formatToParts(correctedUtc);
|
const fromCorrectedParts = fromFormatter.formatToParts(correctedUtc);
|
||||||
const fromDay = parseInt(fromCorrectedParts.find((p) => p.type === "day")!.value);
|
const fromDay = parseInt(fromCorrectedParts.find((p) => p.type === "day")!.value);
|
||||||
|
const fromMonth = parseInt(fromCorrectedParts.find((p) => p.type === "month")!.value);
|
||||||
|
const fromYear = parseInt(fromCorrectedParts.find((p) => p.type === "year")!.value);
|
||||||
|
|
||||||
const dayOffset = toDay - fromDay;
|
const fromDate = Date.UTC(fromYear, fromMonth - 1, fromDay);
|
||||||
|
const toDate = Date.UTC(toYear, toMonth - 1, toDay);
|
||||||
|
const dayOffset = Math.round((toDate - fromDate) / (24 * 60 * 60 * 1000));
|
||||||
|
|
||||||
return { hour: toHour === 24 ? 0 : toHour, minute: toMin, dayOffset };
|
return { hour: toHour === 24 ? 0 : toHour, minute: toMin, dayOffset };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user