Skip to content

Commit

Permalink
Add lastMoment getter to Interval
Browse files Browse the repository at this point in the history
Convenient way to get the last moment that is actually included in the interval. Makes it easier to properly use the fact that intervals are half open.

My use case: displaying end date of a monthly subscription.

I'm not sure `lastMoment` is the best way to name this, but it was the first thing that I thought of.
  • Loading branch information
ties-s committed Sep 3, 2022
1 parent 7480340 commit 011eaff
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/interval.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ export default class Interval {
get end() {
return this.isValid ? this.e : null;
}

/**
* Returns the last moment included in the interval (since end is not part of the interval)
* @type {DateTime}
*/
get lastMoment() {
return this.isValid ? this.e.minus(1) : null;
}

/**
* Returns whether this Interval's end is at least its start, meaning that the Interval isn't 'backwards'.
Expand Down

0 comments on commit 011eaff

Please sign in to comment.