On Thu, Jul 23, 2020 at 9:47 AM <scude...@gmail.com> wrote: > > A bit late to the party here but I would like to explore your rational for > stating that time.Local should not be modified by user code. The code seems > to suggest this is expected: > > https://golang.org/src/time/zoneinfo.go > ``` > > // localLoc is separate so that initLocal can initialize > 76 // it even if a client has changed Local. > > ``` > > I want to change Local because I want all JSON encoding to be normalized to > UTC and not local time - there does not seem to be a way to do this (please > let me know if I am missing something). It is possible to set the TZ env var > but not from within the program itself - it has to be done via a hacky shell > script before I launch the program. This is because it is impossible to > guarantee that my code will run before any library might access any time > functions causing initLocal to fire. After this changing the TZ env var makes > no difference. > > I know I can set the Location in every time.Time object I create but this is > impossible for time.Time objects coming from other libraries. I essentially > need to write my own visitor to try to identify such foreign time.Time > objects and fix their Location before they can be json serialized. > > I tried to update time.Local using atomic.SetPointer so there really is no > race but the race detector still complains - if there a way to turn it off?
There is no way to change time.Local. It is accessed without any protection, because the time package assumes that it will not change. If your program doesn't fetch any timezones at initialization time, you could use func init() { os.Setenv("TZ", "") } Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVk-HSHG%2BsOzWqo9z%3DS6mbHLsEyELh73SK%3Dn8wwuiLqTA%40mail.gmail.com.