Skip to content

Commit eb71ce5

Browse files
authored
Add lastMoment getter to Interval (#1280)
* 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
1 parent 2c923f9 commit eb71ce5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/interval.js

+8
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ export default class Interval {
195195
get end() {
196196
return this.isValid ? this.e : null;
197197
}
198+
199+
/**
200+
* Returns the last DateTime included in the interval (since end is not part of the interval)
201+
* @type {DateTime}
202+
*/
203+
get lastDateTime() {
204+
return this.isValid ? this.e.minus(1) : null;
205+
}
198206

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

0 commit comments

Comments
 (0)