Skip to content
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

Handle backend updates with correct timezone #1

Open
emibcn opened this issue Sep 27, 2020 · 0 comments
Open

Handle backend updates with correct timezone #1

emibcn opened this issue Sep 27, 2020 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest Simple issues suitable Hacktoberfest PRs javascript Javascript knowledge needed

Comments

@emibcn
Copy link
Owner

emibcn commented Sep 27, 2020

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
  }
@emibcn emibcn added bug Something isn't working good first issue Good for newcomers Hacktoberfest Simple issues suitable Hacktoberfest PRs javascript Javascript knowledge needed labels Sep 27, 2020
emibcn pushed a commit that referenced this issue Oct 9, 2020
emibcn pushed a commit that referenced this issue Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest Simple issues suitable Hacktoberfest PRs javascript Javascript knowledge needed
Projects
None yet
Development

No branches or pull requests

1 participant