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

Add DateRange.prepend (opposite direction of extend) #1748

Merged
merged 2 commits into from
Oct 22, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ case class DateRange(val start: RichDate, val end: RichDate) {
*/
def extend(delta: Duration) = DateRange(start, end + delta)

/**
* Extend the length by moving the start.
* Turns out, we can start the party early.
*/
def prepend(delta: Duration) = DateRange(start - delta, end)

def contains(point: RichDate) = (start <= point) && (point <= end)
/**
* Is the given Date range a (non-strict) subset of the given range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ class DateTest extends WordSpec {
"reject an end that is before its start" in {
intercept[IllegalArgumentException] { DateRange("2010-10-02", "2010-10-01") }
}
"correctly add time in either or both directions" in {
assert(DateRange("2010-10-01", "2010-10-02").extend(Days(3)).each(Days(1)).size === 5)
assert(DateRange("2010-10-01", "2010-10-02").prepend(Days(3)).each(Days(1)).size === 5)
assert(DateRange("2010-10-01", "2010-10-02").embiggen(Days(3)).each(Days(1)).size === 8)
assert(DateRange("2010-10-01", "2010-10-10").extend(Days(1)).prepend(Days(1)) ==
DateRange("2010-10-01", "2010-10-10").embiggen(Days(1)))
}
}
"Time units" should {
def isSame(d1: Duration, d2: Duration) = {
Expand Down