Skip to content

Commit

Permalink
simplify time format logic
Browse files Browse the repository at this point in the history
  • Loading branch information
TyHil committed Dec 12, 2024
1 parent 8235f27 commit 5893a82
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,17 @@ export async function addGCalButtons() {
for (let j = 0; j < courseData.meetings.length; j++) {
const meeting = courseData.meetings[j];
const formatTime = (date, time) => {
const datePart = new Date(date);
const datePart = date.split('T')[0].replaceAll('-', '');
const timePart = String(time).padStart(4, '0');
const hours = parseInt(timePart.slice(0, 2), 10);
const minutes = parseInt(timePart.slice(2), 10);
datePart.setUTCHours(hours, minutes, 0, 0);
return `${datePart.toISOString().replace(/[-:]/g, '').split('.')[0]}`;
return `${datePart}T${timePart}00Z`;
};
const formattedStartDate = formatTime(
meeting.startDate,
meeting.startTime,
);
const formattedEndTime = formatTime(meeting.startDate, meeting.endTime);
const recurrenceEnd =
meeting.endDate.split('T')[0].replaceAll('-', '') + 'T235959';
meeting.endDate.split('T')[0].replaceAll('-', '') + 'T235959Z';
const meetingDays = meeting.days
.replaceAll('Th', 'X')
.split('')
Expand Down

0 comments on commit 5893a82

Please sign in to comment.