Skip to content

time: UnixNano thinks year 1 comes after 1720 #40702

@vsekhar

Description

@vsekhar

UnixNano gives inconsistent results. Specifically, it believes the year 1 comes after the year 1720.

package main

import (
	"fmt"
	"time"
)

func main() {
	t1 := time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)
	t2 := time.Date(1720, 12, 30, 0, 0, 0, 0, time.UTC)
	t3 := time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)	
	
	fmt.Printf("%s: %d\n", t1, t1.UnixNano())
	fmt.Printf("%s: %d\n", t2, t2.UnixNano())
	fmt.Printf("%s: %d\n", t3, t3.UnixNano())
}
0001-01-01 00:00:00 +0000 UTC: -6795364578871345152
1720-12-30 00:00:00 +0000 UTC: -7857820800000000000
1970-01-01 00:00:00 +0000 UTC: 0

https://play.golang.org/p/XrtNdpfNFk1

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions