Skip to content

Commit

Permalink
Merge 77df8a4 into 71fce27
Browse files Browse the repository at this point in the history
  • Loading branch information
rntdrts authored Feb 13, 2021
2 parents 71fce27 + 77df8a4 commit ce063dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions carbon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,10 @@ func (c *Carbon) StartOfWeek() *Carbon {

// EndOfWeek returns the date of the last day of the week at 23:59:59
func (c *Carbon) EndOfWeek() *Carbon {
if c.Weekday() == c.WeekEndsAt() {
return c.EndOfDay();
}

return c.Next(c.WeekEndsAt()).EndOfDay()
}

Expand Down
7 changes: 7 additions & 0 deletions carbon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2309,6 +2309,13 @@ func TestEndOfWeek(t *testing.T) {

expected, _ := Create(2016, time.August, 28, 23, 59, 59, 999999999, "UTC")
assert.Equal(t, expected, t2)

// test end of week when date is last day of weekend
t3, _ := Create(2021, time.January, 17, 13, 0, 0, 0, "UTC")
t4 := t3.EndOfWeek()

expected2, _ := Create(2021, time.January, 17, 23, 59, 59, 999999999, "UTC")
assert.Equal(t, expected2, t4)
}

func TestNextWeekday(t *testing.T) {
Expand Down

0 comments on commit ce063dd

Please sign in to comment.