File tree 1 file changed +3
-28
lines changed
1 file changed +3
-28
lines changed Original file line number Diff line number Diff line change 1
1
package problem1154
2
2
3
- import "strconv"
4
-
5
- var daysBefore = [... ]int {
6
- 0 ,
7
- 31 ,
8
- 31 + 28 ,
9
- 31 + 28 + 31 ,
10
- 31 + 28 + 31 + 30 ,
11
- 31 + 28 + 31 + 30 + 31 ,
12
- 31 + 28 + 31 + 30 + 31 + 30 ,
13
- 31 + 28 + 31 + 30 + 31 + 30 + 31 ,
14
- 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 ,
15
- 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 ,
16
- 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 ,
17
- 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 ,
18
- }
3
+ import "time"
19
4
20
5
func dayOfYear (date string ) int {
21
- year , _ := strconv .Atoi (date [:4 ])
22
- month , _ := strconv .Atoi (date [5 :7 ])
23
- day , _ := strconv .Atoi (date [8 :])
24
- day += daysBefore [month - 1 ]
25
- if month > 2 && isLeap (year ) {
26
- day ++
27
- }
28
- return day
29
- }
30
-
31
- func isLeap (year int ) bool {
32
- return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0 )
6
+ t , _ := time .Parse ("2006-01-02" , date )
7
+ return t .YearDay ()
33
8
}
You can’t perform that action at this time.
0 commit comments