Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC]Fix end of the week when the date provider is the end of the week #66

Merged
merged 1 commit into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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