Skip to content

time: document Location's effect on Time more? #23316

@pjebs

Description

@pjebs

Using Go 1.9

Documenation states:

func (t Time) In(loc *Location) Time
In returns t with the location information set to loc.

My interpretation is that the function In will change the location information but keep all other details the same. The consequence is that it will have a different Unix time usually since they represent different points in time.

startDate := ....   //startDate (time.Time) 2018-01-01 00:00:00 +1100 AEDT
_startDate := time.Date(startDate.Year(), startDate.Month(), startDate.Day(), startDate.Hour(), startDate.Minute(), startDate.Second(), startDate.Nanosecond(), time.UTC)
fmt.Println("startDate", spew.Sdump(startDate), spew.Sdump(startDate.In(time.UTC)), spew.Sdump(_startDate))

Output:

startDate (time.Time) 2018-01-01 00:00:00 +1100 AEDT
 (time.Time) 2017-12-31 13:00:00 +0000 UTC
 (time.Time) 2018-01-01 00:00:00 +0000 UTC

Expected output:
startDate.In(time.UTC)) and _startDate should produce same result

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions