Skip to content

Commit

Permalink
Merge pull request #66 from uniplaces/fix-end-of-the-week
Browse files Browse the repository at this point in the history
[RFC]Fix end of the week when the date provider is the end of the week
  • Loading branch information
Tiago Brito authored Feb 13, 2021
2 parents 71fce27 + 77df8a4 commit 21aebc7
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 21aebc7

Please sign in to comment.