Skip to content

Commit d197a0c

Browse files
committed
precalculate start and end week
1 parent 60b67e6 commit d197a0c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

month/month.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@ import (
66
)
77

88
type Month struct {
9-
m time.Time
10-
dow time.Weekday
11-
now time.Time
9+
m time.Time
10+
dow time.Weekday
11+
now time.Time
12+
start time.Time // Start week
13+
end time.Time // End week
1214
}
1315

14-
func New(year int, month time.Month, dow time.Weekday, now time.Time) Month {
15-
return Month{
16+
func New(year int, month time.Month, dow time.Weekday, now time.Time) (m Month) {
17+
18+
m = Month{
1619
dow: dow,
1720
m: time.Date(year, month, 1, 0, 0, 0, 0, time.Local),
1821
now: now,
1922
}
23+
24+
m.start = m.getStart()
25+
m.end = m.getEnd()
26+
27+
return m
2028
}
2129

2230
func (mon Month) GetMonth() (start time.Time) {
@@ -50,10 +58,7 @@ func (mon Month) getEnd() (end time.Time) {
5058
}
5159

5260
func (mon Month) GetStartEndWeek() (start time.Time, end time.Time) {
53-
start = mon.getStart()
54-
end = mon.getEnd()
55-
56-
return start, end
61+
return mon.start, mon.end
5762
}
5863

5964
func (mon Month) GetDaysWeeks(start time.Time, end time.Time) (weeks int, days int) {

0 commit comments

Comments
 (0)