Created
March 23, 2012 07:59
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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