Skip to content

Instantly share code, notes, and snippets.

@bemasher
Created March 23, 2012 07:59
Show Gist options
  • Save bemasher/2168135 to your computer and use it in GitHub Desktop.
Save bemasher/2168135 to your computer and use it in GitHub Desktop.
Days of the year which are powers of 2 starting from both beginning and end of the year.
package main
import (
"fmt"
"time"
)
const (
DateFormat = "2006-01-02: Jan 02"
)
func main() {
day := 24 * time.Hour
forwardDate := time.Date(2012, 1, 1, 0, 0, 0, 0, time.FixedZone("America/Denver", -6))
reverseDate := time.Date(2013, 1, 1, 0, 0, 0, 0, time.FixedZone("America/Denver", -6))
for i := 1; i < 356; i <<= 1 {
forward := forwardDate.Add(time.Duration(i) * day)
reverse := reverseDate.Add(-time.Duration(i) * day)
fmt.Printf("% 4d: %+v\t%+v\n", i, forward.Format(DateFormat), reverse.Format(DateFormat))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment