File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -57,4 +57,13 @@ describe('time class', () => {
5757 expect ( future . isAfter ( past , 'hour' ) ) . toBe ( false )
5858 } )
5959
60+ it ( 'converts to interval with human display' , ( ) => {
61+ const past = new Time ( '2021-01-15T10:00:00.000Z' )
62+ const future = new Time ( '2021-01-15T10:58:00.000Z' )
63+ const interval = future . intervalTo ( past )
64+ // it flipped start/end so start always comes first
65+ expect ( interval . start . isSame ( past , 'millisecond' ) ) . toBe ( true )
66+ expect ( interval . humanized ) . toEqual ( '58 minutes' )
67+ } )
68+
6069} )
Original file line number Diff line number Diff line change @@ -96,8 +96,15 @@ export default class Time {
9696 get asDate ( ) { return this . _value . toJSDate ( ) }
9797 get asDateTime ( ) { return this . _value }
9898
99- get intervalToNow ( ) { return new Interval ( { start : this , end : Time . now } ) }
100- intervalTo ( other : TimeInputs ) { return new Interval ( { start : this , end : toLDT ( other ) } ) }
99+ get intervalToNow ( ) { return this . intervalTo ( Time . now ) }
100+ intervalTo ( other : TimeInputs ) {
101+ const end = toLDT ( other )
102+ if ( this . isBefore ( end ) ) {
103+ return new Interval ( { start : this , end } )
104+ }
105+ return new Interval ( { start : end , end : this } )
106+ }
107+
101108
102109 toISOString ( ) { return this . asISOString }
103110 toString ( ) { return this . asISOString }
You can’t perform that action at this time.
0 commit comments