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: uninitialized time object produce unexpected conversion for trying to convert timezone with "func (t Time) In(loc *Location) Time" #8550

Closed
gopherbot opened this issue Aug 19, 2014 · 7 comments

Comments

Projects
None yet
6 participants
@gopherbot
Copy link

commented Aug 19, 2014

by nash.tsai:

What does 'go version' print?
go version go1.3.1 darwin/amd64

What happened?

package main

import (
    "time"
)

func main() {
    var t time.Time
    println ("t:", t.String(), "t in Local:", t.In(time.Local).String())
}

output:
t: 0001-01-01 00:00:00 +0000 UTC t in Local: 0001-01-01 08:26:44 +0826 LMT

What should have happened instead?

My timezone is +8 so I would expect:  "0001-01-01 08:00:00 +0800"
@robpike

This comment has been minimized.

Copy link
Contributor

commented Aug 21, 2014

Comment 1:

Something is funny in your example: it's using local mean time, not a proper time zone.
I tried this in California and got
    t: 0001-01-01 00:00:00 +0000 UTC t in Local: 0000-12-31 16:00:00 -0800 PST
which is what I would expect.
Your result makes sense if you have no time zone data beyond LMT and you are in the
middle of a time zone, as LMT is local mean time. I suspect the time zone data on the
machine isn't right.
@gopherbot

This comment has been minimized.

Copy link
Author

commented Sep 4, 2014

Comment 2 by nash.tsai:

The OS is OS X 10.9.4, and the timezone settings it set to auto timezone as per
screenshot attachment.

Attachments:

  1. Screen Shot 2014-08-26 at 4.01.47 PM.png (102184 bytes)
@gopherbot

This comment has been minimized.

Copy link
Author

commented Sep 4, 2014

Comment 3 by nash.tsai:

I've tried to my timezone to Taipei, and it worked as expected:
t: 0001-01-01 00:00:00 +0000 UTC t in Local: 0001-01-01 08:00:00 +0800 CST
And anywhere in China will cause this problem.
@gopherbot

This comment has been minimized.

Copy link
Author

commented Sep 4, 2014

Comment 4 by nash.tsai:

I've tried to set my timezone to Taipei, and it worked as expected:
t: 0001-01-01 00:00:00 +0000 UTC t in Local: 0001-01-01 08:00:00 +0800 CST
And anywhere in China will cause this problem.
@griesemer

This comment has been minimized.

Copy link
Contributor

commented Oct 1, 2014

Comment 5:

Labels changed: added repo-main.

@gopherbot gopherbot added new labels Oct 1, 2014

@bradfitz bradfitz removed the new label Dec 18, 2014

@donlzx

This comment has been minimized.

Copy link

commented Feb 5, 2015

Doesn't matter if the time is initialized or not.

What does 'go version' print?

go version go1.4.1 linux/amd64

What happened?

package main

import (
    "fmt"
    "time"
)

func main() {
    t, _ := time.Parse("20060102", "19000101")
    fmt.Println("t:", t.String(), "t in Local:", t.In(time.Local).String())
}

t: 1900-01-01 00:00:00 +0000 UTC t in Local: 1900-01-01 07:36:42 +0736 LMT

On Linux Mint 17 Qiana, local time zone is Hong Kong (HKT)

@minux

This comment has been minimized.

Copy link
Member

commented Feb 5, 2015

Note the reference time in time.Parse is wrong (should be "20060102"),
although it doesn't matter for this example.

@donlzx, your example is working as intended. It's because Hong Kong
was indeed using LMT with GMT offset of 7:36:42 until 1904 Oct 30, at
least according to the latest tzdata for Asia/Hong_Kong.

I think this issue is mostly due to the fact that some people are not aware
that the correct time zone actually depends on the date and it's not
necessarily the same as the current timezone in use.

I'm going to close this issue as working as intended.

@minux minux closed this Feb 5, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 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.