Easter eggs in Go source code
Tags: go, trivia
Published: 2020-07-21 01:14:40

---
title: Easter eggs in Go source code
published: true
description: Last week I got to know the Easter eggs hidden in Go's source code, so I share them in this post.
tags: Go, trivia
cover_image: https://www.shortlist.com/media/imager/201905/17227-posts.article_lg.jpg
---

## Preface

A week ago, I had a small chat with my friend over some Slack workspace, something like:

> friend: "Does anyone know why `time.minWall` defaults to 1885?"
> me: "No idea, maybe it's from the year in _Back To The Future 3_?"

At that time, I was almost joking but I had no idea why it was set to 1885 neither. Though the fact behind it does not have anything to do with my daily coding in Go, I couldn't help asking the behind-the-scene. I asked my peer Gophers in the team chat, but it seemed no one there couldn't reach the clues for the decision.

Finally, I sent an email to Russ Cox ([@_rsc](https://twitter.com/_rsc)) directly to know the background for the decision.

## `time.minWall`

A const value `time.minWall` is set to 1885.

* [src/time/time.go - go - Git at Google](https://go.googlesource.com/go/+/refs/tags/go1.14.5/src/time/time.go#153)

```
const (
    hasMonotonic = 1 << 63
    maxWall      = wallToInternal + (1<<33 - 1) // year 2157
    minWall      = wallToInternal               // year 1885
    nsecMask     = 1<<30 - 1
    nsecShift    = 30
)
```

This is the constant value that defines the epoch of values in time package. We often use UNIX epoch (i.e. 00:00:00 UTC on 1st January 1970), but it is just one epoch out of a couple of standards or implementations to express datetime values, and of course Go is a multi platform language, so the epoch in Go need to cover all those platforms.

Russ Cox had given comments on Go's epoch publicly in the following places. The first one is on [the GitHub issue thread](https://github.com/golang/go/issues/12914#issuecomment-277335863):

> OK, this is checked in for Go 1.9. I moved the internal epoch to 1885 (max year 2157) to avoid any possible problem with NTP-epoch-derived times. I also adjusted the design doc to reflect this change and some minor encoding changes.

But this comment only mentions why and when they moved the internal epoch to 1885, but not why they didn't to any other years, such as 1900.

The second one is the proposal doc for the move of the internal epoch.

* [Proposal: Monotonic Elapsed Time Measurement in Go](https://go.googlesource.com/proposal/+/master/design/12914-monotonic.md)

> Unix-based systems often use 1970, and Windows-based systems often use 1980. We are unaware of any systems using earlier default wall times, but since the NTP protocol epoch uses 1900, it seemed more future-proof to choose a year before 1900.

Okay, still the rationale supports any years before 1900, not specifically 1885. I was almost sure that the year is derived from _Back To The Future 3_, but I wanted 100% sure for it and I reached out to the person who only knows the decision behind it; I sent an email to Russ to ask the reason. He gave a response within a day (it's super quick, considering timezone difference between EDT and JST) saying:

> Yes, people talked me into moving it back before 1900, and 1885 was the obvious choice due to its historical significance to Hill Valley, California. :-)

I knew it!! Also, it was more than happy that I could get the true answer from who made the decision.

## `http.aLongTimeAgo`

While I appreciated the answer from Russ, it was not the end of the story. There was the another line in Russ' reply.

> See also http.aLongTimeAgo, which is now sadly set to time.Unix(1, 0) but used to be time.Unix(233431200, 0).

In Go 1.14.5, as he says, it's set to `time.Unix(1, 0)`.

* [Go 1.14.5: src/net/http/http.go - go - Git at Google](https://go.googlesource.com/go/+/refs/tags/go1.14.5/src/net/http/http.go#25)

```
// aLongTimeAgo is a non-zero time, far in the past, used for
// immediate cancellation of network operations.
var aLongTimeAgo = time.Unix(1, 0)
```

So let's confirm its original value when it was introduced to the source code. You can find it in Go 1.8.

* [Go 1.8: src/net/http/http.go - go - Git at Google](https://go.googlesource.com/go/+/refs/tags/go1.8/src/net/http/http.go#23)

```
// aLongTimeAgo is a non-zero time, far in the past, used for
// immediate cancelation of network operations.
var aLongTimeAgo = time.Unix(233431200, 0)
```

Let's convert the UNIX time to human readable format. Of course, Go gives super easy way to do it.

* [Sample code to read UNIX time in human readable format](https://play.golang.org/p/c4u1lF5Q6xQ)

```
package main

import (
	"fmt"
	"time"
)

func main() {
	pdt, _ := time.LoadLocation("America/Los_Angeles")
	t := time.Unix(233431200, 0).In(pdt)
	fmt.Println(t)
}
```

The result is:

```
1977-05-25 11:00:00 -0700 PDT
```

We got 2 hints: "A Long Time Ago" and "May 25th, 1977". What these 2 lead to is...

![A long time ago...](https://dev-to-uploads.s3.amazonaws.com/i/hht1vvzyqi1ybuyucn2j.png)

Of course, nothing but _Star Wars: Episode IV_. It was released on May 25th, 1977 ([Wikipedia](https://en.wikipedia.org/wiki/Star_Wars_(film))) 

How this value is used in Go package is to force cancelling existing connections immediately by giving deadlines in past time, such as:

```
cr.conn.rwc.SetReadDeadline(aLongTimeAgo)
```

Some people reacted on the changes when the value was changed to `time.Unix(1, 0)`. I love to see these kinds of comments; those fun chats occasionally happen in changelists.

* [net, net/http: adjust time-in-past constant even earlier](https://github.com/golang/go/commit/6983b9a57955fa12ecd81ab8394ee09e64ef21b9)

## Acknowledgement

* Russ Cox: Thank you for replying to my question and the additional information. Also, thank you for the approval to share this publicly. Quoting his comment:

> Feel free. No secrets here.

* [Chris Broadfoot](https://twitter.com/broady) and [Valentin Deleplace](https://twitter.com/val_deleplace): Thank you for finding out the clues together on the group chat.

* [mattn](https://twitter.com/mattn_jp): Thank you for letting me know the GitHub thread where people reacted on the value. 

## Note

This entry was originally posted to my Japanese blog on July 17th.

* https://ymotongpoo.hatenablog.com/entry/2020/07/17/093000