Skip to content

Commit

Permalink
Add lastMoment getter to Interval (#1280)
Browse files Browse the repository at this point in the history
* Add lastMoment getter to Interval

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.

* Change function name
  • Loading branch information
ties-s authored Aug 3, 2024
1 parent 2c923f9 commit eb71ce5
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 @@ -195,6 +195,14 @@ export default class Interval {
get end() {
return this.isValid ? this.e : null;
}

/**
* Returns the last DateTime included in the interval (since end is not part of the interval)
* @type {DateTime}
*/
get lastDateTime() {
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 eb71ce5

Please sign in to comment.