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

time: EEST timezone not recognized on windows #62065

Closed
mohammedrefaat opened this issue Aug 16, 2023 · 6 comments
Closed

time: EEST timezone not recognized on windows #62065

mohammedrefaat opened this issue Aug 16, 2023 · 6 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows

Comments

@mohammedrefaat
Copy link

mohammedrefaat commented Aug 16, 2023

What version of Go are you using (go version)?

$ go version
1.21.0

Does this issue reproduce with the latest release?

yes

What did you do?

i use this code in my software work in windows

zone, _:= time.Now().Zone()
location_currentzone, err := time.LoadLocation(zone)
if err != nil {

	return time.Now(), err
}

final := te.In(location_currentzone)

but when i upgrade go from 1.20.6 to 1.21.0
time.LoadLocation recognize only to utc and local only and didn't recognize any zone output from time.Now().Zone()
this happened in debug or build in machine have 1.21.0 golang

error:
unknown time zone EEST

@AhmedEmad92
Copy link

AhmedEmad92 commented Aug 16, 2023

Same here , but it gives me error : the device is not ready
time problem
and when i downgraded to 1.20.6 , it works fine !!!

@seankhliao seankhliao changed the title time: time: timezones nor recognized on windows Aug 16, 2023
@seankhliao
Copy link
Member

cc @golang/windows

@qmuntal qmuntal added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 16, 2023
@qmuntal qmuntal changed the title time: timezones nor recognized on windows time: EEST timezone not recognized on windows Aug 16, 2023
@qmuntal
Copy link
Contributor

qmuntal commented Aug 16, 2023

I can reproduce the error using previous go releases, not only go1.21:

package main

import (
	"fmt"
	"os"
	"time"
)

func main() {
	loc, err := time.LoadLocation("EEST")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println(loc)
}
go1.20.2 run . 
unknown time zone EEST
exit status 1

I don't know why it was working before for you @mohammedrefaat.

The EEST is coming from here, were we are mapping a Windows time zone, e.g. GTB Standard Time, into an identifier that Go can handle. The problem is that the time/tzdata database doesn't has an entry for EEST. Maybe @ianlancetaylor or @bcmills will know why.

@ianlancetaylor
Copy link
Contributor

Go just uses the tzdata timezone database (https://github.com/eggert/tz). That database doesn't define an EEST timezone. It does have EET, and it uses EEST as the summer time variant of EET, but it doesn't recognize EEST as a standalone timezone.

That said, I don't think this has much if anything to do with the WIndows abbreviation code. This code, which looks like it might correspond to the code in the original report, fails on Linux in my timezone:

package main

import (
	"fmt"
	"os"
	"time"
)

func main() {
	zone, _ := time.Now().Zone()
	fmt.Println(zone)
	loc, err := time.LoadLocation(zone)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println(loc)
}

I get

PDT
unknown time zone PDT

This shows that the timezone abbreviations returned by time.Time.Zone aren't themselves recognized as timezone names.

Closing this issue as a dup of #5909.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2023
@mohammedrefaat
Copy link
Author

mohammedrefaat commented Aug 17, 2023

I think you need to try it on Windows, I use this code in Windows 11 22H2 os build 22621.2213 :

package main

import (
	"fmt"
	"os"
	"time"
	_ "time/tzdata"
)

func main() {
	te := time.Now()
	zone, _ := time.Now().Zone()
	fmt.Println(zone)
	location_currentzone, err := time.LoadLocation(zone)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	final := te.In(location_currentzone)
	fmt.Println(final)
}

in go 1.20.7
I get

EET
2023-08-17 09:59:00.4998128 +0300 EEST

in go 1.21.0
i get

EEST
unknown time zone EEST
exit status 1

i think zone in
zone, _ := time. Now().Zone()

must return time zone EET not summer time variant of EET in go 1.21.0

@ianlancetaylor
Copy link
Contributor

When I run your program on my system, which is in the timezone America/Los_Angeles, I get

PDT
unknown time zone PDT

That happens with both tip and Go 1.20.

My point is that in general it doesn't work to pass the string returned by time.Time.Zone to time.LoadLocation. It does work for a few specific cases. EET is one of the cases where it happens to work. I don't know why the tzdata database works that way.

I do see that there is a difference between Go 1.20 and Go 1.21 that affects your case, but it appears to be a change in the Windows timezone information. Every so often we update to the current version of https://raw.githubusercontent.com/unicode-org/cldr/main/common/supplemental/windowsZones.xml. When we did that for the 1.21 release, it changed "Egypt Standard Time" to return EEST for summer time. In Go 1.20 it returned EET. That was a change in the Windows timezone file, not in anything that Go controls.

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants