|
1 | | -import Time, { setNow, setResolution } from '../../src/model/time' |
| 1 | +import Time, { Interval, setNow, setResolution } from '../../src/model/time' |
2 | 2 | import { autorun } from 'mobx' |
3 | 3 | import moment from 'moment' |
4 | 4 |
|
@@ -57,13 +57,40 @@ describe('time class', () => { |
57 | 57 | expect(future.isAfter(past, 'hour')).toBe(false) |
58 | 58 | }) |
59 | 59 |
|
60 | | - it('converts to interval with human display', () => { |
| 60 | + it('has a humanized representation', () => { |
| 61 | + expect(new Interval({ |
| 62 | + start: '2020-01-14T03:00:00.000Z', |
| 63 | + end: '2021-01-15T10:58:03.330Z', |
| 64 | + }).humanized).toEqual('1 year') |
| 65 | + expect(new Interval({ |
| 66 | + start: '2021-01-14T03:00:00.000Z', |
| 67 | + end: '2021-04-15T10:58:03.330Z', |
| 68 | + }).humanized).toEqual('3 months') |
| 69 | + expect(new Interval({ |
| 70 | + start: '2021-01-14T03:00:00.000Z', |
| 71 | + end: '2021-01-18T10:58:03.330Z', |
| 72 | + }).humanized).toEqual('4 days') |
| 73 | + expect(new Interval({ |
| 74 | + start: '2021-01-14T03:00:00.000Z', |
| 75 | + end: '2021-01-14T10:58:03.330Z', |
| 76 | + }).humanized).toEqual('7 hours') |
| 77 | + expect(new Interval({ |
| 78 | + start: '2021-01-14T03:00:00.000Z', |
| 79 | + end: '2021-01-14T03:58:03.330Z', |
| 80 | + }).humanized).toEqual('58 minutes') |
| 81 | + expect(new Interval({ |
| 82 | + start: '2021-01-14T03:00:00.000Z', |
| 83 | + end: '2021-01-14T03:0:03.330Z', |
| 84 | + }).humanized).toEqual('now') |
| 85 | + }) |
| 86 | + |
| 87 | + it('converts to sentence', () => { |
61 | 88 | const past = new Time('2021-01-14T03:00:00.000Z') |
62 | 89 | const future = new Time('2021-01-15T10:58:03.330Z') |
63 | 90 | const interval = future.intervalTo(past) |
64 | 91 | // it flipped start/end so start always comes first |
65 | 92 | expect(interval.start.isSame(past, 'millisecond')).toBe(true) |
66 | | - expect(interval.humanized).toEqual('1 day, 7 hours and 58 minutes') |
| 93 | + expect(interval.asSentence).toEqual('1 day, 7 hours and 58 minutes') |
67 | 94 | }) |
68 | 95 |
|
69 | 96 | }) |
0 commit comments