Created
November 22, 2018 22:39
-
-
Save innermond/32f3b3fd275d9385ec9b2d963a9659a0 to your computer and use it in GitHub Desktop.
print a basic text version of a year's month
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" | |
) | |
func main() { | |
year, m := 2018, time.Month(1) | |
tfirst := time.Date(year, m, 1, 0, 0, 0, 0, time.UTC) | |
da, wa := tfirst.Day(), tfirst.Weekday() | |
tlast := time.Date(year, m+1, 0, 0, 0, 0, 0, time.UTC) | |
dz, wz := tlast.Day(), tlast.Weekday() | |
x := 0 | |
for ; x < int(wa); x++ { | |
fmt.Print(" ") | |
} | |
d := 1 | |
for ; d <= dz; d++ { | |
if (d+int(wa)-1)%7 == 0 { | |
fmt.Println(d, " ") | |
} else { | |
fmt.Print(d, " ") | |
} | |
} | |
fmt.Println("\n", da, wa, int(wa), dz, wz, int(wz)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment