Skip to content

Commit

Permalink
LastDayOfMonth added
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick committed Dec 6, 2015
1 parent 552f750 commit 8550750
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions date.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ func (d Date) Date() (year int, month time.Month, day int) {
return t.Date()
}

// LastDayOfMonth returns the last day of the month specified by d.
// The first day of the month is 1.
func (d Date) LastDayOfMonth() int {
y, m, _ := d.Date()
return DaysIn(y, m)
}

// Day returns the day of the month specified by d.
// The first day of the month is 1.
func (d Date) Day() int {
Expand Down
11 changes: 8 additions & 3 deletions date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,14 @@ func TestDaysIn(t *testing.T) {
{2001, time.April, 30},
}
for _, c := range cases {
got := DaysIn(c.year, c.month)
if got != c.expected {
t.Errorf("TestIsLeap(%d) == %v, want %v", c.year, got, c.expected)
got1 := DaysIn(c.year, c.month)
if got1 != c.expected {
t.Errorf("DaysIn(%d) == %v, want %v", c.year, got1, c.expected)
}
d := New(c.year, c.month, 1)
got2 := d.LastDayOfMonth()
if got2 != c.expected {
t.Errorf("DaysIn(%d) == %v, want %v", c.year, got2, c.expected)
}
}
}

0 comments on commit 8550750

Please sign in to comment.