Add unittests for month
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-04-06 22:16:50 +00:00
parent 35690681cf
commit 8fe91293e1
5 changed files with 111 additions and 69 deletions

View File

@ -8,74 +8,6 @@ import (
"github.com/gin-gonic/gin"
)
type Month struct {
Year int
Month int
}
func NewFromTime(date time.Time) Month {
return Month{date.Year(), int(date.Month())}
}
func (m Month) String() string {
return fmt.Sprintf("%d-%d", m.Year, m.Month)
}
func (m Month) FirstOfMonth() time.Time {
return time.Date(m.Year, time.Month(m.Month), 1, 0, 0, 0, 0, time.Now().Location())
}
func (m Month) nextMonth() Month {
if m.Month == 12 {
return Month{m.Year + 1, 1}
}
return Month{m.Year, m.Month}
}
func (m Month) InFuture(date time.Time) bool {
if m.Year < date.Year() {
return true
}
if m.Year > date.Year() {
return false
}
return time.Month(m.Month) < date.Month()
}
func (m Month) isBeforeOrContains(date time.Time) bool {
if m.Year < date.Year() {
return true
}
if m.Year > date.Year() {
return false
}
return time.Month(m.Month) <= date.Month()
}
func (m Month) InPast(date time.Time) bool {
if m.Year > date.Year() {
return false
}
if m.Year < date.Year() {
return true
}
return time.Month(m.Month) > date.Month()
}
func (m Month) InPresent(date time.Time) bool {
if date.Year() != m.Year {
return false
}
return date.Month() == time.Month(m.Month)
}
func getDate(c *gin.Context) (Month, error) {
var year, month int
yearString := c.Param("year")