[go-nuts] Re: Safe to treat time.Local != time.LoadLocation("your current timezone")?
Tamas, that's checking if the offset at a particular instant was the same as the local zone - what OP cares about is that the caller is not using literally "time.Local" in their code. I recommend performing source analysis for this - it's a lot easier on you than runtime checks. -- 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: Safe to treat time.Local != time.LoadLocation("your current timezone")?
2018. október 19., péntek 8:26:22 UTC+2 időpontban Tamás Gulácsi a következőt írta: > > Just check whether a specific time is the same with the specified location > and with the Local location: > > if time.Date(2006,time.Month(1), 1, 0,0,0,0, > time.Local).Equal(time.Date(2006,time.Month(1),1,0,0,0,0, > offset.Location()) { return error } > > 2018. október 19., péntek 8:08:05 UTC+2 időpontban Matt Mueller a > következőt írta: >> >> Hey folks, >> >> I'm trying to ensure that the user must pass a specific location >> (anything but time.Local) into a function. >> >> I'd like to add a check like this: >> >> // ensure we didn't pass in an offset the default time.Local >> if offset.Location() == time.Local { >> return nil, errors.New("offset use a specific timezone") >> } >> >> >> But I'm just not sure if the user happens to specify the timezone that >> matches time.Local that this may evaluate as true. From preliminary tests, >> it seems like it should be fine, but I'd like to double-check. >> >> Thanks! >> >> Matt >> > Or // once, maybe in init() t := time.Now() _, localOff := t.Zone() // the check if _, givenOff := t.In(offset.Location()).Zone(); givenOf == localOff { return nil, errors.New("offset use a specific timezone") } -- 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: Safe to treat time.Local != time.LoadLocation("your current timezone")?
Just check whether a specific time is the same with the specified location and with the Local location: if time.Date(2006,time.Month(1), 1, 0,0,0,0, time.Local).Equal(time.Date(2006,time.Month(1),1,0,0,0,0, offset.Location()) { return error } 2018. október 19., péntek 8:08:05 UTC+2 időpontban Matt Mueller a következőt írta: > > Hey folks, > > I'm trying to ensure that the user must pass a specific location (anything > but time.Local) into a function. > > I'd like to add a check like this: > > // ensure we didn't pass in an offset the default time.Local > if offset.Location() == time.Local { > return nil, errors.New("offset use a specific timezone") > } > > > But I'm just not sure if the user happens to specify the timezone that > matches time.Local that this may evaluate as true. From preliminary tests, > it seems like it should be fine, but I'd like to double-check. > > Thanks! > > Matt > -- 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. For more options, visit https://groups.google.com/d/optout.