Git Product home page Git Product logo

Comments (4)

martin-sweeny avatar martin-sweeny commented on May 25, 2024 1

This is because @dmfilipenko didn't take daylight savings into account, it seems. It looks like this is a snapshot of time zones at some arbitrary point in time.

from timezones.json.

lzilioli avatar lzilioli commented on May 25, 2024 1

Oh man, my job has this file committed to the codebase, I'm so glad I found this github project because I was chasing my tail trying to figure out the issue I was seeing in my app's UI.

Finally, I discovered that EST has this same issue, which ultimately led me here.

If you must continue using this file in your project (we are for now), I think it is cleaner to parse the offset out of the text property rather than rely on the numerical offset property provided in the JSON data.

I am using this code snippet to map the timezones in this JSON by their UTC offset according to their text property.

Note that these UTC offsets are mapped by minutes, not hours.

import {groupBy} from 'lodash';
const UTCOffsetRegex: RegExp = /\(UTC(.*?)\)/;
const timezoneJson = [ ... ];

interface Timezone {
  value: string;
  abbr: string;
  offset: number;
  isdst: boolean;
  text: string;
  utc?: string[];
}

static get tzByOffsetMins(): {[key: number]: Timezone[]} {
	const tzOffsetMap: {[key: number]: Timezone[]} = groupBy(timezoneJson, (timezone: Timezone): number => {
		const offset: string = UTCOffsetRegex.exec(timezone.text)[1];
		const [hours, mins]: string[] = offset.split(':');
		const hoursAsMins: number = Math.abs(Number(hours) * 60);
		const offsetMultiplier: number = hours.startsWith('-') ? -1 : 1;
		const totalMins: number = hoursAsMins + Number(mins);
		const offsetInt: number = totalMins * offsetMultiplier;
		return offsetInt;
	});
	return tzOffsetMap;
}

from timezones.json.

HelloooJoe avatar HelloooJoe commented on May 25, 2024

Yep! I thought I was going crazy.... spent 3 days figuring out why I was always off by one hour when I had a use case between calculating delta between Pacific Standard Time and Central Standard Time... He has the offset for CST set to -5 but it's supposed to be -6 and PST is correct at -8...

from timezones.json.

adrielTosi avatar adrielTosi commented on May 25, 2024

I've notices several of these differences, where the text and offset values differ. For example these two:

  {
    value: 'Central Standard Time',
    abbr: 'CDT',
    offset: -5,
    isdst: true,
    text: '(UTC-06:00) Central Time (US & Canada)',
    utc: [ ... ],
  },
 {
    value: 'Eastern Standard Time',
    abbr: 'EDT',
    offset: -4,
    isdst: true,
    text: '(UTC-05:00) Eastern Time (US & Canada)',
    utc: [ ... ],
  },

Anyone got any insight into this?

Edit: I made some cross checking and created this gist if anyone is interested (https://gist.github.com/adrielTosi/7a08cc60dc3f00e68733bb9b65b7adeb). I don't claim it's 100% correct, but the values to offset and text are the same.

from timezones.json.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.