File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ /* eslint-env jest */
2+
3+ import { msUntilIntervalRepeat } from '../index'
4+
5+ describe ( 'msUntilIntervalRepeat' , ( ) => {
6+ test . each `
7+ now | interval | expected
8+ ${ 100 } | ${ 10 } | ${ 0 }
9+ ${ 1536625260000 } | ${ 60000 } | ${ 0 }
10+ ${ 60000 } | ${ 60000 } | ${ 0 }
11+ ${ 35 } | ${ 60 } | ${ 25 }
12+ ${ 110 } | ${ 100 } | ${ 90 }
13+ ${ 1 } | ${ 9 } | ${ 8 }
14+ ${ 1000 } | ${ 20 } | ${ 0 }
15+ ${ 9 } | ${ 20 } | ${ 11 }
16+ ` (
17+ 'returns remaining: $expected with now: $now and interval: $interval' ,
18+ ( { now, interval, expected} ) => {
19+ expect ( msUntilIntervalRepeat ( now , interval ) ) . toBe ( expected )
20+ } ,
21+ )
22+ } )
Original file line number Diff line number Diff line change @@ -4,6 +4,14 @@ import * as React from 'react'
44import moment from 'moment-timezone'
55import delay from 'delay'
66
7+ export function msUntilIntervalRepeat ( now : number , interval : number ) {
8+ let next = now
9+ while ( next % interval !== 0 ) {
10+ next += 1
11+ }
12+ return next - now
13+ }
14+
715type Props = {
816 interval : number , // ms
917 timezone ?: string ,
You can’t perform that action at this time.
0 commit comments