Skip to content
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
6 changes: 3 additions & 3 deletions shared/specs/model/time.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ describe('time class', () => {
})

it('converts to interval with human display', () => {
const past = new Time('2021-01-15T10:00:00.000Z')
const future = new Time('2021-01-15T10:58:00.000Z')
const past = new Time('2021-01-14T03:00:00.000Z')
const future = new Time('2021-01-15T10:58:03.330Z')
const interval = future.intervalTo(past)
// it flipped start/end so start always comes first
expect(interval.start.isSame(past, 'millisecond')).toBe(true)
expect(interval.humanized).toEqual('58 minutes')
expect(interval.humanized).toEqual('1 day, 7 hours and 58 minutes')
})

})
5 changes: 3 additions & 2 deletions shared/src/model/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import moment from 'moment';
import { extendMoment } from 'moment-range';
import pluralize from 'pluralize';
import { now as getNow } from 'mobx-utils'
import { toSentence } from '../helpers/string';

const { range } = extendMoment(moment as any);

Expand Down Expand Up @@ -183,12 +184,12 @@ export class Interval {
}

get humanized() {
const { days, hours, minutes } = this.asLuxon.toDuration(['days', 'hours', 'minutes'])
const { days, hours, minutes } = this.asLuxon.toDuration(['days', 'hours', 'minutes', 'seconds'])
let str: string[] = []
if (days) str.push(pluralize('day', days, true))
if (hours) str.push(pluralize('hour', hours, true))
if (minutes) str.push(pluralize('minute', minutes, true))
return str.join(' ')
return toSentence(str)
}

get asMoment() {
Expand Down