Skip to content

🐛 Bug: Incorrect Times/Timezones when fetching events from the Community calendar #1036

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

Closed
benjagm opened this issue Oct 18, 2024 · 4 comments
Assignees
Labels
🐛 Bug Indicates that the issue is a bug or defect. Hacktoberfest Issues accepeted Hacktoberfest'24 Status: In Progress This issue is being worked on, and has someone assigned.

Comments

@benjagm
Copy link
Collaborator

benjagm commented Oct 18, 2024

Describe the bug

We are fetching events from the JSON Schema's Google Calendar using the ical file and events are in different timezones. To present it on the Landing page and the Community page we are converting all to UTC timezone but it seems that the conversion is not working as expected. Specifically the APAC/Americas bi-monthly office hours. We need to review the logic of Timezone conversion to make sure it works.

Steps To Reproduce

Access the landing page or the community page and check the events list. The time/timezone should be consistent with the event present in the calendar:
https://calendar.google.com/calendar/embed?src=json.schema.community%40gmail.com&ctz=Europe%2FLondon

Expected Behavior

Correct times are presented converting to UTC

Screenshots

No response

Device Information [optional]

- OS:
- Browser:
- version:

Are you working on this issue?

No

Do you think this work might require an [Architectural Decision Record (ADR)]? (significant or noteworthy)

No

@benjagm benjagm added 🐛 Bug Indicates that the issue is a bug or defect. Status: Triage This is the initial status for an issue that requires triage. labels Oct 18, 2024
@benjagm benjagm added Status: Available No one has claimed responsibility for resolving this issue. and removed Status: Triage This is the initial status for an issue that requires triage. labels Oct 18, 2024
@benjagm benjagm moved this to Waiting for Contributions in Website Contributor Board Oct 18, 2024
@github-actions github-actions bot added the Status: Triage This is the initial status for an issue that requires triage. label Oct 18, 2024
@DhairyaMajmudar DhairyaMajmudar added Status: Accepted It's clear what the subject of the issue is about, and what the resolution should be. Hacktoberfest Issues accepeted Hacktoberfest'24 and removed Status: Triage This is the initial status for an issue that requires triage. labels Oct 18, 2024
@rishabhknowss
Copy link
Contributor

Let me try fixing this

@techmannih
Copy link
Contributor

techmannih commented Oct 23, 2024

@benjagm May I work on this issue ,,,
able to fetch all timing according to timezone and fixed all APAC/Americas bi-monthly office hours.
Screenshot 2024-10-23 121612
image

@benjagm
Copy link
Collaborator Author

benjagm commented Oct 23, 2024

Thanks, @techmannih. please go ahead. The only comments is we need the meetings to be shown in the website converted to UTC for all visitors.

@benjagm benjagm added Status: In Progress This issue is being worked on, and has someone assigned. and removed Status: Available No one has claimed responsibility for resolving this issue. Status: Accepted It's clear what the subject of the issue is about, and what the resolution should be. labels Oct 23, 2024
@benjagm benjagm moved this from Waiting for Contributions to In Progress in Website Contributor Board Oct 23, 2024
@techmannih
Copy link
Contributor

techmannih commented Oct 23, 2024

@benjagm please check this, this is not depend on localtime,

function printEventsForNextWeeks(icalData: { [x: string]: any }) {
  const arrayDates = [];
  if (!icalData) {
    console.error('iCal data is empty or invalid.');
    return;
  }

  // Calculate the range of dates for the next 12 weeks from today
  const today = moment.utc().startOf('day'); // Use UTC for today
  const nextFourWeeksEnd = moment.utc().add(12, 'weeks').endOf('day'); // Use UTC for the end date

  // Loop through the events in the iCal data
  for (const k in icalData) {
    const event = icalData[k];

    if (event.type === 'VEVENT') {
      const title = event.summary;

      // Parse the start date in UTC
      const startDate = moment.utc(event.start);
      console.log('startDate', startDate);

      // Complicated case - if an RRULE exists, handle multiple recurrences of the event
      if (event.rrule) {
        const dates = event.rrule.between(today.toDate(), nextFourWeeksEnd.toDate(), true);

        // Loop through the set of date entries
        for (const date of dates) {
          const startDate = moment.utc(date); // Use UTC directly

          // Check if the event falls within the next 12 weeks
          if (startDate.isBetween(today, nextFourWeeksEnd, undefined, '[]')) {
            const utcDate = startDate.utc(); // Already in UTC

            const time = utcDate.format('MMMM Do YYYY, h:mm a');
            const day = utcDate.format('D');
            const parsedStartDate = utcDate.format('YYYY-MM-DD HH:mm:ss');
            arrayDates.push({
              title,
              time,
              day,
              timezone: 'UTC',
              parsedStartDate,
            });
          }
        }
      } else {
        // Simple case - no recurrences
        if (startDate.isBetween(today, nextFourWeeksEnd, undefined, '[]')) {
          const utcDate = startDate; // Already in UTC

          const time = utcDate.format('MMMM Do YYYY, h:mm a');
          const day = utcDate.format('D');
          const parsedStartDate = utcDate.format('YYYY-MM-DD HH:mm:ss');
          arrayDates.push({
            title,
            time,
            day,
            timezone: 'UTC',
            parsedStartDate,
          });
        }
      }
    }
  }

  // Sort the array based on parsedStartDate
  arrayDates.sort((x, y) => new Date(x.parsedStartDate).getTime() - new Date(y.parsedStartDate).getTime());

  return arrayDates;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Indicates that the issue is a bug or defect. Hacktoberfest Issues accepeted Hacktoberfest'24 Status: In Progress This issue is being worked on, and has someone assigned.
Projects
Status: In Progress
Development

No branches or pull requests

4 participants