/
calendar.go
44 lines (35 loc) · 939 Bytes
/
calendar.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package geo
import "time"
// TODO: Create struct that tracks date and time.
type Calendar struct {
t time.Time
}
func NewCalendar() *Calendar {
return &Calendar{
t: time.Unix(0, 0),
}
}
// GetDayOfYear returns the current day of the year.
func (c *Calendar) GetDayOfYear() int {
return c.t.YearDay()
}
// Tick advances the calendar by one day.
func (c *Calendar) Tick() {
c.t = c.t.Add(time.Hour * 24)
}
// TickYear advances the calendar by one year.
func (c *Calendar) TickYear() {
c.t = c.t.AddDate(1, 0, 0)
}
// SetYear sets the year of the calendar.
func (c *Calendar) SetYear(year int64) {
c.t = time.Date(int(year), 1, 1, 0, 0, 0, 0, time.UTC)
}
// GetYear returns the current year.
func (c *Calendar) GetYear() int64 {
return int64(c.t.Year())
}
// GetYearProgress returns the progress of the current year in 0.0-1.0.
func (c *Calendar) GetYearProgress() float64 {
return float64(c.t.YearDay()) / float64(365)
}