Amandeep kaur
Amandeep kaur

Reputation: 1025

time.LoadLocation() gives unknown timezone for US/Pacific-New timezone

Go version: 1.14.2

Operating system: Linux (Ubuntu)

I am working on a dynamic timezone based system in which user can set the timezone. I have a user who set the timezone to US/Pecific-New. For this timezone, the golang time package gives following error:

unknown time zone US/Pacific-New

I have researched on this and found that time package loads the timezone from the local system having file paths:

/usr/share/zoneinfo

/usr/local/go/lib/time

On these paths, on my local system as well as on staging Pacific-New is missing on both locations.

Is there a way to get Pacific-New on these locations ?

Upvotes: 2

Views: 5088

Answers (2)

Matt Johnson-Pint
Matt Johnson-Pint

Reputation: 241788

US/Pacific-New was never a "real" time zone and should not be selected on any system.

It was created to reflect a potential change to Pacific time that was never enacted into law. The idea at the time was that there would be a time zone ready in advance of the change. However, since the bill wasn't enacted this turned out to be a failed experiment. The TZDB no longer tries to create zones in speculative anticipation of future changes, but only adds or updates them when they are official or otherwise imminent.

Ultimately, US/Pacific-New was only ever a link to US/Pacific and then later updated as a link to the preferred form of America/Los_Angeles The last TZDB release to include such a link for US/Pacific-New was 2020a.

From the 2020b release notes:

The long-obsolete files pacificnew, systemv, and yearistype.sh have been removed from the distribution. (Thanks to Tim Parenti.)

You can read more about the long storied history with this link entry by searching the NEWS file in the TZDB for "Pacific-New" and "pacificnew", and by reading the 2020a version of the pacificnew file from before it was deleted.

As far as practical advice, don't set US/Pacific-New on any system. It is no longer a valid time zone identifier. The whole system will be affected by this. Switch to America/Los_Angeles instead.

Upvotes: 5

Paul Hankin
Paul Hankin

Reputation: 58339

Rather than time.LoadLocation() you can use time.LoadLocationFromTZData() which loads a location from the contents of a timezone file, which can contain whatever timezones you like.

You will need a correctly formatted timezone file with the timezones you wish to use, perhaps based on whatever you have in /usr/share/zoneinfo.

Upvotes: 1

Related Questions