Skip to content

Handle backend updates with correct timezone #1

@emibcn

Description

@emibcn

Currently, the data auto update mechanism only works if the user has the same timezone than the official at Catalonia: CEST (with timelight.

https://github.com/emibcn/covid/blob/master/app/src/Backend/Maps/index.js#L132

  // Calculates haw many milliseconds until next schedulled update (today's or tomorrow)
  // TODO: Take care of timezones: Official date is in CEST/GMT+0200 (with daylight saving modifications), Date uses user's timezone and returns UTC
  //       Now, it only works if user timezone is CEST
  //       Probably, the best would be to translate both dates into UTC and, only then, compare them
  millisToNextUpdate = () => {
    const now = new Date();
    const todayDataSchedule = new Date(now.getFullYear(), now.getMonth(), now.getDate(), ...this.officialUpdateTime, 0, 0);
    const millisTillSchedulle = todayDataSchedule - now;

    return millisTillSchedulle <= 0
      ? millisTillSchedulle + 86_400_000 // it's on or after today's schedule, try next schedule tomorrow.
      : millisTillSchedulle
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    HacktoberfestSimple issues suitable Hacktoberfest PRsbugSomething isn't workinggood first issueGood for newcomersjavascriptJavascript knowledge needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions