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: add SetLocal #10701

Closed
georgmu opened this issue May 5, 2015 · 5 comments

Comments

Projects
None yet
6 participants
@georgmu
Copy link

commented May 5, 2015

I want to provide an API server which is capable of setting the system time zone.

After changing the system time zone, the running go process still uses the old timezone and it is not possible to refresh except restarting the process.

In java there is a java.util.TimeZone.setDefault() to switch the timezone of the VM. It would be nice to either provide something similar or to add a method to refresh the localLoc variable.

@ianlancetaylor ianlancetaylor changed the title No way to update time zone of a running process time: No way to update time zone of a running process May 5, 2015

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone May 5, 2015

@nightlyone

This comment has been minimized.

Copy link
Contributor

commented May 5, 2015

I wish there wasn't.

Timezones are basically an UI/display issue. If you know what is the "local" time zone, just convert your times to it instead of setting a global default.

@georgmu

This comment has been minimized.

Copy link
Author

commented May 6, 2015

Well, there are certain services running on the machine that want to use the timezone to format their data. Thus, a central time zone setting for the host makes sense.
This is not about UI at first, but a sane default timezone representing the local time for a local use makes sense. UI is capable of converting this to an other timezone, if required

@Thomasdezeeuw

This comment has been minimized.

Copy link
Contributor

commented May 6, 2015

I think you use UTC time at all times to communicatie between systems. This way you don't need to deal with these sort of issues.

@georgmu

This comment has been minimized.

Copy link
Author

commented May 6, 2015

Well, I currently have this kind of an issue, and without a restart of the program, I am not able to solve it.

There are good reasons to have a system-wide time zone on a server. This might not be useful for services and system-to-system communication, but for the local system it is.

Even the default log.Println() uses the local timezone to format the date, but it does not react on time zone changes, nor is it possible to force a re-read of the local time zone. (and the default log.Println() does not print any timezone offset to "know" what time zone it is using currently)

@rsc

This comment has been minimized.

Copy link
Contributor

commented Oct 16, 2015

I've updated the title. What you're asking for is

package time

// SetLocal changes the current meaning of time.Local to match loc.
func SetLocal(loc *Location)

I don't believe this is a good idea. In general but especially in Go, coordination via global mutable state is almost always a mistake and difficult to correct once you realize it.

If there are higher-level APIs that force the use of time.Local, we should probably address those instead. For example, if package log is what you are concerned about, it would probably be okay to file a separate issue for adding log.SetLocation and log.(*Logger).SetLocation.

@rsc rsc changed the title time: No way to update time zone of a running process time: add SetLocal Oct 16, 2015

@rsc rsc closed this Oct 16, 2015

@golang golang locked and limited conversation to collaborators Oct 17, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.