javascript-time-ago 2.5.10 → 2.5.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/javascript-time-ago.js +1 -1
- package/bundle/javascript-time-ago.js.map +1 -1
- package/bundle/javascript-time-ago.min.js +1 -1
- package/bundle/javascript-time-ago.min.js.map +1 -1
- package/commonjs/LocaleDataStore.js +2 -5
- package/commonjs/LocaleDataStore.js.map +1 -1
- package/commonjs/PropTypes.js +12 -12
- package/commonjs/PropTypes.js.map +1 -1
- package/commonjs/TimeAgo.js +135 -190
- package/commonjs/TimeAgo.js.map +1 -1
- package/commonjs/TimeAgo.test.js +124 -130
- package/commonjs/TimeAgo.test.js.map +1 -1
- package/commonjs/cache.js +7 -25
- package/commonjs/cache.js.map +1 -1
- package/commonjs/cache.test.js +1 -3
- package/commonjs/cache.test.js.map +1 -1
- package/commonjs/isStyleObject.js +9 -9
- package/commonjs/isStyleObject.js.map +1 -1
- package/commonjs/isStyleObject.test.js +1 -3
- package/commonjs/isStyleObject.test.js.map +1 -1
- package/commonjs/locale.js +6 -19
- package/commonjs/locale.js.map +1 -1
- package/commonjs/locale.test.js +2 -11
- package/commonjs/locale.test.js.map +1 -1
- package/commonjs/round.js +2 -5
- package/commonjs/round.js.map +1 -1
- package/commonjs/steps/approximate.js +1 -4
- package/commonjs/steps/approximate.js.map +1 -1
- package/commonjs/steps/approximate.test.js +1 -6
- package/commonjs/steps/approximate.test.js.map +1 -1
- package/commonjs/steps/getStep.js +36 -53
- package/commonjs/steps/getStep.js.map +1 -1
- package/commonjs/steps/getStep.test.js +7 -7
- package/commonjs/steps/getStep.test.js.map +1 -1
- package/commonjs/steps/getStepDenominator.js +2 -5
- package/commonjs/steps/getStepDenominator.js.map +1 -1
- package/commonjs/steps/getStepDenominator.test.js +1 -3
- package/commonjs/steps/getStepDenominator.test.js.map +1 -1
- package/commonjs/steps/getStepMinTime.js +17 -32
- package/commonjs/steps/getStepMinTime.js.map +1 -1
- package/commonjs/steps/getStepMinTime.test.js +1 -3
- package/commonjs/steps/getStepMinTime.test.js.map +1 -1
- package/commonjs/steps/getTimeToNextUpdate.js +19 -41
- package/commonjs/steps/getTimeToNextUpdate.js.map +1 -1
- package/commonjs/steps/getTimeToNextUpdate.test.js +29 -25
- package/commonjs/steps/getTimeToNextUpdate.test.js.map +1 -1
- package/commonjs/steps/getTimeToNextUpdateForUnit.js +3 -12
- package/commonjs/steps/getTimeToNextUpdateForUnit.js.map +1 -1
- package/commonjs/steps/getTimeToNextUpdateForUnit.test.js +1 -7
- package/commonjs/steps/getTimeToNextUpdateForUnit.test.js.map +1 -1
- package/commonjs/steps/helpers.js +1 -2
- package/commonjs/steps/helpers.js.map +1 -1
- package/commonjs/steps/helpers.test.js +0 -1
- package/commonjs/steps/helpers.test.js.map +1 -1
- package/commonjs/steps/index.js +1 -6
- package/commonjs/steps/index.js.map +1 -1
- package/commonjs/steps/renameLegacyProperties.js +6 -14
- package/commonjs/steps/renameLegacyProperties.js.map +1 -1
- package/commonjs/steps/renameLegacyProperties.test.js +1 -3
- package/commonjs/steps/renameLegacyProperties.test.js.map +1 -1
- package/commonjs/steps/round.js +1 -2
- package/commonjs/steps/round.js.map +1 -1
- package/commonjs/steps/round.test.js +1 -7
- package/commonjs/steps/round.test.js.map +1 -1
- package/commonjs/steps/units.js +10 -21
- package/commonjs/steps/units.js.map +1 -1
- package/commonjs/style/approximate.js +2 -6
- package/commonjs/style/approximate.js.map +1 -1
- package/commonjs/style/approximateTime.js +2 -6
- package/commonjs/style/approximateTime.js.map +1 -1
- package/commonjs/style/approximateTime.test.js +116 -75
- package/commonjs/style/approximateTime.test.js.map +1 -1
- package/commonjs/style/getStyleByName.js +3 -29
- package/commonjs/style/getStyleByName.js.map +1 -1
- package/commonjs/style/mini.js +9 -6
- package/commonjs/style/mini.js.map +1 -1
- package/commonjs/style/mini.test.js +15 -25
- package/commonjs/style/mini.test.js.map +1 -1
- package/commonjs/style/miniMinute.js +8 -13
- package/commonjs/style/miniMinute.js.map +1 -1
- package/commonjs/style/miniMinute.test.js +11 -17
- package/commonjs/style/miniMinute.test.js.map +1 -1
- package/commonjs/style/miniMinuteNow.js +8 -13
- package/commonjs/style/miniMinuteNow.js.map +1 -1
- package/commonjs/style/miniMinuteNow.test.js +11 -17
- package/commonjs/style/miniMinuteNow.test.js.map +1 -1
- package/commonjs/style/miniNow.js +8 -13
- package/commonjs/style/miniNow.js.map +1 -1
- package/commonjs/style/miniNow.test.js +11 -17
- package/commonjs/style/miniNow.test.js.map +1 -1
- package/commonjs/style/renameLegacyProperties.js +7 -13
- package/commonjs/style/renameLegacyProperties.js.map +1 -1
- package/commonjs/style/renameLegacyProperties.test.js +1 -4
- package/commonjs/style/renameLegacyProperties.test.js.map +1 -1
- package/commonjs/style/round.js +2 -6
- package/commonjs/style/round.js.map +1 -1
- package/commonjs/style/round.test.js +51 -67
- package/commonjs/style/round.test.js.map +1 -1
- package/commonjs/style/roundMinute.js +8 -13
- package/commonjs/style/roundMinute.js.map +1 -1
- package/commonjs/style/roundMinute.test.js +20 -27
- package/commonjs/style/roundMinute.test.js.map +1 -1
- package/commonjs/style/twitter.js +34 -38
- package/commonjs/style/twitter.js.map +1 -1
- package/commonjs/style/twitter.test.js +49 -55
- package/commonjs/style/twitter.test.js.map +1 -1
- package/commonjs/style/twitterFirstMinute.js +10 -15
- package/commonjs/style/twitterFirstMinute.js.map +1 -1
- package/commonjs/style/twitterFirstMinute.test.js +16 -23
- package/commonjs/style/twitterFirstMinute.test.js.map +1 -1
- package/commonjs/style/twitterMinute.js +8 -13
- package/commonjs/style/twitterMinute.js.map +1 -1
- package/commonjs/style/twitterMinute.test.js +20 -25
- package/commonjs/style/twitterMinute.test.js.map +1 -1
- package/commonjs/style/twitterMinuteNow.js +8 -13
- package/commonjs/style/twitterMinuteNow.js.map +1 -1
- package/commonjs/style/twitterMinuteNow.test.js +20 -25
- package/commonjs/style/twitterMinuteNow.test.js.map +1 -1
- package/commonjs/style/twitterNow.js +8 -13
- package/commonjs/style/twitterNow.js.map +1 -1
- package/commonjs/style/twitterNow.test.js +18 -24
- package/commonjs/style/twitterNow.test.js.map +1 -1
- package/load-all-locales/index.cjs +32 -0
- package/load-all-locales/index.cjs.js +32 -0
- package/load-all-locales/index.js +64 -0
- package/locale/ak/package.json +16 -0
- package/locale/ak.json +267 -0
- package/locale/ak.json.d.ts +4 -0
- package/locale/ak.json.js +267 -0
- package/locale/bal-Latn/package.json +16 -0
- package/locale/bal-Latn.json +240 -0
- package/locale/bal-Latn.json.d.ts +4 -0
- package/locale/bal-Latn.json.js +240 -0
- package/locale/be-tarask/package.json +16 -0
- package/locale/be-tarask.json +259 -0
- package/locale/be-tarask.json.d.ts +4 -0
- package/locale/be-tarask.json.js +259 -0
- package/locale/blo/package.json +16 -0
- package/locale/blo.json +159 -0
- package/locale/blo.json.d.ts +4 -0
- package/locale/blo.json.js +159 -0
- package/locale/bn.json +5 -2
- package/locale/bn.json.js +5 -2
- package/locale/bs.json +8 -2
- package/locale/bs.json.js +8 -2
- package/locale/ccp.json +2 -8
- package/locale/ccp.json.js +2 -8
- package/locale/csw/package.json +16 -0
- package/locale/csw.json +180 -0
- package/locale/csw.json.d.ts +4 -0
- package/locale/csw.json.js +180 -0
- package/locale/cy.json +6 -12
- package/locale/cy.json.js +6 -12
- package/locale/doi/package.json +16 -0
- package/locale/doi.json +159 -0
- package/locale/doi.json.d.ts +4 -0
- package/locale/doi.json.js +159 -0
- package/locale/en-AU.json +12 -12
- package/locale/en-AU.json.js +12 -12
- package/locale/en-CZ/package.json +16 -0
- package/locale/en-CZ.json +219 -0
- package/locale/en-CZ.json.d.ts +4 -0
- package/locale/en-CZ.json.js +219 -0
- package/locale/en-ES/package.json +16 -0
- package/locale/en-ES.json +219 -0
- package/locale/en-ES.json.d.ts +4 -0
- package/locale/en-ES.json.js +219 -0
- package/locale/en-FR/package.json +16 -0
- package/locale/en-FR.json +219 -0
- package/locale/en-FR.json.d.ts +4 -0
- package/locale/en-FR.json.js +219 -0
- package/locale/en-GS/package.json +16 -0
- package/locale/en-GS.json +219 -0
- package/locale/en-GS.json.d.ts +4 -0
- package/locale/en-GS.json.js +219 -0
- package/locale/en-HU/package.json +16 -0
- package/locale/en-HU.json +219 -0
- package/locale/en-HU.json.d.ts +4 -0
- package/locale/en-HU.json.js +219 -0
- package/locale/en-ID/package.json +16 -0
- package/locale/en-ID.json +219 -0
- package/locale/en-ID.json.d.ts +4 -0
- package/locale/en-ID.json.js +219 -0
- package/locale/en-IT/package.json +16 -0
- package/locale/en-IT.json +219 -0
- package/locale/en-IT.json.d.ts +4 -0
- package/locale/en-IT.json.js +219 -0
- package/locale/en-NO/package.json +16 -0
- package/locale/en-NO.json +219 -0
- package/locale/en-NO.json.d.ts +4 -0
- package/locale/en-NO.json.js +219 -0
- package/locale/en-PL/package.json +16 -0
- package/locale/en-PL.json +219 -0
- package/locale/en-PL.json.d.ts +4 -0
- package/locale/en-PL.json.js +219 -0
- package/locale/en-PT/package.json +16 -0
- package/locale/en-PT.json +219 -0
- package/locale/en-PT.json.d.ts +4 -0
- package/locale/en-PT.json.js +219 -0
- package/locale/en-RO/package.json +16 -0
- package/locale/en-RO.json +219 -0
- package/locale/en-RO.json.d.ts +4 -0
- package/locale/en-RO.json.js +219 -0
- package/locale/en-SK/package.json +16 -0
- package/locale/en-SK.json +219 -0
- package/locale/en-SK.json.d.ts +4 -0
- package/locale/en-SK.json.js +219 -0
- package/locale/es-MX.json +12 -9
- package/locale/es-MX.json.js +12 -9
- package/locale/es-SV.json +2 -2
- package/locale/es-SV.json.js +2 -2
- package/locale/eu.json +24 -24
- package/locale/eu.json.js +24 -24
- package/locale/ha.json +119 -65
- package/locale/ha.json.js +119 -65
- package/locale/he.json +0 -6
- package/locale/he.json.js +0 -6
- package/locale/hi-Latn.json +2 -2
- package/locale/hi-Latn.json.js +2 -2
- package/locale/ht/package.json +16 -0
- package/locale/ht.json +207 -0
- package/locale/ht.json.d.ts +4 -0
- package/locale/ht.json.js +207 -0
- package/locale/id.json +1 -1
- package/locale/id.json.js +1 -1
- package/locale/ie/package.json +16 -0
- package/locale/ie.json +159 -0
- package/locale/ie.json.d.ts +4 -0
- package/locale/ie.json.js +159 -0
- package/locale/ig.json +17 -17
- package/locale/ig.json.js +17 -17
- package/locale/ii/package.json +16 -0
- package/locale/ii.json +165 -0
- package/locale/ii.json.d.ts +4 -0
- package/locale/ii.json.js +165 -0
- package/locale/is.json +4 -1
- package/locale/is.json.js +4 -1
- package/locale/kaa/package.json +16 -0
- package/locale/kaa.json +159 -0
- package/locale/kaa.json.d.ts +4 -0
- package/locale/kaa.json.js +159 -0
- package/locale/kok-Latn/package.json +16 -0
- package/locale/kok-Latn.json +159 -0
- package/locale/kok-Latn.json.d.ts +4 -0
- package/locale/kok-Latn.json.js +159 -0
- package/locale/kok.json +8 -8
- package/locale/kok.json.js +8 -8
- package/locale/ks.json +9 -9
- package/locale/ks.json.js +9 -9
- package/locale/ku.json +55 -46
- package/locale/ku.json.js +55 -46
- package/locale/lld/package.json +16 -0
- package/locale/lld.json +291 -0
- package/locale/lld.json.d.ts +4 -0
- package/locale/lld.json.js +291 -0
- package/locale/mi.json +22 -22
- package/locale/mi.json.js +22 -22
- package/locale/ms-Arab/package.json +16 -0
- package/locale/ms-Arab.json +159 -0
- package/locale/ms-Arab.json.d.ts +4 -0
- package/locale/ms-Arab.json.js +159 -0
- package/locale/nb.json +2 -2
- package/locale/nb.json.js +2 -2
- package/locale/ne.json +1 -1
- package/locale/ne.json.js +1 -1
- package/locale/nn.json +4 -4
- package/locale/nn.json.js +4 -4
- package/locale/no.json +2 -2
- package/locale/no.json.js +2 -2
- package/locale/nqo/package.json +16 -0
- package/locale/nqo.json +159 -0
- package/locale/nqo.json.d.ts +4 -0
- package/locale/nqo.json.js +159 -0
- package/locale/om/package.json +16 -0
- package/locale/om.json +213 -0
- package/locale/om.json.d.ts +4 -0
- package/locale/om.json.js +213 -0
- package/locale/or.json +1 -1
- package/locale/or.json.js +1 -1
- package/locale/pl.json +59 -0
- package/locale/pl.json.js +59 -0
- package/locale/qu.json +46 -46
- package/locale/qu.json.js +46 -46
- package/locale/rhg/package.json +16 -0
- package/locale/rhg.json +159 -0
- package/locale/rhg.json.d.ts +4 -0
- package/locale/rhg.json.js +159 -0
- package/locale/sl.json +12 -12
- package/locale/sl.json.js +12 -12
- package/locale/sr-Cyrl-BA.json +2 -2
- package/locale/sr-Cyrl-BA.json.js +2 -2
- package/locale/sr-Latn-BA.json +2 -2
- package/locale/sr-Latn-BA.json.js +2 -2
- package/locale/sv.json +1 -1
- package/locale/sv.json.js +1 -1
- package/locale/syr/package.json +16 -0
- package/locale/syr.json +303 -0
- package/locale/syr.json.d.ts +4 -0
- package/locale/syr.json.js +303 -0
- package/locale/ti.json +6 -6
- package/locale/ti.json.js +6 -6
- package/locale/tn/package.json +16 -0
- package/locale/tn.json +159 -0
- package/locale/tn.json.d.ts +4 -0
- package/locale/tn.json.js +159 -0
- package/locale/to.json +26 -26
- package/locale/to.json.js +26 -26
- package/locale/uk.json +1 -1
- package/locale/uk.json.js +1 -1
- package/locale/ur-IN.json +9 -6
- package/locale/ur-IN.json.js +9 -6
- package/locale/vec/package.json +16 -0
- package/locale/vec.json +267 -0
- package/locale/vec.json.d.ts +4 -0
- package/locale/vec.json.js +267 -0
- package/locale/xnr/package.json +16 -0
- package/locale/xnr.json +159 -0
- package/locale/xnr.json.d.ts +4 -0
- package/locale/xnr.json.js +159 -0
- package/locale/yo-BJ.json +17 -17
- package/locale/yo-BJ.json.js +17 -17
- package/locale/yo.json +17 -17
- package/locale/yo.json.js +17 -17
- package/locale-more-styles/pl/long-time.json +30 -0
- package/locale-more-styles/pl/mini.json +9 -0
- package/locale-more-styles/pl/now.json +7 -0
- package/locale-more-styles/pl/short-time.json +12 -0
- package/modules/LocaleDataStore.js +2 -3
- package/modules/LocaleDataStore.js.map +1 -1
- package/modules/PropTypes.js +11 -7
- package/modules/PropTypes.js.map +1 -1
- package/modules/TimeAgo.js +135 -174
- package/modules/TimeAgo.js.map +1 -1
- package/modules/TimeAgo.test.js +126 -115
- package/modules/TimeAgo.test.js.map +1 -1
- package/modules/cache.js +6 -22
- package/modules/cache.js.map +1 -1
- package/modules/cache.test.js.map +1 -1
- package/modules/isStyleObject.js +9 -7
- package/modules/isStyleObject.js.map +1 -1
- package/modules/isStyleObject.test.js.map +1 -1
- package/modules/locale.js +6 -16
- package/modules/locale.js.map +1 -1
- package/modules/locale.test.js +0 -4
- package/modules/locale.test.js.map +1 -1
- package/modules/round.js +2 -3
- package/modules/round.js.map +1 -1
- package/modules/steps/approximate.js +6 -2
- package/modules/steps/approximate.js.map +1 -1
- package/modules/steps/approximate.test.js +0 -2
- package/modules/steps/approximate.test.js.map +1 -1
- package/modules/steps/getStep.js +36 -48
- package/modules/steps/getStep.js.map +1 -1
- package/modules/steps/getStep.test.js +6 -2
- package/modules/steps/getStep.test.js.map +1 -1
- package/modules/steps/getStepDenominator.js +2 -3
- package/modules/steps/getStepDenominator.js.map +1 -1
- package/modules/steps/getStepDenominator.test.js.map +1 -1
- package/modules/steps/getStepMinTime.js +17 -29
- package/modules/steps/getStepMinTime.js.map +1 -1
- package/modules/steps/getStepMinTime.test.js.map +1 -1
- package/modules/steps/getTimeToNextUpdate.js +19 -31
- package/modules/steps/getTimeToNextUpdate.js.map +1 -1
- package/modules/steps/getTimeToNextUpdate.test.js +27 -18
- package/modules/steps/getTimeToNextUpdate.test.js.map +1 -1
- package/modules/steps/getTimeToNextUpdateForUnit.js +4 -10
- package/modules/steps/getTimeToNextUpdateForUnit.js.map +1 -1
- package/modules/steps/getTimeToNextUpdateForUnit.test.js +0 -4
- package/modules/steps/getTimeToNextUpdateForUnit.test.js.map +1 -1
- package/modules/steps/helpers.js +1 -1
- package/modules/steps/helpers.js.map +1 -1
- package/modules/steps/helpers.test.js.map +1 -1
- package/modules/steps/index.js +2 -1
- package/modules/steps/index.js.map +1 -1
- package/modules/steps/renameLegacyProperties.js +6 -13
- package/modules/steps/renameLegacyProperties.js.map +1 -1
- package/modules/steps/renameLegacyProperties.test.js.map +1 -1
- package/modules/steps/round.js.map +1 -1
- package/modules/steps/round.test.js +0 -3
- package/modules/steps/round.test.js.map +1 -1
- package/modules/steps/units.js +5 -9
- package/modules/steps/units.js.map +1 -1
- package/modules/style/approximate.js +5 -1
- package/modules/style/approximate.js.map +1 -1
- package/modules/style/approximateTime.js +6 -2
- package/modules/style/approximateTime.js.map +1 -1
- package/modules/style/approximateTime.test.js +115 -70
- package/modules/style/approximateTime.test.js.map +1 -1
- package/modules/style/getStyleByName.js +4 -17
- package/modules/style/getStyleByName.js.map +1 -1
- package/modules/style/mini.js +8 -4
- package/modules/style/mini.js.map +1 -1
- package/modules/style/mini.test.js +14 -20
- package/modules/style/mini.test.js.map +1 -1
- package/modules/style/miniMinute.js +6 -6
- package/modules/style/miniMinute.js.map +1 -1
- package/modules/style/miniMinute.test.js +10 -12
- package/modules/style/miniMinute.test.js.map +1 -1
- package/modules/style/miniMinuteNow.js +6 -6
- package/modules/style/miniMinuteNow.js.map +1 -1
- package/modules/style/miniMinuteNow.test.js +10 -12
- package/modules/style/miniMinuteNow.test.js.map +1 -1
- package/modules/style/miniNow.js +6 -6
- package/modules/style/miniNow.js.map +1 -1
- package/modules/style/miniNow.test.js +10 -12
- package/modules/style/miniNow.test.js.map +1 -1
- package/modules/style/renameLegacyProperties.js +8 -10
- package/modules/style/renameLegacyProperties.js.map +1 -1
- package/modules/style/renameLegacyProperties.test.js +0 -1
- package/modules/style/renameLegacyProperties.test.js.map +1 -1
- package/modules/style/round.js +3 -2
- package/modules/style/round.js.map +1 -1
- package/modules/style/round.test.js +50 -62
- package/modules/style/round.test.js.map +1 -1
- package/modules/style/roundMinute.js +8 -7
- package/modules/style/roundMinute.js.map +1 -1
- package/modules/style/roundMinute.test.js +19 -22
- package/modules/style/roundMinute.test.js.map +1 -1
- package/modules/style/twitter.js +35 -32
- package/modules/style/twitter.js.map +1 -1
- package/modules/style/twitter.test.js +48 -50
- package/modules/style/twitter.test.js.map +1 -1
- package/modules/style/twitterFirstMinute.js +8 -7
- package/modules/style/twitterFirstMinute.js.map +1 -1
- package/modules/style/twitterFirstMinute.test.js +15 -18
- package/modules/style/twitterFirstMinute.test.js.map +1 -1
- package/modules/style/twitterMinute.js +6 -6
- package/modules/style/twitterMinute.js.map +1 -1
- package/modules/style/twitterMinute.test.js +19 -20
- package/modules/style/twitterMinute.test.js.map +1 -1
- package/modules/style/twitterMinuteNow.js +6 -6
- package/modules/style/twitterMinuteNow.js.map +1 -1
- package/modules/style/twitterMinuteNow.test.js +19 -20
- package/modules/style/twitterMinuteNow.test.js.map +1 -1
- package/modules/style/twitterNow.js +6 -6
- package/modules/style/twitterNow.js.map +1 -1
- package/modules/style/twitterNow.test.js +17 -19
- package/modules/style/twitterNow.test.js.map +1 -1
- package/package.json +261 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStepMinTime.js","names":["getSecondsInUnit","getDiffRatioToNextRoundedNumber","getStepMinTime","step","prevStep","timestamp","now","future","round","minTime","id","unit","undefined","threshold","getMinTimeForUnit","toUnit","fromUnit","formatAs","test","console","warn","JSON","stringify","toUnitAmount","fromUnitAmount"],"sources":["../../source/steps/getStepMinTime.js"],"sourcesContent":["import { getSecondsInUnit } from './units.js'\r\nimport { getDiffRatioToNextRoundedNumber } from '../round.js'\r\n\r\nexport default function getStepMinTime(step, {\r\n\tprevStep,\r\n\ttimestamp,\r\n\t// `now` argument is used in a deprecated `step.test()` function.\r\n\tnow,\r\n\tfuture,\r\n\tround\r\n}) {\r\n\tlet minTime\r\n\t// \"threshold_for_xxx\" is a legacy property.\r\n\tif (prevStep) {\r\n\t\tif (prevStep.id || prevStep.unit) {\r\n\t\t\tminTime = step[`threshold_for_${prevStep.id || prevStep.unit}`]\r\n\t\t}\r\n\t}\r\n\tif (minTime === undefined) {\r\n\t\t// \"threshold\" is a legacy property.\r\n\t\tif (step.threshold !== undefined) {\r\n\t\t\t// \"threshold\" is a legacy name for \"minTime\".\r\n\t\t\tminTime = step.threshold\r\n\t\t\t// \"threshold\" function is deprecated.\r\n\t\t\tif (typeof minTime === 'function') {\r\n\t\t\t\tminTime = minTime(now, future)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (minTime === undefined) {\r\n\t\tminTime = step.minTime\r\n\t}\r\n\t// A deprecated way of specifying a different threshold\r\n\t// depending on the previous step's unit.\r\n\tif (typeof minTime === 'object') {\r\n\t\tif (prevStep && prevStep.id && minTime[prevStep.id] !== undefined) {\r\n\t\t\tminTime = minTime[prevStep.id]\r\n\t\t} else {\r\n\t\t\tminTime = minTime.default\r\n\t\t}\r\n\t}\r\n\tif (typeof minTime === 'function') {\r\n\t\tminTime = minTime(timestamp, {\r\n\t\t\tfuture,\r\n\t\t\tgetMinTimeForUnit(toUnit, fromUnit) {\r\n\t\t\t\treturn getMinTimeForUnit(\r\n\t\t\t\t\ttoUnit,\r\n\t\t\t\t\tfromUnit || prevStep && prevStep.formatAs,\r\n\t\t\t\t\t{ round }\r\n\t\t\t\t)\r\n\t\t\t}\r\n\t\t})\r\n\t}\r\n\t// Evaluate the `test()` function.\r\n\t// `test()` function is deprecated.\r\n\tif (minTime === undefined) {\r\n\t\tif (step.test) {\r\n\t\t\tif (step.test(timestamp, {\r\n\t\t\t\tnow,\r\n\t\t\t\tfuture\r\n\t\t\t})) {\r\n\t\t\t\t// `0` threshold always passes.\r\n\t\t\t\tminTime = 0\r\n\t\t\t} else {\r\n\t\t\t\t// `MAX_SAFE_INTEGER` threshold won't ever pass in real life.\r\n\t\t\t\tminTime = 9007199254740991 // Number.MAX_SAFE_INTEGER\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (minTime === undefined) {\r\n\t\tif (prevStep) {\r\n\t\t\tif (step.formatAs && prevStep.formatAs) {\r\n\t\t\t\tminTime = getMinTimeForUnit(step.formatAs, prevStep.formatAs, { round })\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\t// The first step's `minTime` is `0` by default.\r\n\t\t\tminTime = 0\r\n\t\t}\r\n\t}\r\n\t// Warn if no `minTime` was defined or could be deduced.\r\n\tif (minTime === undefined) {\r\n\t\tconsole.warn('[javascript-time-ago] A step should specify `minTime`:\\n' + JSON.stringify(step, null, 2))\r\n\t}\r\n\treturn minTime\r\n}\r\n\r\nfunction getMinTimeForUnit(toUnit, fromUnit, { round }) {\r\n\tconst toUnitAmount = getSecondsInUnit(toUnit)\r\n\t// if (!fromUnit) {\r\n\t// \treturn toUnitAmount;\r\n\t// }\r\n\t// if (!fromUnit) {\r\n\t// \tfromUnit = getPreviousUnitFor(toUnit)\r\n\t// }\r\n\tlet fromUnitAmount\r\n\tif (fromUnit === 'now') {\r\n\t\tfromUnitAmount = getSecondsInUnit(toUnit)\r\n\t} else {\r\n\t\tfromUnitAmount = getSecondsInUnit(fromUnit)\r\n\t}\r\n\tif (toUnitAmount !== undefined && fromUnitAmount !== undefined) {\r\n\t\treturn toUnitAmount - fromUnitAmount * (1 - getDiffRatioToNextRoundedNumber(round))\r\n\t}\r\n}"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getStepMinTime.js","names":["getSecondsInUnit","getDiffRatioToNextRoundedNumber","getStepMinTime","step","_ref","prevStep","timestamp","now","future","round","minTime","id","unit","concat","undefined","threshold","_typeof","getMinTimeForUnit","toUnit","fromUnit","formatAs","test","console","warn","JSON","stringify","_ref2","toUnitAmount","fromUnitAmount"],"sources":["../../source/steps/getStepMinTime.js"],"sourcesContent":["import { getSecondsInUnit } from './units.js'\r\nimport { getDiffRatioToNextRoundedNumber } from '../round.js'\r\n\r\nexport default function getStepMinTime(step, {\r\n\tprevStep,\r\n\ttimestamp,\r\n\t// `now` argument is used in a deprecated `step.test()` function.\r\n\tnow,\r\n\tfuture,\r\n\tround\r\n}) {\r\n\tlet minTime\r\n\t// \"threshold_for_xxx\" is a legacy property.\r\n\tif (prevStep) {\r\n\t\tif (prevStep.id || prevStep.unit) {\r\n\t\t\tminTime = step[`threshold_for_${prevStep.id || prevStep.unit}`]\r\n\t\t}\r\n\t}\r\n\tif (minTime === undefined) {\r\n\t\t// \"threshold\" is a legacy property.\r\n\t\tif (step.threshold !== undefined) {\r\n\t\t\t// \"threshold\" is a legacy name for \"minTime\".\r\n\t\t\tminTime = step.threshold\r\n\t\t\t// \"threshold\" function is deprecated.\r\n\t\t\tif (typeof minTime === 'function') {\r\n\t\t\t\tminTime = minTime(now, future)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (minTime === undefined) {\r\n\t\tminTime = step.minTime\r\n\t}\r\n\t// A deprecated way of specifying a different threshold\r\n\t// depending on the previous step's unit.\r\n\tif (typeof minTime === 'object') {\r\n\t\tif (prevStep && prevStep.id && minTime[prevStep.id] !== undefined) {\r\n\t\t\tminTime = minTime[prevStep.id]\r\n\t\t} else {\r\n\t\t\tminTime = minTime.default\r\n\t\t}\r\n\t}\r\n\tif (typeof minTime === 'function') {\r\n\t\tminTime = minTime(timestamp, {\r\n\t\t\tfuture,\r\n\t\t\tgetMinTimeForUnit(toUnit, fromUnit) {\r\n\t\t\t\treturn getMinTimeForUnit(\r\n\t\t\t\t\ttoUnit,\r\n\t\t\t\t\tfromUnit || prevStep && prevStep.formatAs,\r\n\t\t\t\t\t{ round }\r\n\t\t\t\t)\r\n\t\t\t}\r\n\t\t})\r\n\t}\r\n\t// Evaluate the `test()` function.\r\n\t// `test()` function is deprecated.\r\n\tif (minTime === undefined) {\r\n\t\tif (step.test) {\r\n\t\t\tif (step.test(timestamp, {\r\n\t\t\t\tnow,\r\n\t\t\t\tfuture\r\n\t\t\t})) {\r\n\t\t\t\t// `0` threshold always passes.\r\n\t\t\t\tminTime = 0\r\n\t\t\t} else {\r\n\t\t\t\t// `MAX_SAFE_INTEGER` threshold won't ever pass in real life.\r\n\t\t\t\tminTime = 9007199254740991 // Number.MAX_SAFE_INTEGER\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (minTime === undefined) {\r\n\t\tif (prevStep) {\r\n\t\t\tif (step.formatAs && prevStep.formatAs) {\r\n\t\t\t\tminTime = getMinTimeForUnit(step.formatAs, prevStep.formatAs, { round })\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\t// The first step's `minTime` is `0` by default.\r\n\t\t\tminTime = 0\r\n\t\t}\r\n\t}\r\n\t// Warn if no `minTime` was defined or could be deduced.\r\n\tif (minTime === undefined) {\r\n\t\tconsole.warn('[javascript-time-ago] A step should specify `minTime`:\\n' + JSON.stringify(step, null, 2))\r\n\t}\r\n\treturn minTime\r\n}\r\n\r\nfunction getMinTimeForUnit(toUnit, fromUnit, { round }) {\r\n\tconst toUnitAmount = getSecondsInUnit(toUnit)\r\n\t// if (!fromUnit) {\r\n\t// \treturn toUnitAmount;\r\n\t// }\r\n\t// if (!fromUnit) {\r\n\t// \tfromUnit = getPreviousUnitFor(toUnit)\r\n\t// }\r\n\tlet fromUnitAmount\r\n\tif (fromUnit === 'now') {\r\n\t\tfromUnitAmount = getSecondsInUnit(toUnit)\r\n\t} else {\r\n\t\tfromUnitAmount = getSecondsInUnit(fromUnit)\r\n\t}\r\n\tif (toUnitAmount !== undefined && fromUnitAmount !== undefined) {\r\n\t\treturn toUnitAmount - fromUnitAmount * (1 - getDiffRatioToNextRoundedNumber(round))\r\n\t}\r\n}"],"mappings":";AAAA,SAASA,gBAAgB,QAAQ,YAAY;AAC7C,SAASC,+BAA+B,QAAQ,aAAa;AAE7D,eAAe,SAASC,cAAcA,CAACC,IAAI,EAAAC,IAAA,EAOxC;EAAA,IANFC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IACRC,SAAS,GAAAF,IAAA,CAATE,SAAS;IAETC,GAAG,GAAAH,IAAA,CAAHG,GAAG;IACHC,MAAM,GAAAJ,IAAA,CAANI,MAAM;IACNC,KAAK,GAAAL,IAAA,CAALK,KAAK;EAEL,IAAIC,OAAO;EACX;EACA,IAAIL,QAAQ,EAAE;IACb,IAAIA,QAAQ,CAACM,EAAE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AACD","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStepMinTime.test.js","names":["getStepMinTime","describe","it","test","prevStep","minTime","should","equal"],"sources":["../../source/steps/getStepMinTime.test.js"],"sourcesContent":["import getStepMinTime from './getStepMinTime.js'\r\n\r\ndescribe('getStepMinTime', () => {\r\n\tit('should support `step.test()` function (returns true)', () => {\r\n\t\tgetStepMinTime({\r\n\t\t\ttest: () => true\r\n\t\t}, {\r\n\t\t\tprevStep: { minTime: 1 }\r\n\t\t}).should.equal(0)\r\n\t})\r\n\r\n\tit('should support `step.test()` function (returns false)', () => {\r\n\t\tgetStepMinTime({\r\n\t\t\ttest: () => false\r\n\t\t}, {\r\n\t\t\tprevStep: { minTime: 1 }\r\n\t\t}).should.equal(9007199254740991)\r\n\t})\r\n})"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"getStepMinTime.test.js","names":["getStepMinTime","describe","it","test","prevStep","minTime","should","equal"],"sources":["../../source/steps/getStepMinTime.test.js"],"sourcesContent":["import getStepMinTime from './getStepMinTime.js'\r\n\r\ndescribe('getStepMinTime', () => {\r\n\tit('should support `step.test()` function (returns true)', () => {\r\n\t\tgetStepMinTime({\r\n\t\t\ttest: () => true\r\n\t\t}, {\r\n\t\t\tprevStep: { minTime: 1 }\r\n\t\t}).should.equal(0)\r\n\t})\r\n\r\n\tit('should support `step.test()` function (returns false)', () => {\r\n\t\tgetStepMinTime({\r\n\t\t\ttest: () => false\r\n\t\t}, {\r\n\t\t\tprevStep: { minTime: 1 }\r\n\t\t}).should.equal(9007199254740991)\r\n\t})\r\n})"],"mappings":"AAAA,OAAOA,cAAc,MAAM,qBAAqB;AAEhDC,QAAQ,CAAC,gBAAgB,EAAE,YAAM;EAChCC,EAAE,CAAC,sDAAsD,EAAE,YAAM;IAChEF,cAAc,CAAC;MACdG,IAAI,EAAE,SAAAA,KAAA;QAAA,OAAM,IAAI;MAAA;IACjB,CAAC,EAAE;MACFC,QAAQ,EAAE;QAAEC,OAAO,EAAE;MAAE;IACxB,CAAC,CAAC,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC;EACnB,CAAC,CAAC;EAEFL,EAAE,CAAC,uDAAuD,EAAE,YAAM;IACjEF,cAAc,CAAC;MACdG,IAAI,EAAE,SAAAA,KAAA;QAAA,OAAM,KAAK;MAAA;IAClB,CAAC,EAAE;MACFC,QAAQ,EAAE;QAAEC,OAAO,EAAE;MAAE;IACxB,CAAC,CAAC,CAACC,MAAM,CAACC,KAAK,CAAC,gBAAgB,CAAC;EAClC,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import _getTimeToNextUpdateForUnit from './getTimeToNextUpdateForUnit.js';
|
|
2
2
|
import getStepMinTime from './getStepMinTime.js';
|
|
3
|
-
import { getRoundFunction } from '../round.js';
|
|
3
|
+
import { getRoundFunction } from '../round.js';
|
|
4
4
|
|
|
5
|
+
// A thousand years is practically a metaphor for "infinity".
|
|
5
6
|
var YEAR = 365 * 24 * 60 * 60 * 1000;
|
|
6
7
|
export var INFINITY = 1000 * YEAR;
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Gets the time to next update for a date and a step.
|
|
9
11
|
* @param {number} date — The date passed to `.format()`, converted to a timestamp.
|
|
@@ -15,21 +17,21 @@ export var INFINITY = 1000 * YEAR;
|
|
|
15
17
|
* @param {string} [options.round] - (undocumented) Rounding mechanism.
|
|
16
18
|
* @return {number} [timeToNextUpdate]
|
|
17
19
|
*/
|
|
18
|
-
|
|
19
20
|
export default function getTimeToNextUpdate(date, step, _ref) {
|
|
20
21
|
var prevStep = _ref.prevStep,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
nextStep = _ref.nextStep,
|
|
23
|
+
now = _ref.now,
|
|
24
|
+
future = _ref.future,
|
|
25
|
+
round = _ref.round;
|
|
25
26
|
var timestamp = date.getTime ? date.getTime() : date;
|
|
26
|
-
|
|
27
27
|
var getTimeToNextUpdateForUnit = function getTimeToNextUpdateForUnit(unit) {
|
|
28
28
|
return _getTimeToNextUpdateForUnit(unit, timestamp, {
|
|
29
29
|
now: now,
|
|
30
30
|
round: round
|
|
31
31
|
});
|
|
32
|
-
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// For future dates, steps move from the last one to the first one,
|
|
33
35
|
// while for past dates, steps move from the first one to the last one,
|
|
34
36
|
// due to the fact that time flows in one direction,
|
|
35
37
|
// and future dates' interval naturally becomes smaller
|
|
@@ -43,24 +45,19 @@ export default function getTimeToNextUpdate(date, step, _ref) {
|
|
|
43
45
|
// from the current step to the next step,
|
|
44
46
|
// therefore check the `minTime` of the next step.
|
|
45
47
|
//
|
|
46
|
-
|
|
47
|
-
|
|
48
48
|
var timeToStepChange = getTimeToStepChange(future ? step : nextStep, timestamp, {
|
|
49
49
|
future: future,
|
|
50
50
|
now: now,
|
|
51
51
|
round: round,
|
|
52
|
-
prevStep: future ? prevStep : step
|
|
53
|
-
|
|
52
|
+
prevStep: future ? prevStep : step
|
|
53
|
+
// isFirstStep: future && isFirstStep
|
|
54
54
|
});
|
|
55
|
-
|
|
56
55
|
if (timeToStepChange === undefined) {
|
|
57
56
|
// Can't reliably determine "time to next update"
|
|
58
57
|
// if not all of the steps provide `minTime`.
|
|
59
58
|
return;
|
|
60
59
|
}
|
|
61
|
-
|
|
62
60
|
var timeToNextUpdate;
|
|
63
|
-
|
|
64
61
|
if (step) {
|
|
65
62
|
if (step.getTimeToNextUpdate) {
|
|
66
63
|
timeToNextUpdate = step.getTimeToNextUpdate(timestamp, {
|
|
@@ -71,11 +68,9 @@ export default function getTimeToNextUpdate(date, step, _ref) {
|
|
|
71
68
|
round: round
|
|
72
69
|
});
|
|
73
70
|
}
|
|
74
|
-
|
|
75
71
|
if (timeToNextUpdate === undefined) {
|
|
76
72
|
// "unit" is now called "formatAs".
|
|
77
73
|
var unit = step.unit || step.formatAs;
|
|
78
|
-
|
|
79
74
|
if (unit) {
|
|
80
75
|
// For some units, like "now", there's no defined amount of seconds in them.
|
|
81
76
|
// In such cases, `getTimeToNextUpdateForUnit()` returns `undefined`,
|
|
@@ -85,18 +80,16 @@ export default function getTimeToNextUpdate(date, step, _ref) {
|
|
|
85
80
|
}
|
|
86
81
|
}
|
|
87
82
|
}
|
|
88
|
-
|
|
89
83
|
if (timeToNextUpdate === undefined) {
|
|
90
84
|
return timeToStepChange;
|
|
91
85
|
}
|
|
92
|
-
|
|
93
86
|
return Math.min(timeToNextUpdate, timeToStepChange);
|
|
94
87
|
}
|
|
95
88
|
export function getStepChangesAt(currentOrNextStep, timestamp, _ref2) {
|
|
96
89
|
var now = _ref2.now,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
90
|
+
future = _ref2.future,
|
|
91
|
+
round = _ref2.round,
|
|
92
|
+
prevStep = _ref2.prevStep;
|
|
100
93
|
// The first step's `minTime` is `0` by default.
|
|
101
94
|
// It doesn't "change" steps at zero point
|
|
102
95
|
// but it does change the wording when switching
|
|
@@ -109,11 +102,9 @@ export function getStepChangesAt(currentOrNextStep, timestamp, _ref2) {
|
|
|
109
102
|
round: round,
|
|
110
103
|
prevStep: prevStep
|
|
111
104
|
});
|
|
112
|
-
|
|
113
105
|
if (minTime === undefined) {
|
|
114
106
|
return;
|
|
115
107
|
}
|
|
116
|
-
|
|
117
108
|
if (future) {
|
|
118
109
|
// The step changes to the previous step
|
|
119
110
|
// as soon as `timestamp - now` becomes
|
|
@@ -127,20 +118,19 @@ export function getStepChangesAt(currentOrNextStep, timestamp, _ref2) {
|
|
|
127
118
|
// equal to `minTime` of the next step:
|
|
128
119
|
// `now - timestamp === minTime`
|
|
129
120
|
// => `now === timestamp + minTime`.
|
|
121
|
+
|
|
130
122
|
// This is a special case when double-update could be skipped.
|
|
131
123
|
if (minTime === 0 && timestamp === now) {
|
|
132
124
|
return INFINITY;
|
|
133
125
|
}
|
|
134
|
-
|
|
135
126
|
return timestamp + minTime * 1000;
|
|
136
127
|
}
|
|
137
128
|
}
|
|
138
129
|
export function getTimeToStepChange(step, timestamp, _ref3) {
|
|
139
130
|
var now = _ref3.now,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
131
|
+
future = _ref3.future,
|
|
132
|
+
round = _ref3.round,
|
|
133
|
+
prevStep = _ref3.prevStep;
|
|
144
134
|
if (step) {
|
|
145
135
|
var stepChangesAt = getStepChangesAt(step, timestamp, {
|
|
146
136
|
now: now,
|
|
@@ -148,11 +138,9 @@ export function getTimeToStepChange(step, timestamp, _ref3) {
|
|
|
148
138
|
round: round,
|
|
149
139
|
prevStep: prevStep
|
|
150
140
|
});
|
|
151
|
-
|
|
152
141
|
if (stepChangesAt === undefined) {
|
|
153
142
|
return;
|
|
154
143
|
}
|
|
155
|
-
|
|
156
144
|
return stepChangesAt - now;
|
|
157
145
|
} else {
|
|
158
146
|
if (future) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTimeToNextUpdate.js","names":["_getTimeToNextUpdateForUnit","getStepMinTime","getRoundFunction","YEAR","INFINITY","getTimeToNextUpdate","date","step","prevStep","nextStep","now","future","round","timestamp","getTime","getTimeToNextUpdateForUnit","unit","timeToStepChange","getTimeToStepChange","undefined","timeToNextUpdate","formatAs","Math","min","getStepChangesAt","currentOrNextStep","minTime","stepChangesAt"],"sources":["../../source/steps/getTimeToNextUpdate.js"],"sourcesContent":["import _getTimeToNextUpdateForUnit from './getTimeToNextUpdateForUnit.js'\r\nimport getStepMinTime from './getStepMinTime.js'\r\nimport { getRoundFunction } from '../round.js'\r\n\r\n// A thousand years is practically a metaphor for \"infinity\".\r\nconst YEAR = 365 * 24 * 60 * 60 * 1000\r\nexport const INFINITY = 1000 * YEAR\r\n\r\n/**\r\n * Gets the time to next update for a date and a step.\r\n * @param {number} date — The date passed to `.format()`, converted to a timestamp.\r\n * @param {object} step\r\n * @param {object} [options.previousStep]\r\n * @param {object} [options.nextStep]\r\n * @param {number} options.now\r\n * @param {boolean} options.future\r\n * @param {string} [options.round] - (undocumented) Rounding mechanism.\r\n * @return {number} [timeToNextUpdate]\r\n */\r\nexport default function getTimeToNextUpdate(date, step, { prevStep, nextStep, now, future, round }) {\r\n\tconst timestamp = date.getTime ? date.getTime() : date\r\n\r\n\tconst getTimeToNextUpdateForUnit = (unit) => _getTimeToNextUpdateForUnit(unit, timestamp, { now, round })\r\n\r\n\t// For future dates, steps move from the last one to the first one,\r\n\t// while for past dates, steps move from the first one to the last one,\r\n\t// due to the fact that time flows in one direction,\r\n\t// and future dates' interval naturally becomes smaller\r\n\t// while past dates' interval naturally grows larger.\r\n\t//\r\n\t// For future dates, it's the transition\r\n\t// from the current step to the previous step,\r\n\t// therefore check the `minTime` of the current step.\r\n\t//\r\n\t// For past dates, it's the transition\r\n\t// from the current step to the next step,\r\n\t// therefore check the `minTime` of the next step.\r\n\t//\r\n\tconst timeToStepChange = getTimeToStepChange(future ? step : nextStep, timestamp, {\r\n\t\tfuture,\r\n\t\tnow,\r\n\t\tround,\r\n\t\tprevStep: future ? prevStep : step,\r\n\t\t// isFirstStep: future && isFirstStep\r\n\t})\r\n\r\n\tif (timeToStepChange === undefined) {\r\n\t\t// Can't reliably determine \"time to next update\"\r\n\t\t// if not all of the steps provide `minTime`.\r\n\t\treturn\r\n\t}\r\n\r\n\tlet timeToNextUpdate\r\n\r\n\tif (step) {\r\n\t\tif (step.getTimeToNextUpdate) {\r\n\t\t\ttimeToNextUpdate = step.getTimeToNextUpdate(timestamp, {\r\n\t\t\t\tgetTimeToNextUpdateForUnit,\r\n\t\t\t\tgetRoundFunction,\r\n\t\t\t\tnow,\r\n\t\t\t\tfuture,\r\n\t\t\t\tround\r\n\t\t\t})\r\n\t\t}\r\n\r\n\t\tif (timeToNextUpdate === undefined) {\r\n\t\t\t// \"unit\" is now called \"formatAs\".\r\n\t\t\tconst unit = step.unit || step.formatAs\r\n\t\t\tif (unit) {\r\n\t\t\t\t// For some units, like \"now\", there's no defined amount of seconds in them.\r\n\t\t\t\t// In such cases, `getTimeToNextUpdateForUnit()` returns `undefined`,\r\n\t\t\t\t// and the next step's `minTime` could be used to calculate the update interval:\r\n\t\t\t\t// it will just assume that the label never changes for this step.\r\n\t\t\t\ttimeToNextUpdate = getTimeToNextUpdateForUnit(unit)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tif (timeToNextUpdate === undefined) {\r\n\t\treturn timeToStepChange\r\n\t}\r\n\r\n\treturn Math.min(timeToNextUpdate, timeToStepChange)\r\n}\r\n\r\nexport function getStepChangesAt(currentOrNextStep, timestamp, { now, future, round, prevStep }) {\r\n\t// The first step's `minTime` is `0` by default.\r\n\t// It doesn't \"change\" steps at zero point\r\n\t// but it does change the wording when switching\r\n\t// from \"future\" to \"past\": \"in ...\" -> \"... ago\".\r\n\t// Therefore, the label should be updated at zero-point too.\r\n\tconst minTime = getStepMinTime(currentOrNextStep, { timestamp, now, future, round, prevStep })\r\n\tif (minTime === undefined) {\r\n\t\treturn\r\n\t}\r\n\tif (future) {\r\n\t\t// The step changes to the previous step\r\n\t\t// as soon as `timestamp - now` becomes\r\n\t\t// less than the `minTime` of the current step:\r\n\t\t// `timestamp - now === minTime - 1`\r\n\t\t// => `now === timestamp - minTime + 1`.\r\n\t\treturn timestamp - minTime * 1000 + 1\r\n\t} else {\r\n\t\t// The step changes to the next step\r\n\t\t// as soon as `now - timestamp` becomes\r\n\t\t// equal to `minTime` of the next step:\r\n\t\t// `now - timestamp === minTime`\r\n\t\t// => `now === timestamp + minTime`.\r\n\r\n\t\t// This is a special case when double-update could be skipped.\r\n\t\tif (minTime === 0 && timestamp === now) {\r\n\t\t\treturn INFINITY\r\n\t\t}\r\n\r\n\t\treturn timestamp + minTime * 1000\r\n\t}\r\n}\r\n\r\nexport function getTimeToStepChange(step, timestamp, {\r\n\tnow,\r\n\tfuture,\r\n\tround,\r\n\tprevStep\r\n}) {\r\n\tif (step) {\r\n\t\tconst stepChangesAt = getStepChangesAt(step, timestamp, {\r\n\t\t\tnow,\r\n\t\t\tfuture,\r\n\t\t\tround,\r\n\t\t\tprevStep\r\n\t\t})\r\n\t\tif (stepChangesAt === undefined) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\treturn stepChangesAt - now\r\n\t} else {\r\n\t\tif (future) {\r\n\t\t\t// No step.\r\n\t\t\t// Update right after zero point, when it changes from \"future\" to \"past\".\r\n\t\t\treturn timestamp - now + 1\r\n\t\t} else {\r\n\t\t\t// The last step doesn't ever change when `date` is in the past.\r\n\t\t\treturn INFINITY\r\n\t\t}\r\n\t}\r\n}"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"getTimeToNextUpdate.js","names":["_getTimeToNextUpdateForUnit","getStepMinTime","getRoundFunction","YEAR","INFINITY","getTimeToNextUpdate","date","step","_ref","prevStep","nextStep","now","future","round","timestamp","getTime","getTimeToNextUpdateForUnit","unit","timeToStepChange","getTimeToStepChange","undefined","timeToNextUpdate","formatAs","Math","min","getStepChangesAt","currentOrNextStep","_ref2","minTime","_ref3","stepChangesAt"],"sources":["../../source/steps/getTimeToNextUpdate.js"],"sourcesContent":["import _getTimeToNextUpdateForUnit from './getTimeToNextUpdateForUnit.js'\r\nimport getStepMinTime from './getStepMinTime.js'\r\nimport { getRoundFunction } from '../round.js'\r\n\r\n// A thousand years is practically a metaphor for \"infinity\".\r\nconst YEAR = 365 * 24 * 60 * 60 * 1000\r\nexport const INFINITY = 1000 * YEAR\r\n\r\n/**\r\n * Gets the time to next update for a date and a step.\r\n * @param {number} date — The date passed to `.format()`, converted to a timestamp.\r\n * @param {object} step\r\n * @param {object} [options.previousStep]\r\n * @param {object} [options.nextStep]\r\n * @param {number} options.now\r\n * @param {boolean} options.future\r\n * @param {string} [options.round] - (undocumented) Rounding mechanism.\r\n * @return {number} [timeToNextUpdate]\r\n */\r\nexport default function getTimeToNextUpdate(date, step, { prevStep, nextStep, now, future, round }) {\r\n\tconst timestamp = date.getTime ? date.getTime() : date\r\n\r\n\tconst getTimeToNextUpdateForUnit = (unit) => _getTimeToNextUpdateForUnit(unit, timestamp, { now, round })\r\n\r\n\t// For future dates, steps move from the last one to the first one,\r\n\t// while for past dates, steps move from the first one to the last one,\r\n\t// due to the fact that time flows in one direction,\r\n\t// and future dates' interval naturally becomes smaller\r\n\t// while past dates' interval naturally grows larger.\r\n\t//\r\n\t// For future dates, it's the transition\r\n\t// from the current step to the previous step,\r\n\t// therefore check the `minTime` of the current step.\r\n\t//\r\n\t// For past dates, it's the transition\r\n\t// from the current step to the next step,\r\n\t// therefore check the `minTime` of the next step.\r\n\t//\r\n\tconst timeToStepChange = getTimeToStepChange(future ? step : nextStep, timestamp, {\r\n\t\tfuture,\r\n\t\tnow,\r\n\t\tround,\r\n\t\tprevStep: future ? prevStep : step,\r\n\t\t// isFirstStep: future && isFirstStep\r\n\t})\r\n\r\n\tif (timeToStepChange === undefined) {\r\n\t\t// Can't reliably determine \"time to next update\"\r\n\t\t// if not all of the steps provide `minTime`.\r\n\t\treturn\r\n\t}\r\n\r\n\tlet timeToNextUpdate\r\n\r\n\tif (step) {\r\n\t\tif (step.getTimeToNextUpdate) {\r\n\t\t\ttimeToNextUpdate = step.getTimeToNextUpdate(timestamp, {\r\n\t\t\t\tgetTimeToNextUpdateForUnit,\r\n\t\t\t\tgetRoundFunction,\r\n\t\t\t\tnow,\r\n\t\t\t\tfuture,\r\n\t\t\t\tround\r\n\t\t\t})\r\n\t\t}\r\n\r\n\t\tif (timeToNextUpdate === undefined) {\r\n\t\t\t// \"unit\" is now called \"formatAs\".\r\n\t\t\tconst unit = step.unit || step.formatAs\r\n\t\t\tif (unit) {\r\n\t\t\t\t// For some units, like \"now\", there's no defined amount of seconds in them.\r\n\t\t\t\t// In such cases, `getTimeToNextUpdateForUnit()` returns `undefined`,\r\n\t\t\t\t// and the next step's `minTime` could be used to calculate the update interval:\r\n\t\t\t\t// it will just assume that the label never changes for this step.\r\n\t\t\t\ttimeToNextUpdate = getTimeToNextUpdateForUnit(unit)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tif (timeToNextUpdate === undefined) {\r\n\t\treturn timeToStepChange\r\n\t}\r\n\r\n\treturn Math.min(timeToNextUpdate, timeToStepChange)\r\n}\r\n\r\nexport function getStepChangesAt(currentOrNextStep, timestamp, { now, future, round, prevStep }) {\r\n\t// The first step's `minTime` is `0` by default.\r\n\t// It doesn't \"change\" steps at zero point\r\n\t// but it does change the wording when switching\r\n\t// from \"future\" to \"past\": \"in ...\" -> \"... ago\".\r\n\t// Therefore, the label should be updated at zero-point too.\r\n\tconst minTime = getStepMinTime(currentOrNextStep, { timestamp, now, future, round, prevStep })\r\n\tif (minTime === undefined) {\r\n\t\treturn\r\n\t}\r\n\tif (future) {\r\n\t\t// The step changes to the previous step\r\n\t\t// as soon as `timestamp - now` becomes\r\n\t\t// less than the `minTime` of the current step:\r\n\t\t// `timestamp - now === minTime - 1`\r\n\t\t// => `now === timestamp - minTime + 1`.\r\n\t\treturn timestamp - minTime * 1000 + 1\r\n\t} else {\r\n\t\t// The step changes to the next step\r\n\t\t// as soon as `now - timestamp` becomes\r\n\t\t// equal to `minTime` of the next step:\r\n\t\t// `now - timestamp === minTime`\r\n\t\t// => `now === timestamp + minTime`.\r\n\r\n\t\t// This is a special case when double-update could be skipped.\r\n\t\tif (minTime === 0 && timestamp === now) {\r\n\t\t\treturn INFINITY\r\n\t\t}\r\n\r\n\t\treturn timestamp + minTime * 1000\r\n\t}\r\n}\r\n\r\nexport function getTimeToStepChange(step, timestamp, {\r\n\tnow,\r\n\tfuture,\r\n\tround,\r\n\tprevStep\r\n}) {\r\n\tif (step) {\r\n\t\tconst stepChangesAt = getStepChangesAt(step, timestamp, {\r\n\t\t\tnow,\r\n\t\t\tfuture,\r\n\t\t\tround,\r\n\t\t\tprevStep\r\n\t\t})\r\n\t\tif (stepChangesAt === undefined) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\treturn stepChangesAt - now\r\n\t} else {\r\n\t\tif (future) {\r\n\t\t\t// No step.\r\n\t\t\t// Update right after zero point, when it changes from \"future\" to \"past\".\r\n\t\t\treturn timestamp - now + 1\r\n\t\t} else {\r\n\t\t\t// The last step doesn't ever change when `date` is in the past.\r\n\t\t\treturn INFINITY\r\n\t\t}\r\n\t}\r\n}"],"mappings":"AAAA,OAAOA,2BAA2B,MAAM,iCAAiC;AACzE,OAAOC,cAAc,MAAM,qBAAqB;AAChD,SAASC,gBAAgB,QAAQ,aAAa;;AAE9C;AACA,IAAMC,IAAI,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;AACtC,OAAO,IAAMC,QAAQ,GAAG,IAAI,GAAGD,IAAI;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASE,mBAAmBA,CAACC,IAAI,EAAEC,IAAI,EAAAC,IAAA,EAA8C;EAAA,IAA1CC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;IAAEC,GAAG,GAAAH,IAAA,CAAHG,GAAG;IAAEC,MAAM,GAAAJ,IAAA,CAANI,MAAM;IAAEC,KAAK,GAAAL,IAAA,CAALK,KAAK;EAC/F,IAAMC,SAAS,GAAGR,IAAI,CAACS,OAAO,GAAGT,IAAI,CAACS,OAAO,CAAC,CAAC,GAAGT,IAAI;EAEtD,IAAMU,0BAA0B,GAAG,SAA7BA,0BAA0BA,CAAIC,IAAI;IAAA,OAAKjB,2BAA2B,CAACiB,IAAI,EAAEH,SAAS,EAAE;MAAEH,GAAG,EAAHA,GAAG;MAAEE,KAAK,EAALA;IAAM,CAAC,CAAC;EAAA;;EAEzG;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAMK,gBAAgB,GAAGC,mBAAmB,CAACP,MAAM,GAAGL,IAAI,GAAGG,QAAQ,EAAEI,SA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166
|
now: 0,
|
|
167
167
|
future: false,
|
|
168
168
|
prevStep: undefined
|
|
169
|
-
}).should.equal(INFINITY);
|
|
169
|
+
}).should.equal(INFINITY);
|
|
170
|
+
|
|
171
|
+
// Past.
|
|
170
172
|
// Is at zero point.
|
|
171
173
|
// The next step is seconds.
|
|
172
174
|
// Updates at the next step.
|
|
173
|
-
|
|
174
175
|
getStepChangesAt({
|
|
175
176
|
unit: 'second',
|
|
176
177
|
minTime: 1
|
|
@@ -178,32 +179,35 @@ describe('getStepChangesAt', function () {
|
|
|
178
179
|
now: 0,
|
|
179
180
|
future: false,
|
|
180
181
|
prevStep: {}
|
|
181
|
-
}).should.equal(1 * 1000);
|
|
182
|
+
}).should.equal(1 * 1000);
|
|
183
|
+
|
|
184
|
+
// Future.
|
|
182
185
|
// Inside the first step.
|
|
183
186
|
// Updates after zero point.
|
|
184
|
-
|
|
185
187
|
getStepChangesAt({
|
|
186
188
|
unit: 'now'
|
|
187
189
|
}, 0.9 * 1000, {
|
|
188
190
|
now: 0,
|
|
189
191
|
future: true,
|
|
190
192
|
prevStep: undefined
|
|
191
|
-
}).should.equal(0.9 * 1000 + 1);
|
|
193
|
+
}).should.equal(0.9 * 1000 + 1);
|
|
194
|
+
|
|
195
|
+
// Future.
|
|
192
196
|
// The first step doesn't start at 0.
|
|
193
197
|
// Outside of the first step.
|
|
194
198
|
// Updates right after zero point.
|
|
195
|
-
|
|
196
199
|
getTimeToStepChange(undefined, 0.9 * 1000, {
|
|
197
200
|
now: 0,
|
|
198
201
|
future: true,
|
|
199
202
|
prevStep: undefined
|
|
200
|
-
}).should.equal(0.9 * 1000 + 1);
|
|
203
|
+
}).should.equal(0.9 * 1000 + 1);
|
|
204
|
+
|
|
205
|
+
// Past.
|
|
201
206
|
// The current step is `undefined`.
|
|
202
207
|
// The next step is the first step.
|
|
203
208
|
// The first step doesn't start at 0.
|
|
204
209
|
// Outside of the first step.
|
|
205
210
|
// Updates at entering the first step.
|
|
206
|
-
|
|
207
211
|
getStepChangesAt({
|
|
208
212
|
minTime: 1,
|
|
209
213
|
unit: 'second'
|
|
@@ -211,10 +215,11 @@ describe('getStepChangesAt', function () {
|
|
|
211
215
|
now: 0,
|
|
212
216
|
future: false,
|
|
213
217
|
prevStep: {}
|
|
214
|
-
}).should.equal(0.1 * 1000);
|
|
218
|
+
}).should.equal(0.1 * 1000);
|
|
219
|
+
|
|
220
|
+
// Future.
|
|
215
221
|
// The first step doesn't start at 0.
|
|
216
222
|
// Will output empty string after it exits the current step.
|
|
217
|
-
|
|
218
223
|
getStepChangesAt({
|
|
219
224
|
minTime: 1,
|
|
220
225
|
unit: 'second'
|
|
@@ -222,39 +227,43 @@ describe('getStepChangesAt', function () {
|
|
|
222
227
|
now: 0,
|
|
223
228
|
future: true,
|
|
224
229
|
prevStep: undefined
|
|
225
|
-
}).should.equal(0.1 * 1000 + 1);
|
|
230
|
+
}).should.equal(0.1 * 1000 + 1);
|
|
231
|
+
|
|
232
|
+
// Past.
|
|
226
233
|
// Next step is seconds.
|
|
227
234
|
// The "next" step doesn't have `minTime`,
|
|
228
235
|
// so "time to next update" couldn't be determined.
|
|
229
|
-
|
|
230
236
|
expect(getStepChangesAt({
|
|
231
237
|
unit: 'unknown-time-unit'
|
|
232
238
|
}, 0, {
|
|
233
239
|
now: 0,
|
|
234
240
|
future: false,
|
|
235
241
|
prevStep: {}
|
|
236
|
-
})).to.be.undefined;
|
|
242
|
+
})).to.be.undefined;
|
|
243
|
+
|
|
244
|
+
// Past.
|
|
237
245
|
// No next step.
|
|
238
246
|
// The last step never changes.
|
|
239
|
-
|
|
240
247
|
getTimeToStepChange(undefined, 0, {
|
|
241
248
|
now: 0,
|
|
242
249
|
future: false,
|
|
243
250
|
isFirstStep: undefined
|
|
244
|
-
}).should.equal(INFINITY);
|
|
251
|
+
}).should.equal(INFINITY);
|
|
252
|
+
|
|
253
|
+
// Future.
|
|
245
254
|
// Current step is seconds.
|
|
246
255
|
// Updates after zero point.
|
|
247
|
-
|
|
248
256
|
getStepChangesAt({
|
|
249
257
|
unit: 'second'
|
|
250
258
|
}, 0, {
|
|
251
259
|
now: 0,
|
|
252
260
|
future: true,
|
|
253
261
|
prevStep: undefined
|
|
254
|
-
}).should.equal(1);
|
|
262
|
+
}).should.equal(1);
|
|
263
|
+
|
|
264
|
+
// Past.
|
|
255
265
|
// Next step is minutes.
|
|
256
266
|
// Already at zero point, so no need to update at zero point.
|
|
257
|
-
|
|
258
267
|
getStepChangesAt({
|
|
259
268
|
minTime: 60,
|
|
260
269
|
formatAs: 'minute'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTimeToNextUpdate.test.js","names":["getTimeToNextUpdate","INFINITY","getStepChangesAt","getTimeToStepChange","describe","it","expect","minTime","format","now","future","isFirstStep","to","equal","Date","nextStep","formatAs","be","undefined","should","test","unit","prevStep"],"sources":["../../source/steps/getTimeToNextUpdate.test.js"],"sourcesContent":["import getTimeToNextUpdate, { INFINITY, getStepChangesAt, getTimeToStepChange } from './getTimeToNextUpdate.js'\r\n\r\ndescribe('getTimeToNextUpdate', () => {\r\n\tit('should return infinity when there are no more steps, and it does not format as a unit (past)', () => {\r\n\t\texpect(getTimeToNextUpdate(-4 * 60 * 1000, {\r\n\t\t\tminTime: 59.5,\r\n\t\t\tformat: () => ''\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: true\r\n\t\t})).to.equal(INFINITY)\r\n\t})\r\n\r\n\tit('should support date argument', () => {\r\n\t\texpect(getTimeToNextUpdate(new Date(4 * 60 * 1000), {\r\n\t\t\tminTime: 60\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tisFirstStep: true,\r\n\t\t\tnextStep: {}\r\n\t\t})).to.equal(3 * 60 * 1000 + 1)\r\n\t})\r\n\r\n\tit('should return this step\\'s \"minTime\" timestamp (future)', () => {\r\n\t\texpect(getTimeToNextUpdate(4 * 60 * 1000, {\r\n\t\t\tminTime: 60,\r\n\t\t\tformat: () => ''\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tisFirstStep: true,\r\n\t\t\tnextStep: {\r\n\t\t\t\tformat: () => ''\r\n\t\t\t}\r\n\t\t})).to.equal(3 * 60 * 1000 + 1)\r\n\t})\r\n\r\n\tit('should return undefined when there is a next step and time to next update can not be reliably determined (formatAs) (past)', () => {\r\n\t\texpect(getTimeToNextUpdate(-4 * 60 * 1000, {\r\n\t\t\tminTime: 60,\r\n\t\t\tformatAs: 'minute'\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: true,\r\n\t\t\tnextStep: {\r\n\t\t\t\tformatAs: 'unknown-time-unit'\r\n\t\t\t}\r\n\t\t})).to.be.undefined\r\n\t})\r\n\r\n\tit('should get time to next update (no next step) (past)', () => {\r\n\t\tgetTimeToNextUpdate(-4 * 60 * 1000, {\r\n\t\t\tformatAs: 'minute',\r\n\t\t\tminTime: 59.5\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: true\r\n\t\t}).should.equal(0.5 * 60 * 1000)\r\n\t})\r\n\r\n\tit('should get time to next update (no next step) (future)', () => {\r\n\t\tgetTimeToNextUpdate(4 * 60 * 1000, {\r\n\t\t\tformatAs: 'minute',\r\n\t\t\tminTime: 59.5\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tisFirstStep: true\r\n\t\t}).should.equal(0.5 * 60 * 1000 + 1)\r\n\t})\r\n\r\n\tit('should get time to next update (has prev/next step without `minTime`) (future)', () => {\r\n\t\tgetTimeToNextUpdate(4 * 60 * 1000, {\r\n\t\t\tformatAs: 'minute',\r\n\t\t\tminTime: 59.5\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tisFirstStep: true,\r\n\t\t\tnextStep: {\r\n\t\t\t\tformatAs: 'hour',\r\n\t\t\t\ttest: () => false\r\n\t\t\t}\r\n\t\t}).should.equal(0.5 * 60 * 1000 + 1)\r\n\t})\r\n\r\n\tit('should get time to next update (has `getTimeToNextUpdate`) (past)', () => {\r\n\t\tgetTimeToNextUpdate(-4 * 60 * 1000, {\r\n\t\t\tformatAs: 'minute',\r\n\t\t\tminTime: 59.5,\r\n\t\t\tgetTimeToNextUpdate: () => 0.25 * 60 * 1000\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: true\r\n\t\t}).should.equal(0.25 * 60 * 1000)\r\n\t})\r\n\r\n\tit('should get time to next update (has `getTimeToNextUpdate`) (future)', () => {\r\n\t\tgetTimeToNextUpdate(4 * 60 * 1000, {\r\n\t\t\tformatAs: 'minute',\r\n\t\t\tminTime: 59.5,\r\n\t\t\tgetTimeToNextUpdate: () => 0.25 * 60 * 1000\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tisFirstStep: true\r\n\t\t}).should.equal(0.25 * 60 * 1000)\r\n\t})\r\n\r\n\tit('should get time to next update (has both unit and prev/next steps with `minTime`) (returns time to \"minTime\" of next step) (past)', () => {\r\n\t\tgetTimeToNextUpdate(-59 * 60 * 1000, {\r\n\t\t\tformatAs: 'minute',\r\n\t\t\tminTime: 59.5\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: true,\r\n\t\t\tnextStep: {\r\n\t\t\t\tformatAs: 'hour',\r\n\t\t\t\tminTime: 59.5 * 60\r\n\t\t\t}\r\n\t\t}).should.equal(0.5 * 60 * 1000)\r\n\t})\r\n\r\n\tit('should get time to next update (has no unit but has prev/next step with `minTime`) (returns time to \"minTime\" of next step) (past)', () => {\r\n\t\tgetTimeToNextUpdate(-59 * 60 * 1000, {\r\n\t\t\tformat: () => {},\r\n\t\t\tminTime: 59.5\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: true,\r\n\t\t\tnextStep: {\r\n\t\t\t\tformatAs: 'hour',\r\n\t\t\t\tminTime: 59.5 * 60\r\n\t\t\t}\r\n\t\t}).should.equal(0.5 * 60 * 1000)\r\n\t})\r\n\r\n\tit('should get time to next update (will be outside of the first step) (future)', () => {\r\n\t\tgetTimeToNextUpdate(60 * 60 * 1000, {\r\n\t\t\tformatAs: 'hour',\r\n\t\t\tminTime: 60 * 60\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tisFirstStep: true\r\n\t\t}).should.equal(1)\r\n\t})\r\n})\r\n\r\ndescribe('getStepChangesAt', () => {\r\n\tit('should work for \"round\" steps', () => {\r\n\t\t// Future.\r\n\t\t// Is at zero point.\r\n\t\t// No next step.\r\n\t\t// No tickable unit.\r\n\t\t// Doesn't update.\r\n\t\tgetStepChangesAt({\r\n\t\t\tunit: 'now'\r\n\t\t}, 0, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tprevStep: undefined\r\n\t\t}).should.equal(INFINITY)\r\n\r\n\t\t// Past.\r\n\t\t// Is at zero point.\r\n\t\t// The next step is seconds.\r\n\t\t// Updates at the next step.\r\n\t\tgetStepChangesAt({\r\n\t\t\tunit: 'second',\r\n\t\t\tminTime: 1\r\n\t\t}, 0, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tprevStep: {}\r\n\t\t}).should.equal(1 * 1000)\r\n\r\n\t\t// Future.\r\n\t\t// Inside the first step.\r\n\t\t// Updates after zero point.\r\n\t\tgetStepChangesAt({\r\n\t\t\tunit: 'now'\r\n\t\t}, 0.9 * 1000, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tprevStep: undefined\r\n\t\t}).should.equal(0.9 * 1000 + 1)\r\n\r\n\t\t// Future.\r\n\t\t// The first step doesn't start at 0.\r\n\t\t// Outside of the first step.\r\n\t\t// Updates right after zero point.\r\n\t\tgetTimeToStepChange(undefined, 0.9 * 1000, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tprevStep: undefined\r\n\t\t}).should.equal(0.9 * 1000 + 1)\r\n\r\n\t\t// Past.\r\n\t\t// The current step is `undefined`.\r\n\t\t// The next step is the first step.\r\n\t\t// The first step doesn't start at 0.\r\n\t\t// Outside of the first step.\r\n\t\t// Updates at entering the first step.\r\n\t\tgetStepChangesAt({\r\n\t\t\tminTime: 1,\r\n\t\t\tunit: 'second'\r\n\t\t}, -0.9 * 1000, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tprevStep: {}\r\n\t\t}).should.equal(0.1 * 1000)\r\n\r\n\t\t// Future.\r\n\t\t// The first step doesn't start at 0.\r\n\t\t// Will output empty string after it exits the current step.\r\n\t\tgetStepChangesAt({\r\n\t\t\tminTime: 1,\r\n\t\t\tunit: 'second'\r\n\t\t}, 1.1 * 1000, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tprevStep: undefined\r\n\t\t}).should.equal(0.1 * 1000 + 1)\r\n\r\n\t\t// Past.\r\n\t\t// Next step is seconds.\r\n\t\t// The \"next\" step doesn't have `minTime`,\r\n\t\t// so \"time to next update\" couldn't be determined.\r\n\t\texpect(getStepChangesAt({\r\n\t\t\tunit: 'unknown-time-unit'\r\n\t\t}, 0, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tprevStep: {}\r\n\t\t})).to.be.undefined\r\n\r\n\t\t// Past.\r\n\t\t// No next step.\r\n\t\t// The last step never changes.\r\n\t\tgetTimeToStepChange(undefined, 0, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: undefined\r\n\t\t}).should.equal(INFINITY)\r\n\r\n\t\t// Future.\r\n\t\t// Current step is seconds.\r\n\t\t// Updates after zero point.\r\n\t\tgetStepChangesAt({\r\n\t\t\tunit: 'second'\r\n\t\t}, 0, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tprevStep: undefined\r\n\t\t}).should.equal(1)\r\n\r\n\t\t// Past.\r\n\t\t// Next step is minutes.\r\n\t\t// Already at zero point, so no need to update at zero point.\r\n\t\tgetStepChangesAt({\r\n\t\t\tminTime: 60,\r\n\t\t\tformatAs: 'minute'\r\n\t\t}, 0, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tprevStep: {}\r\n\t\t}).should.equal(60 * 1000)\r\n\t})\r\n})"],"mappings":"AAAA,OAAOA,mBAAP,IAA8BC,QAA9B,EAAwCC,gBAAxC,EAA0DC,mBAA1D,QAAqF,0BAArF;AAEAC,QAAQ,CAAC,qBAAD,EAAwB,YAAM;EACrCC,EAAE,CAAC,8FAAD,EAAiG,YAAM;IACxGC,MAAM,CAACN,mBAAmB,CAAC,CAAC,CAAD,GAAK,EAAL,GAAU,IAAX,EAAiB;MAC1CO,OAAO,EAAE,IADiC;MAE1CC,MAAM,EAAE;QAAA,OAAM,EAAN;MAAA;IAFkC,CAAjB,EAGvB;MACFC,GAAG,EAAE,CADH;MAEFC,MAAM,EAAE,KAFN;MAGFC,WAAW,EAAE;IAHX,CAHuB,CAApB,CAAN,CAOIC,EAPJ,CAOOC,KAPP,CAOaZ,QAPb;EAQA,CATC,CAAF;EAWAI,EAAE,CAAC,8BAAD,EAAiC,YAAM;IACxCC,MAAM,CAACN,mBAAmB,CAAC,IAAIc,IAAJ,CAAS,IAAI,EAAJ,GAAS,IAAlB,CAAD,EAA0B;MACnDP,OAAO,EAAE;IAD0C,CAA1B,EAEvB;MACFE,GAAG,EAAE,CADH;MAEFC,MAAM,EAAE,IAFN;MAGFC,WAAW,EAAE,IAHX;MAIFI,QAAQ,EAAE;IAJR,CAFuB,CAApB,CAAN,CAOIH,EAPJ,CAOOC,KAPP,CAOa,IAAI,EAAJ,GAAS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EAAE;IADU,CAAD,EAEb,CAFa,EAEV;MACLZ,GAAG,EAAE,CADA;MAELC,MAAM,EAAE,IAFH;MAGLY,QAAQ,EAAEJ;IAHL,CAFU,CAAhB,CAMGC,MANH,CAMUN,KANV,CAMgB,CANhB,EAnGyC,CA2GzC;IACA;IACA;;IACAX,gBAAgB,CAAC;MAChBK,OAAO,EAAE,EADO;MAEhBS,QAAQ,EAAE;IAFM,CAAD,EAGb,CAHa,EAGV;MACLP,GAAG,EAAE,CADA;MAELC,MAAM,EAAE,KAFH;MAGLY,QAAQ,EAAE;IAHL,CAHU,CAAhB,CAOGH,MAPH,CAOUN,KAPV,CAOgB,KAAK,IAPrB;EAQA,CAtHC,CAAF;AAuHA,CAxHO,CAAR"}
|
|
1
|
+
{"version":3,"file":"getTimeToNextUpdate.test.js","names":["getTimeToNextUpdate","INFINITY","getStepChangesAt","getTimeToStepChange","describe","it","expect","minTime","format","now","future","isFirstStep","to","equal","Date","nextStep","formatAs","be","undefined","should","test","unit","prevStep"],"sources":["../../source/steps/getTimeToNextUpdate.test.js"],"sourcesContent":["import getTimeToNextUpdate, { INFINITY, getStepChangesAt, getTimeToStepChange } from './getTimeToNextUpdate.js'\r\n\r\ndescribe('getTimeToNextUpdate', () => {\r\n\tit('should return infinity when there are no more steps, and it does not format as a unit (past)', () => {\r\n\t\texpect(getTimeToNextUpdate(-4 * 60 * 1000, {\r\n\t\t\tminTime: 59.5,\r\n\t\t\tformat: () => ''\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: true\r\n\t\t})).to.equal(INFINITY)\r\n\t})\r\n\r\n\tit('should support date argument', () => {\r\n\t\texpect(getTimeToNextUpdate(new Date(4 * 60 * 1000), {\r\n\t\t\tminTime: 60\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tisFirstStep: true,\r\n\t\t\tnextStep: {}\r\n\t\t})).to.equal(3 * 60 * 1000 + 1)\r\n\t})\r\n\r\n\tit('should return this step\\'s \"minTime\" timestamp (future)', () => {\r\n\t\texpect(getTimeToNextUpdate(4 * 60 * 1000, {\r\n\t\t\tminTime: 60,\r\n\t\t\tformat: () => ''\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tisFirstStep: true,\r\n\t\t\tnextStep: {\r\n\t\t\t\tformat: () => ''\r\n\t\t\t}\r\n\t\t})).to.equal(3 * 60 * 1000 + 1)\r\n\t})\r\n\r\n\tit('should return undefined when there is a next step and time to next update can not be reliably determined (formatAs) (past)', () => {\r\n\t\texpect(getTimeToNextUpdate(-4 * 60 * 1000, {\r\n\t\t\tminTime: 60,\r\n\t\t\tformatAs: 'minute'\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: true,\r\n\t\t\tnextStep: {\r\n\t\t\t\tformatAs: 'unknown-time-unit'\r\n\t\t\t}\r\n\t\t})).to.be.undefined\r\n\t})\r\n\r\n\tit('should get time to next update (no next step) (past)', () => {\r\n\t\tgetTimeToNextUpdate(-4 * 60 * 1000, {\r\n\t\t\tformatAs: 'minute',\r\n\t\t\tminTime: 59.5\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: true\r\n\t\t}).should.equal(0.5 * 60 * 1000)\r\n\t})\r\n\r\n\tit('should get time to next update (no next step) (future)', () => {\r\n\t\tgetTimeToNextUpdate(4 * 60 * 1000, {\r\n\t\t\tformatAs: 'minute',\r\n\t\t\tminTime: 59.5\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tisFirstStep: true\r\n\t\t}).should.equal(0.5 * 60 * 1000 + 1)\r\n\t})\r\n\r\n\tit('should get time to next update (has prev/next step without `minTime`) (future)', () => {\r\n\t\tgetTimeToNextUpdate(4 * 60 * 1000, {\r\n\t\t\tformatAs: 'minute',\r\n\t\t\tminTime: 59.5\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tisFirstStep: true,\r\n\t\t\tnextStep: {\r\n\t\t\t\tformatAs: 'hour',\r\n\t\t\t\ttest: () => false\r\n\t\t\t}\r\n\t\t}).should.equal(0.5 * 60 * 1000 + 1)\r\n\t})\r\n\r\n\tit('should get time to next update (has `getTimeToNextUpdate`) (past)', () => {\r\n\t\tgetTimeToNextUpdate(-4 * 60 * 1000, {\r\n\t\t\tformatAs: 'minute',\r\n\t\t\tminTime: 59.5,\r\n\t\t\tgetTimeToNextUpdate: () => 0.25 * 60 * 1000\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: true\r\n\t\t}).should.equal(0.25 * 60 * 1000)\r\n\t})\r\n\r\n\tit('should get time to next update (has `getTimeToNextUpdate`) (future)', () => {\r\n\t\tgetTimeToNextUpdate(4 * 60 * 1000, {\r\n\t\t\tformatAs: 'minute',\r\n\t\t\tminTime: 59.5,\r\n\t\t\tgetTimeToNextUpdate: () => 0.25 * 60 * 1000\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tisFirstStep: true\r\n\t\t}).should.equal(0.25 * 60 * 1000)\r\n\t})\r\n\r\n\tit('should get time to next update (has both unit and prev/next steps with `minTime`) (returns time to \"minTime\" of next step) (past)', () => {\r\n\t\tgetTimeToNextUpdate(-59 * 60 * 1000, {\r\n\t\t\tformatAs: 'minute',\r\n\t\t\tminTime: 59.5\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: true,\r\n\t\t\tnextStep: {\r\n\t\t\t\tformatAs: 'hour',\r\n\t\t\t\tminTime: 59.5 * 60\r\n\t\t\t}\r\n\t\t}).should.equal(0.5 * 60 * 1000)\r\n\t})\r\n\r\n\tit('should get time to next update (has no unit but has prev/next step with `minTime`) (returns time to \"minTime\" of next step) (past)', () => {\r\n\t\tgetTimeToNextUpdate(-59 * 60 * 1000, {\r\n\t\t\tformat: () => {},\r\n\t\t\tminTime: 59.5\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: true,\r\n\t\t\tnextStep: {\r\n\t\t\t\tformatAs: 'hour',\r\n\t\t\t\tminTime: 59.5 * 60\r\n\t\t\t}\r\n\t\t}).should.equal(0.5 * 60 * 1000)\r\n\t})\r\n\r\n\tit('should get time to next update (will be outside of the first step) (future)', () => {\r\n\t\tgetTimeToNextUpdate(60 * 60 * 1000, {\r\n\t\t\tformatAs: 'hour',\r\n\t\t\tminTime: 60 * 60\r\n\t\t}, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tisFirstStep: true\r\n\t\t}).should.equal(1)\r\n\t})\r\n})\r\n\r\ndescribe('getStepChangesAt', () => {\r\n\tit('should work for \"round\" steps', () => {\r\n\t\t// Future.\r\n\t\t// Is at zero point.\r\n\t\t// No next step.\r\n\t\t// No tickable unit.\r\n\t\t// Doesn't update.\r\n\t\tgetStepChangesAt({\r\n\t\t\tunit: 'now'\r\n\t\t}, 0, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tprevStep: undefined\r\n\t\t}).should.equal(INFINITY)\r\n\r\n\t\t// Past.\r\n\t\t// Is at zero point.\r\n\t\t// The next step is seconds.\r\n\t\t// Updates at the next step.\r\n\t\tgetStepChangesAt({\r\n\t\t\tunit: 'second',\r\n\t\t\tminTime: 1\r\n\t\t}, 0, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tprevStep: {}\r\n\t\t}).should.equal(1 * 1000)\r\n\r\n\t\t// Future.\r\n\t\t// Inside the first step.\r\n\t\t// Updates after zero point.\r\n\t\tgetStepChangesAt({\r\n\t\t\tunit: 'now'\r\n\t\t}, 0.9 * 1000, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tprevStep: undefined\r\n\t\t}).should.equal(0.9 * 1000 + 1)\r\n\r\n\t\t// Future.\r\n\t\t// The first step doesn't start at 0.\r\n\t\t// Outside of the first step.\r\n\t\t// Updates right after zero point.\r\n\t\tgetTimeToStepChange(undefined, 0.9 * 1000, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tprevStep: undefined\r\n\t\t}).should.equal(0.9 * 1000 + 1)\r\n\r\n\t\t// Past.\r\n\t\t// The current step is `undefined`.\r\n\t\t// The next step is the first step.\r\n\t\t// The first step doesn't start at 0.\r\n\t\t// Outside of the first step.\r\n\t\t// Updates at entering the first step.\r\n\t\tgetStepChangesAt({\r\n\t\t\tminTime: 1,\r\n\t\t\tunit: 'second'\r\n\t\t}, -0.9 * 1000, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tprevStep: {}\r\n\t\t}).should.equal(0.1 * 1000)\r\n\r\n\t\t// Future.\r\n\t\t// The first step doesn't start at 0.\r\n\t\t// Will output empty string after it exits the current step.\r\n\t\tgetStepChangesAt({\r\n\t\t\tminTime: 1,\r\n\t\t\tunit: 'second'\r\n\t\t}, 1.1 * 1000, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tprevStep: undefined\r\n\t\t}).should.equal(0.1 * 1000 + 1)\r\n\r\n\t\t// Past.\r\n\t\t// Next step is seconds.\r\n\t\t// The \"next\" step doesn't have `minTime`,\r\n\t\t// so \"time to next update\" couldn't be determined.\r\n\t\texpect(getStepChangesAt({\r\n\t\t\tunit: 'unknown-time-unit'\r\n\t\t}, 0, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tprevStep: {}\r\n\t\t})).to.be.undefined\r\n\r\n\t\t// Past.\r\n\t\t// No next step.\r\n\t\t// The last step never changes.\r\n\t\tgetTimeToStepChange(undefined, 0, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tisFirstStep: undefined\r\n\t\t}).should.equal(INFINITY)\r\n\r\n\t\t// Future.\r\n\t\t// Current step is seconds.\r\n\t\t// Updates after zero point.\r\n\t\tgetStepChangesAt({\r\n\t\t\tunit: 'second'\r\n\t\t}, 0, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: true,\r\n\t\t\tprevStep: undefined\r\n\t\t}).should.equal(1)\r\n\r\n\t\t// Past.\r\n\t\t// Next step is minutes.\r\n\t\t// Already at zero point, so no need to update at zero point.\r\n\t\tgetStepChangesAt({\r\n\t\t\tminTime: 60,\r\n\t\t\tformatAs: 'minute'\r\n\t\t}, 0, {\r\n\t\t\tnow: 0,\r\n\t\t\tfuture: false,\r\n\t\t\tprevStep: {}\r\n\t\t}).should.equal(60 * 1000)\r\n\t})\r\n})"],"mappings":"AAAA,OAAOA,mBAAmB,IAAIC,QAAQ,EAAEC,gBAAgB,EAAEC,mBAAmB,QAAQ,0BAA0B;AAE/GC,QAAQ,CAAC,qBAAqB,EAAE,YAAM;EACrCC,EAAE,CAAC,8FAA8F,EAAE,YAAM;IACxGC,MAAM,CAACN,mBAAmB,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE;MAC1CO,OAAO,EAAE,IAAI;MACbC,MAAM,EAAE,SAAAA,OAAA;QAAA,OAAM,EAAE;MAAA;IACjB,CAAC,EAAE;MACFC,GAAG,EAAE,CAAC;MACNC,MAAM,EAAE,KAAK;MACbC,WAAW,EAAE;IACd,CAAC,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAACZ,QAAQ,CAAC;EACvB,CAAC,CAAC;EAEFI,EAAE,CAAC,8BAA8B,EAAE,YAAM;IACxCC,MAAM,CAACN,mBAAmB,CAAC,IAAIc,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE;MACnDP,OAAO,EAAE;IACV,CAAC,EAAE;MACFE,GAAG,EAAE,CAAC;MACNC,MAAM,EAAE,IAAI;MACZC,WAAW,EAAE,IAAI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C,MAAM,EAAE,KAAK;MACbC,WAAW,EAAEO;IACd,CAAC,CAAC,CAACC,MAAM,CAACN,KAAK,CAACZ,QAAQ,CAAC;;IAEzB;IACA;IACA;IACAC,gBAAgB,CAAC;MAChBmB,IAAI,EAAE;IACP,CAAC,EAAE,CAAC,EAAE;MACLZ,GAAG,EAAE,CAAC;MACNC,MAAM,EAAE,IAAI;MACZY,QAAQ,EAAEJ;IACX,CAAC,CAAC,CAACC,MAAM,CAACN,KAAK,CAAC,CAAC,CAAC;;IAElB;IACA;IACA;IACAX,gBAAgB,CAAC;MAChBK,OAAO,EAAE,EAAE;MACXS,QAAQ,EAAE;IACX,CAAC,EAAE,CAAC,EAAE;MACLP,GAAG,EAAE,CAAC;MACNC,MAAM,EAAE,KAAK;MACbY,QAAQ,EAAE,CAAC;IACZ,CAAC,CAAC,CAACH,MAAM,CAACN,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC;EAC3B,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getSecondsInUnit } from './units.js';
|
|
2
2
|
import { getRoundFunction, getDiffRatioToNextRoundedNumber } from '../round.js';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Gets the time to next update for a step with a time unit defined.
|
|
5
6
|
* @param {string} unit
|
|
@@ -8,23 +9,19 @@ import { getRoundFunction, getDiffRatioToNextRoundedNumber } from '../round.js';
|
|
|
8
9
|
* @param {string} [options.round] — (undocumented) Rounding mechanism.
|
|
9
10
|
* @return {number} [timeToNextUpdate]
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
12
|
export default function getTimeToNextUpdateForUnit(unit, timestamp, _ref) {
|
|
13
13
|
var now = _ref.now,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
round = _ref.round;
|
|
16
15
|
// For some units, like "now", there's no defined amount of seconds in them.
|
|
17
16
|
if (!getSecondsInUnit(unit)) {
|
|
18
17
|
// If there's no amount of seconds defined for this unit
|
|
19
18
|
// then the update interval can't be determined reliably.
|
|
20
19
|
return;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
var unitDenominator = getSecondsInUnit(unit) * 1000;
|
|
24
22
|
var future = timestamp > now;
|
|
25
23
|
var preciseAmount = Math.abs(timestamp - now);
|
|
26
24
|
var roundedAmount = getRoundFunction(round)(preciseAmount / unitDenominator) * unitDenominator;
|
|
27
|
-
|
|
28
25
|
if (future) {
|
|
29
26
|
if (roundedAmount > 0) {
|
|
30
27
|
// Amount decreases with time.
|
|
@@ -34,16 +31,13 @@ export default function getTimeToNextUpdateForUnit(unit, timestamp, _ref) {
|
|
|
34
31
|
// when "future" changes to "past".
|
|
35
32
|
return preciseAmount - roundedAmount + 1;
|
|
36
33
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
}
|
|
35
|
+
// Amount increases with time.
|
|
40
36
|
return -(preciseAmount - roundedAmount) + getDiffToNextRoundedNumber(round, unitDenominator);
|
|
41
37
|
}
|
|
42
|
-
|
|
43
38
|
function getDiffToNextRoundedNumber(round, unitDenominator) {
|
|
44
39
|
return getDiffRatioToNextRoundedNumber(round) * unitDenominator;
|
|
45
40
|
}
|
|
46
|
-
|
|
47
41
|
function getDiffToPreviousRoundedNumber(round, unitDenominator) {
|
|
48
42
|
return (1 - getDiffRatioToNextRoundedNumber(round)) * unitDenominator + 1;
|
|
49
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTimeToNextUpdateForUnit.js","names":["getSecondsInUnit","getRoundFunction","getDiffRatioToNextRoundedNumber","getTimeToNextUpdateForUnit","unit","timestamp","now","round","unitDenominator","future","preciseAmount","Math","abs","roundedAmount","getDiffToPreviousRoundedNumber","getDiffToNextRoundedNumber"],"sources":["../../source/steps/getTimeToNextUpdateForUnit.js"],"sourcesContent":["import { getSecondsInUnit } from './units.js'\r\nimport { getRoundFunction, getDiffRatioToNextRoundedNumber } from '../round.js'\r\n\r\n/**\r\n * Gets the time to next update for a step with a time unit defined.\r\n * @param {string} unit\r\n * @param {number} date — The date passed to `.format()`, converted to a timestamp.\r\n * @param {number} options.now\r\n * @param {string} [options.round] — (undocumented) Rounding mechanism.\r\n * @return {number} [timeToNextUpdate]\r\n */\r\nexport default function getTimeToNextUpdateForUnit(unit, timestamp, { now, round }) {\r\n\t// For some units, like \"now\", there's no defined amount of seconds in them.\r\n\tif (!getSecondsInUnit(unit)) {\r\n\t\t// If there's no amount of seconds defined for this unit\r\n\t\t// then the update interval can't be determined reliably.\r\n\t\treturn\r\n\t}\r\n\tconst unitDenominator = getSecondsInUnit(unit) * 1000\r\n\tconst future = timestamp > now\r\n\tconst preciseAmount = Math.abs(timestamp - now)\r\n\tconst roundedAmount = getRoundFunction(round)(preciseAmount / unitDenominator) * unitDenominator\r\n\tif (future) {\r\n\t\tif (roundedAmount > 0) {\r\n\t\t\t// Amount decreases with time.\r\n\t\t\treturn (preciseAmount - roundedAmount) +\r\n\t\t\t\tgetDiffToPreviousRoundedNumber(round, unitDenominator)\r\n\t\t} else {\r\n\t\t\t// Refresh right after the zero point,\r\n\t\t\t// when \"future\" changes to \"past\".\r\n\t\t\treturn (preciseAmount - roundedAmount) + 1\r\n\t\t}\r\n\t}\r\n \t// Amount increases with time.\r\n\treturn -(preciseAmount - roundedAmount) + getDiffToNextRoundedNumber(round, unitDenominator)\r\n}\r\n\r\nfunction getDiffToNextRoundedNumber(round, unitDenominator) {\r\n\treturn getDiffRatioToNextRoundedNumber(round) * unitDenominator\r\n}\r\n\r\nfunction getDiffToPreviousRoundedNumber(round, unitDenominator) {\r\n\treturn (1 - getDiffRatioToNextRoundedNumber(round)) * unitDenominator + 1\r\n}"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"file":"getTimeToNextUpdateForUnit.js","names":["getSecondsInUnit","getRoundFunction","getDiffRatioToNextRoundedNumber","getTimeToNextUpdateForUnit","unit","timestamp","_ref","now","round","unitDenominator","future","preciseAmount","Math","abs","roundedAmount","getDiffToPreviousRoundedNumber","getDiffToNextRoundedNumber"],"sources":["../../source/steps/getTimeToNextUpdateForUnit.js"],"sourcesContent":["import { getSecondsInUnit } from './units.js'\r\nimport { getRoundFunction, getDiffRatioToNextRoundedNumber } from '../round.js'\r\n\r\n/**\r\n * Gets the time to next update for a step with a time unit defined.\r\n * @param {string} unit\r\n * @param {number} date — The date passed to `.format()`, converted to a timestamp.\r\n * @param {number} options.now\r\n * @param {string} [options.round] — (undocumented) Rounding mechanism.\r\n * @return {number} [timeToNextUpdate]\r\n */\r\nexport default function getTimeToNextUpdateForUnit(unit, timestamp, { now, round }) {\r\n\t// For some units, like \"now\", there's no defined amount of seconds in them.\r\n\tif (!getSecondsInUnit(unit)) {\r\n\t\t// If there's no amount of seconds defined for this unit\r\n\t\t// then the update interval can't be determined reliably.\r\n\t\treturn\r\n\t}\r\n\tconst unitDenominator = getSecondsInUnit(unit) * 1000\r\n\tconst future = timestamp > now\r\n\tconst preciseAmount = Math.abs(timestamp - now)\r\n\tconst roundedAmount = getRoundFunction(round)(preciseAmount / unitDenominator) * unitDenominator\r\n\tif (future) {\r\n\t\tif (roundedAmount > 0) {\r\n\t\t\t// Amount decreases with time.\r\n\t\t\treturn (preciseAmount - roundedAmount) +\r\n\t\t\t\tgetDiffToPreviousRoundedNumber(round, unitDenominator)\r\n\t\t} else {\r\n\t\t\t// Refresh right after the zero point,\r\n\t\t\t// when \"future\" changes to \"past\".\r\n\t\t\treturn (preciseAmount - roundedAmount) + 1\r\n\t\t}\r\n\t}\r\n \t// Amount increases with time.\r\n\treturn -(preciseAmount - roundedAmount) + getDiffToNextRoundedNumber(round, unitDenominator)\r\n}\r\n\r\nfunction getDiffToNextRoundedNumber(round, unitDenominator) {\r\n\treturn getDiffRatioToNextRoundedNumber(round) * unitDenominator\r\n}\r\n\r\nfunction getDiffToPreviousRoundedNumber(round, unitDenominator) {\r\n\treturn (1 - getDiffRatioToNextRoundedNumber(round)) * unitDenominator + 1\r\n}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AC;AAC1E","ignoreList":[]}
|
|
@@ -17,7 +17,6 @@ describe('getTimeToNextUpdateForUnit', function () {
|
|
|
17
17
|
now: 0
|
|
18
18
|
}).should.equal(expected * 1000 + (addOneMs ? 1 : 0));
|
|
19
19
|
};
|
|
20
|
-
|
|
21
20
|
test(9, 0.5);
|
|
22
21
|
test(9.1, 0.6);
|
|
23
22
|
test(9.4, 0.9);
|
|
@@ -39,7 +38,6 @@ describe('getTimeToNextUpdateForUnit', function () {
|
|
|
39
38
|
now: 0
|
|
40
39
|
}).should.equal(expected * 1000);
|
|
41
40
|
};
|
|
42
|
-
|
|
43
41
|
test(10, 0.5);
|
|
44
42
|
test(9.9, 0.6);
|
|
45
43
|
test(9.5, 1);
|
|
@@ -61,7 +59,6 @@ describe('getTimeToNextUpdateForUnit', function () {
|
|
|
61
59
|
round: 'floor'
|
|
62
60
|
}).should.equal(expected * 1000 + (addOneMs ? 1 : 0));
|
|
63
61
|
};
|
|
64
|
-
|
|
65
62
|
test(9, 0);
|
|
66
63
|
test(9.1, 0.1);
|
|
67
64
|
test(9.4, 0.4);
|
|
@@ -83,7 +80,6 @@ describe('getTimeToNextUpdateForUnit', function () {
|
|
|
83
80
|
round: 'floor'
|
|
84
81
|
}).should.equal(expected * 1000);
|
|
85
82
|
};
|
|
86
|
-
|
|
87
83
|
test(10, 1);
|
|
88
84
|
test(9.9, 0.1);
|
|
89
85
|
test(9.5, 0.5);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTimeToNextUpdateForUnit.test.js","names":["getTimeToNextUpdateForUnit","describe","it","expect","to","be","undefined","Date","now","should","equal","test","seconds","expected","addOneMs","round"],"sources":["../../source/steps/getTimeToNextUpdateForUnit.test.js"],"sourcesContent":["import getTimeToNextUpdateForUnit from './getTimeToNextUpdateForUnit.js'\r\n\r\ndescribe('getTimeToNextUpdateForUnit', () => {\r\n\tit('should return undefined for unknown units', () => {\r\n\t\texpect(getTimeToNextUpdateForUnit('now', 0, {})).to.be.undefined\r\n\t})\r\n\r\n\tit('should support Date argument', () => {\r\n\t\tgetTimeToNextUpdateForUnit('second', new Date(0), {\r\n\t\t\t// future: false,\r\n\t\t\tnow: 0\r\n\t\t}).should.equal(500)\r\n\t})\r\n\r\n\tit('should get time to next update for unit (future)', () => {\r\n\t\tconst test = (seconds, expected, addOneMs = true) => {\r\n\t\t\tgetTimeToNextUpdateForUnit('second', seconds * 1000, {\r\n\t\t\t\t// future: true,\r\n\t\t\t\tnow: 0\r\n\t\t\t}).should.equal(expected * 1000 + (addOneMs ? 1 : 0))\r\n\t\t}\r\n\r\n\t\ttest(9, 0.5)\r\n\t\ttest(9.1, 0.6)\r\n\t\ttest(9.4, 0.9)\r\n\t\ttest(9.5, 0)\r\n\t\ttest(9.9, 0.4)\r\n\t\ttest(10, 0.5)\r\n\r\n\t\ttest(1.1, 0.6)\r\n\t\ttest(1, 0.5)\r\n\t\ttest(0.9, 0.4)\r\n\t\ttest(0.5, 0)\r\n\t\ttest(0.4, 0.4)\r\n\t\ttest(0, 0.5, false)\r\n\t})\r\n\r\n\tit('should get time to next update for unit (past)', () => {\r\n\t\tconst test = (seconds, expected, addOneMs = true) => {\r\n\t\t\tgetTimeToNextUpdateForUnit('second', -1 * seconds * 1000, {\r\n\t\t\t\t// future: false,\r\n\t\t\t\tnow: 0\r\n\t\t\t}).should.equal(expected * 1000)\r\n\t\t}\r\n\r\n\t\ttest(10, 0.5)\r\n\t\ttest(9.9, 0.6)\r\n\t\ttest(9.5, 1)\r\n\t\ttest(9.4, 0.1)\r\n\t\ttest(9.1, 0.4)\r\n\t\ttest(9, 0.5)\r\n\r\n\t\ttest(0, 0.5, false)\r\n\t\ttest(0.5, 1, false)\r\n\t\ttest(0.9, 0.6, false)\r\n\t\ttest(1, 0.5, false)\r\n\t\ttest(1.1, 0.4, false)\r\n\t})\r\n\r\n\tit('should support \"floor\" rounding (future)', () => {\r\n\t\tconst test = (seconds, expected, addOneMs = true) => {\r\n\t\t\tgetTimeToNextUpdateForUnit('second', seconds * 1000, {\r\n\t\t\t\t// future: true,\r\n\t\t\t\tnow: 0,\r\n\t\t\t\tround: 'floor'\r\n\t\t\t}).should.equal(expected * 1000 + (addOneMs ? 1 : 0))\r\n\t\t}\r\n\r\n\t\ttest(9, 0)\r\n\t\ttest(9.1, 0.1)\r\n\t\ttest(9.4, 0.4)\r\n\t\ttest(9.5, 0.5)\r\n\t\ttest(9.9, 0.9)\r\n\t\ttest(10, 0)\r\n\r\n\t\ttest(1.1, 0.1)\r\n\t\ttest(1, 0)\r\n\t\ttest(0.9, 0.9)\r\n\t\ttest(0.5, 0.5)\r\n\t\ttest(0.1, 0.1)\r\n\t\ttest(0, 1, false)\r\n\t})\r\n\r\n\tit('should support \"floor\" rounding (past)', () => {\r\n\t\tconst test = (seconds, expected) => {\r\n\t\t\tgetTimeToNextUpdateForUnit('second', -1 * seconds * 1000, {\r\n\t\t\t\t// future: false,\r\n\t\t\t\tnow: 0,\r\n\t\t\t\tround: 'floor'\r\n\t\t\t}).should.equal(expected * 1000)\r\n\t\t}\r\n\r\n\t\ttest(10, 1)\r\n\t\ttest(9.9, 0.1)\r\n\t\ttest(9.5, 0.5)\r\n\t\ttest(9.4, 0.6)\r\n\t\ttest(9.1, 0.9)\r\n\t\ttest(9, 1)\r\n\r\n\t\ttest(0, 1)\r\n\t\ttest(0.5, 0.5)\r\n\t\ttest(0.9, 0.1)\r\n\t\ttest(1, 1)\r\n\t\ttest(1.1, 0.9)\r\n\t})\r\n})"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"getTimeToNextUpdateForUnit.test.js","names":["getTimeToNextUpdateForUnit","describe","it","expect","to","be","undefined","Date","now","should","equal","test","seconds","expected","addOneMs","arguments","length","round"],"sources":["../../source/steps/getTimeToNextUpdateForUnit.test.js"],"sourcesContent":["import getTimeToNextUpdateForUnit from './getTimeToNextUpdateForUnit.js'\r\n\r\ndescribe('getTimeToNextUpdateForUnit', () => {\r\n\tit('should return undefined for unknown units', () => {\r\n\t\texpect(getTimeToNextUpdateForUnit('now', 0, {})).to.be.undefined\r\n\t})\r\n\r\n\tit('should support Date argument', () => {\r\n\t\tgetTimeToNextUpdateForUnit('second', new Date(0), {\r\n\t\t\t// future: false,\r\n\t\t\tnow: 0\r\n\t\t}).should.equal(500)\r\n\t})\r\n\r\n\tit('should get time to next update for unit (future)', () => {\r\n\t\tconst test = (seconds, expected, addOneMs = true) => {\r\n\t\t\tgetTimeToNextUpdateForUnit('second', seconds * 1000, {\r\n\t\t\t\t// future: true,\r\n\t\t\t\tnow: 0\r\n\t\t\t}).should.equal(expected * 1000 + (addOneMs ? 1 : 0))\r\n\t\t}\r\n\r\n\t\ttest(9, 0.5)\r\n\t\ttest(9.1, 0.6)\r\n\t\ttest(9.4, 0.9)\r\n\t\ttest(9.5, 0)\r\n\t\ttest(9.9, 0.4)\r\n\t\ttest(10, 0.5)\r\n\r\n\t\ttest(1.1, 0.6)\r\n\t\ttest(1, 0.5)\r\n\t\ttest(0.9, 0.4)\r\n\t\ttest(0.5, 0)\r\n\t\ttest(0.4, 0.4)\r\n\t\ttest(0, 0.5, false)\r\n\t})\r\n\r\n\tit('should get time to next update for unit (past)', () => {\r\n\t\tconst test = (seconds, expected, addOneMs = true) => {\r\n\t\t\tgetTimeToNextUpdateForUnit('second', -1 * seconds * 1000, {\r\n\t\t\t\t// future: false,\r\n\t\t\t\tnow: 0\r\n\t\t\t}).should.equal(expected * 1000)\r\n\t\t}\r\n\r\n\t\ttest(10, 0.5)\r\n\t\ttest(9.9, 0.6)\r\n\t\ttest(9.5, 1)\r\n\t\ttest(9.4, 0.1)\r\n\t\ttest(9.1, 0.4)\r\n\t\ttest(9, 0.5)\r\n\r\n\t\ttest(0, 0.5, false)\r\n\t\ttest(0.5, 1, false)\r\n\t\ttest(0.9, 0.6, false)\r\n\t\ttest(1, 0.5, false)\r\n\t\ttest(1.1, 0.4, false)\r\n\t})\r\n\r\n\tit('should support \"floor\" rounding (future)', () => {\r\n\t\tconst test = (seconds, expected, addOneMs = true) => {\r\n\t\t\tgetTimeToNextUpdateForUnit('second', seconds * 1000, {\r\n\t\t\t\t// future: true,\r\n\t\t\t\tnow: 0,\r\n\t\t\t\tround: 'floor'\r\n\t\t\t}).should.equal(expected * 1000 + (addOneMs ? 1 : 0))\r\n\t\t}\r\n\r\n\t\ttest(9, 0)\r\n\t\ttest(9.1, 0.1)\r\n\t\ttest(9.4, 0.4)\r\n\t\ttest(9.5, 0.5)\r\n\t\ttest(9.9, 0.9)\r\n\t\ttest(10, 0)\r\n\r\n\t\ttest(1.1, 0.1)\r\n\t\ttest(1, 0)\r\n\t\ttest(0.9, 0.9)\r\n\t\ttest(0.5, 0.5)\r\n\t\ttest(0.1, 0.1)\r\n\t\ttest(0, 1, false)\r\n\t})\r\n\r\n\tit('should support \"floor\" rounding (past)', () => {\r\n\t\tconst test = (seconds, expected) => {\r\n\t\t\tgetTimeToNextUpdateForUnit('second', -1 * seconds * 1000, {\r\n\t\t\t\t// future: false,\r\n\t\t\t\tnow: 0,\r\n\t\t\t\tround: 'floor'\r\n\t\t\t}).should.equal(expected * 1000)\r\n\t\t}\r\n\r\n\t\ttest(10, 1)\r\n\t\ttest(9.9, 0.1)\r\n\t\ttest(9.5, 0.5)\r\n\t\ttest(9.4, 0.6)\r\n\t\ttest(9.1, 0.9)\r\n\t\ttest(9, 1)\r\n\r\n\t\ttest(0, 1)\r\n\t\ttest(0.5, 0.5)\r\n\t\ttest(0.9, 0.1)\r\n\t\ttest(1, 1)\r\n\t\ttest(1.1, 0.9)\r\n\t})\r\n})"],"mappings":"AAAA,OAAOA,0BAA0B,MAAM,iCAAiC;AAExEC,QAAQ,CAAC,4BAA4B,EAAE,YAAM;EAC5CC,EAAE,CAAC,2CAA2C,EAAE,YAAM;IACrDC,MAAM,CAACH,0BAA0B,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAACI,EAAE,CAACC,EAAE,CAACC,SAAS;EACjE,CA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