Created
November 22, 2018 22:56
-
-
Save innermond/028dc5b0f9aebb25286a36f661b7de50 to your computer and use it in GitHub Desktop.
days of a month in a slice
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(11) | |
tfirst := time.Date(year, m, 1, 0, 0, 0, 0, time.UTC) | |
wa := int(tfirst.Weekday()) - 1 | |
tlast := time.Date(year, m+1, 0, 0, 0, 0, 0, time.UTC) | |
dz := int(tlast.Day()) | |
dd := make([][]int, 0) | |
row := make([]int, 0) | |
x := 0 | |
for ; x < wa; x++ { | |
row = append(row, 0) | |
} | |
d := 1 | |
for ; d <= dz; d++ { | |
row = append(row, d) | |
if (d+wa)%7 == 0 { | |
dd = append(dd, row) | |
row = make([]int, 0) | |
} | |
} | |
if len(row) > 0 { | |
dd = append(dd, row) | |
} | |
fmt.Println(dd) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment