vvo / tzdb

🕰 Simplified, grouped and always up to date list of time zones, with major cities

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get the user's timezone?

durancristhian opened this issue · comments

Hi!, I really like this project :) Thank you for the work you put on it.

I'm using luxon to handle dates on a project and tzdb to build a timezone select but I'm not able to get the user's timezone on the list. I'll share an example:

// Native JS API
// logs "America/Buenos_Aires"
console.log(Intl.DateTimeFormat().resolvedOptions().timeZone)

// Same but with Luxon
// Logs "America/Buenos_Aires" too
import { DateTime } from 'luxon'

console.log(DateTime.local().zoneName)

and the list I get from tzdb has name and groups which are composed of Continent/Country/City and I wouldn't like to make a guess algorithm to pick up the right time zone. Is there any way to accomplish this?

Update. This occurs only with Argentina 😆 I'd like to understand why is this happening tho...

Sooo, I made a temporary solution that looks like:

const userTz = DateTime.local().zoneName
const { 0: continent, length, [length - 1]: city } = userTz.split('/')

const timeZoneToUseInTheSelect: `${continent}/${city}`

@durancristhian (I missed this message).

There's indeed a difference between what JavaScript API is sending and the data we're using (http://download.geonames.org/export/dump/timeZones.txt).

One thing we could do is have some sort of manual mapping for some of the timezones in the generate.ns script. Unfortunately, I won't have time to do this change for now. So.. PR accepted :)

I believe it's a chrome bug/v8 bug whatever that is not listing the right name for America/Argentina/Buenos_Aires. The "real" timezone name being America/Argentina/Buenos_Aires as seen here: https://en.wikipedia.org/wiki/Time_in_Argentina#IANA_time_zone_database

Thank you so much for the clarification :)
I've manually spplited the value like described in #93 (comment)

I'll close the issue.