Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-24 Thread Mike Cohen
Thanks Robert, this is what I ended up doing. I wouldnt say it was trivial though :-) https://github.com/Velocidex/json Thanks and sorry for hijacking this thread. Maybe a suggestion - if users are not expected to change time.Local maybe it should be made private or at least wording in the module

Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-24 Thread Steven Hartland
Always serialise t.UTC()? On 24/07/2020 04:26, Mike Cohen wrote: To be clear, the time.MarshalJSON() function produces valid RFC 3339 timestamps which allow arbitrary timezones. This means that local time offset is used in the string representation. Although all representations are

Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-24 Thread Robert Engels
Yea, it is strange the the Json encoder api doesn’t allow the caller to provide a mashaller for any type. It would be trivial to change the code to do so. That being said I’m sure you can find custom json libs on the web that will do this. Or fork it yourself - it is not a lot of code. > On

Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-24 Thread Mike Cohen
To be clear, the time.MarshalJSON() function produces valid RFC 3339 timestamps which allow arbitrary timezones. This means that local time offset is used in the string representation. Although all representations are technically equivalent their string form is not so we need to do special parsing

Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-23 Thread Ian Lance Taylor
On Thu, Jul 23, 2020 at 5:13 PM Michael Cohen wrote: > > Thanks Ian, this does not work as I mentioned because there is no way to > guarantee that my init function will run before any of my libraries creating > a time object (which many do as they start various background tasks). > > Doing what

Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-23 Thread Jason E. Aten
> 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). Yes, you are missing something. This is very easy. Do not change Local. Just use the In() method on

Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-23 Thread Michael Cohen
Thanks Ian, this does not work as I mentioned because there is no way to guarantee that my init function will run before any of my libraries creating a time object (which many do as they start various background tasks). Doing what you say is fragile because even if it appears to work, one day I

Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-23 Thread Ian Lance Taylor
On Thu, Jul 23, 2020 at 9:47 AM 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

Re: [go-nuts] When set time.Location, will be detected Data Race

2020-07-23 Thread scudette
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 initialize76 // it

Re: [go-nuts] When set time.Location, will be detected Data Race

2018-12-05 Thread Matt Harden
Just wrapping a write with a mutex is not enough; you have to wrap all the reads as well. In this case that's not possible because there are reads of time.Local all over the place. Anyway, as has been said, time.Local should never be written to in user code. On Fri, Nov 30, 2018 at 7:46 AM Agniva

Re: [go-nuts] When set time.Location, will be detected Data Race

2018-11-30 Thread Agniva De Sarker
Can you show us the code ? It would help Are you trying to set a variable of type time.Location ? Or are you trying to set time.Local to something else ? Like Ian said, if you want to change the location of a specific time value, use the In method. > But there are lots of place that

Re: [go-nuts] When set time.Location, will be detected Data Race

2018-11-30 Thread Marvin Renich
* Ian Lance Taylor [181130 01:01]: > On Thu, Nov 29, 2018 at 9:47 PM wrote: > > The feature of golang is goroutine, and it is a normal situation that get > > time in different goroutine. > > But only can set time.Location in one goroutine. So the Data Race is > > inevitable. > > > > And there

Re: [go-nuts] When set time.Location, will be detected Data Race

2018-11-29 Thread Ian Lance Taylor
On Thu, Nov 29, 2018 at 9:47 PM wrote: > > My go version is 1.11. > > When I set time.Location, then … > > == > WARNING: DATA RACE > Write at 0x02e275d0 by main goroutine: > vcs.taiyouxi.net/platform/planx/timeutil.SetTimeLocal() > >

[go-nuts] When set time.Location, will be detected Data Race

2018-11-29 Thread zhangzhentaihe
My go version is 1.11. When I set time.Location, then … == WARNING: DATA RACE Write at 0x02e275d0 by main goroutine: vcs.taiyouxi.net/platform/planx/timeutil.SetTimeLocal()