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

Posix TZ string #140

Open
hartmamt opened this issue Oct 24, 2023 · 2 comments
Open

Posix TZ string #140

hartmamt opened this issue Oct 24, 2023 · 2 comments

Comments

@hartmamt
Copy link

hartmamt commented Oct 24, 2023

Is there any way to pass in a time zone location and get back the posix tz string? For example:

Africa/El_Aaiun returns <GMT>0?

I've got Go code that will do this but it requires reflection.

// getFieldString uses to get the unexported value of the extends field
func getFieldString(e *time.Location, field string) string {
	r := reflect.ValueOf(e)
	f := reflect.Indirect(r).FieldByName(field)
	return f.String()
}

// ConvertFormat formats the tz string so it is readable by ESP32 devices
func convertFormat(t *time.Location) string {
	r := regexp.MustCompile(`<.*?>`)
	var count int
	return r.ReplaceAllStringFunc(
		getFieldString(t, "extend"),
		func(m string) string {
			count++
			if count == 1 {
				return "<GMT>"
			}
			return "<DST>"
		},
	)
}
@djc
Copy link
Member

djc commented Oct 24, 2023

I don't think we currently support that. I'm not very fluent in Go code, so not sure how it synthesizes this data from what's in the TZDB.

@pitdicker
Copy link
Contributor

This crate compiles the time zone data into a large table of transitions for a fixed set of years. The data doesn't include a TZ string like TZif files have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants