Skip to content

Instantly share code, notes, and snippets.

@natural
Created March 3, 2014 19:36
Show Gist options
  • Save natural/9332923 to your computer and use it in GitHub Desktop.
Save natural/9332923 to your computer and use it in GitHub Desktop.
// http://play.golang.org/p/i5L__nrXyA
package main
import (
"fmt"
"log"
"time"
)
// change this to your local time zone name.
const LOCAL_TZ = "America/Anchorage"
// if this is running on appengine, or on a system
// that can't load a tz database, also change this
// to match the utc offset for the tz name above
const LOCAL_OFFSET = -9
// change this to show more or fewer checkpoints
const SHOW_CHECKPOINTS = 100
// labels, don't mess with them
const (
CHECKPOINT = "checkpoint"
CYCLE = "cycle"
TIME_FORMAT = "02-Jan-2006 15:04 MST"
)
var (
// reference dates
REF_CHECKPOINT = time.Date(2014, time.March, 3, 22, 0, 0, 0, time.UTC)
REF_CYCLE = REF_CHECKPOINT.Add(time.Hour * 85)
)
func main() {
location, err := time.LoadLocation(LOCAL_TZ)
if true || err != nil {
log.Printf("couldn't load timezone " + LOCAL_TZ + "\n")
location = time.FixedZone("local", LOCAL_OFFSET*60*60)
}
fmt.Printf("reference checkpoint (utc): %v\n",
REF_CHECKPOINT.Format(TIME_FORMAT))
fmt.Printf("reference checkpoint (local): %v\n",
REF_CHECKPOINT.In(location).Format(TIME_FORMAT))
fmt.Printf("reference cycle (utc): %v\n",
REF_CYCLE.Format(TIME_FORMAT))
fmt.Printf("reference cycle (local): %v\n\n",
REF_CYCLE.In(location).Format(TIME_FORMAT))
var (
checkpoint = REF_CHECKPOINT
label string
now = time.Now()
offset time.Duration
)
for i := 0; i < SHOW_CHECKPOINTS; {
checkpoint = checkpoint.Add(5 * time.Hour)
if checkpoint.Before(now) {
continue
}
label = CHECKPOINT
offset = checkpoint.Sub(REF_CYCLE)
if offset.Hours() == 0 || int(offset.Hours())%125 == 0 {
label = CYCLE
}
fmt.Printf("%10s (utc, local): %v, %v\n",
label,
checkpoint.Format(TIME_FORMAT),
checkpoint.In(location).Format(TIME_FORMAT),
)
i += 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment