javascript-time-ago 2.5.11 → 2.6.0
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/CHANGELOG.md +10 -1
- package/README.md +410 -272
- 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/FullDateFormatter.js +72 -0
- package/commonjs/FullDateFormatter.js.map +1 -0
- package/commonjs/FullDateFormatter.test.js +26 -0
- package/commonjs/FullDateFormatter.test.js.map +1 -0
- 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 +300 -253
- package/commonjs/TimeAgo.js.map +1 -1
- package/commonjs/TimeAgo.test.js +214 -135
- 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 +31 -39
- 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 +27 -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 -39
- package/commonjs/style/twitter.js.map +1 -1
- package/commonjs/style/twitter.test.js +54 -57
- 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/full-date-formatter/index.cjs +4 -0
- package/full-date-formatter/index.cjs.js +9 -0
- package/full-date-formatter/index.d.ts +6 -0
- package/full-date-formatter/index.js +1 -0
- package/full-date-formatter/package.json +15 -0
- package/index.cjs +1 -1
- package/index.cjs.js +2 -2
- package/index.d.ts +14 -4
- package/index.js +3 -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/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/modules/FullDateFormatter.js +67 -0
- package/modules/FullDateFormatter.js.map +1 -0
- package/modules/FullDateFormatter.test.js +22 -0
- package/modules/FullDateFormatter.test.js.map +1 -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 +299 -237
- package/modules/TimeAgo.js.map +1 -1
- package/modules/TimeAgo.test.js +217 -119
- 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 +31 -36
- package/modules/steps/getStepMinTime.js.map +1 -1
- package/modules/steps/getStepMinTime.test.js.map +1 -1
- package/modules/steps/getTimeToNextUpdate.js +28 -32
- 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 +36 -33
- package/modules/style/twitter.js.map +1 -1
- package/modules/style/twitter.test.js +53 -52
- 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 +275 -13
package/modules/TimeAgo.test.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
4
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) { ; } } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
1
7
|
import TimeAgo from './TimeAgo.js';
|
|
2
|
-
import { getLocaleData } from './LocaleDataStore.js';
|
|
8
|
+
import { getLocaleData } from './LocaleDataStore.js';
|
|
3
9
|
|
|
4
|
-
|
|
10
|
+
// Load locale specific relative date/time messages
|
|
11
|
+
import english from '../locale/en.json' assert { type: 'json' };
|
|
5
12
|
|
|
13
|
+
// Just so this function code is covered.
|
|
6
14
|
TimeAgo.setDefaultLocale('en');
|
|
7
15
|
describe("javascript-time-ago", function () {
|
|
8
16
|
it('should default to "round-minute" style', function () {
|
|
@@ -40,8 +48,8 @@ describe("javascript-time-ago", function () {
|
|
|
40
48
|
}, {
|
|
41
49
|
future: true,
|
|
42
50
|
now: 0
|
|
43
|
-
}).should.equal('now');
|
|
44
|
-
|
|
51
|
+
}).should.equal('now');
|
|
52
|
+
// `flavour` is a legacy name of `labels` property.
|
|
45
53
|
timeAgo.format(0, {
|
|
46
54
|
flavour: 'mini'
|
|
47
55
|
}, {
|
|
@@ -61,8 +69,8 @@ describe("javascript-time-ago", function () {
|
|
|
61
69
|
}, {
|
|
62
70
|
future: true,
|
|
63
71
|
now: 0
|
|
64
|
-
}).should.equal('in 0 minutes');
|
|
65
|
-
|
|
72
|
+
}).should.equal('in 0 minutes');
|
|
73
|
+
// `gradation` is a legacy name of `steps` property.
|
|
66
74
|
timeAgo.format(0, {
|
|
67
75
|
gradation: [{
|
|
68
76
|
formatAs: 'minute'
|
|
@@ -135,16 +143,16 @@ describe("javascript-time-ago", function () {
|
|
|
135
143
|
past: '{0} minute(s) ago',
|
|
136
144
|
future: 'in {0} minute(s)'
|
|
137
145
|
};
|
|
138
|
-
TimeAgo.addLocale(english);
|
|
139
|
-
|
|
146
|
+
TimeAgo.addLocale(english);
|
|
147
|
+
// Past.
|
|
140
148
|
timeAgo.format(Date.now() - 60 * 1000, {
|
|
141
149
|
labels: 'long-time'
|
|
142
|
-
}).should.equal('1 minute(s) ago');
|
|
143
|
-
|
|
150
|
+
}).should.equal('1 minute(s) ago');
|
|
151
|
+
// Future (covers an "else" branch).
|
|
144
152
|
timeAgo.format(Date.now() + 60 * 1000, {
|
|
145
153
|
labels: 'long-time'
|
|
146
|
-
}).should.equal('in 1 minute(s)');
|
|
147
|
-
|
|
154
|
+
}).should.equal('in 1 minute(s)');
|
|
155
|
+
// Undo.
|
|
148
156
|
english['long-time'].minute = englishLongTimeMinute;
|
|
149
157
|
timeAgo.format(Date.now() - 60 * 1000, {
|
|
150
158
|
labels: 'long-time'
|
|
@@ -157,43 +165,43 @@ describe("javascript-time-ago", function () {
|
|
|
157
165
|
}).should.equal('in a moment');
|
|
158
166
|
});
|
|
159
167
|
it('should accept a string style name argument', function () {
|
|
160
|
-
var timeAgo = new TimeAgo('en');
|
|
161
|
-
|
|
168
|
+
var timeAgo = new TimeAgo('en');
|
|
169
|
+
// "mini".
|
|
162
170
|
timeAgo.format(Date.now() - 0 * 1000, 'mini').should.equal('0s');
|
|
163
|
-
timeAgo.format(Date.now() - 1 * 1000, 'mini').should.equal('1s');
|
|
164
|
-
|
|
171
|
+
timeAgo.format(Date.now() - 1 * 1000, 'mini').should.equal('1s');
|
|
172
|
+
// "mini-now".
|
|
165
173
|
timeAgo.format(Date.now() - 0 * 1000, 'mini-now').should.equal('now');
|
|
166
|
-
timeAgo.format(Date.now() - 1 * 1000, 'mini-now').should.equal('1s');
|
|
167
|
-
|
|
174
|
+
timeAgo.format(Date.now() - 1 * 1000, 'mini-now').should.equal('1s');
|
|
175
|
+
// "mini-minute-now".
|
|
168
176
|
timeAgo.format(Date.now() - 29 * 1000, 'mini-minute-now').should.equal('now');
|
|
169
|
-
timeAgo.format(Date.now() - 60 * 1000, 'mini-minute-now').should.equal('1m');
|
|
170
|
-
|
|
177
|
+
timeAgo.format(Date.now() - 60 * 1000, 'mini-minute-now').should.equal('1m');
|
|
178
|
+
// "mini-minute".
|
|
171
179
|
timeAgo.format(Date.now() - 29 * 1000, 'mini-minute').should.equal('0m');
|
|
172
|
-
timeAgo.format(Date.now() - 60 * 1000, 'mini-minute').should.equal('1m');
|
|
173
|
-
|
|
180
|
+
timeAgo.format(Date.now() - 60 * 1000, 'mini-minute').should.equal('1m');
|
|
181
|
+
// "twitter".
|
|
174
182
|
timeAgo.format(Date.now() - 0 * 1000, 'twitter').should.equal('0s');
|
|
175
|
-
timeAgo.format(Date.now() - 1 * 1000, 'twitter').should.equal('1s');
|
|
176
|
-
|
|
183
|
+
timeAgo.format(Date.now() - 1 * 1000, 'twitter').should.equal('1s');
|
|
184
|
+
// "twitter-now".
|
|
177
185
|
timeAgo.format(Date.now() - 0 * 1000, 'twitter-now').should.equal('now');
|
|
178
|
-
timeAgo.format(Date.now() - 1 * 1000, 'twitter-now').should.equal('1s');
|
|
179
|
-
|
|
186
|
+
timeAgo.format(Date.now() - 1 * 1000, 'twitter-now').should.equal('1s');
|
|
187
|
+
// "twitter-minute-now".
|
|
180
188
|
timeAgo.format(Date.now() - 29 * 1000, 'twitter-minute-now').should.equal('now');
|
|
181
|
-
timeAgo.format(Date.now() - 60 * 1000, 'twitter-minute-now').should.equal('1m');
|
|
182
|
-
|
|
189
|
+
timeAgo.format(Date.now() - 60 * 1000, 'twitter-minute-now').should.equal('1m');
|
|
190
|
+
// "twitter-minute".
|
|
183
191
|
timeAgo.format(Date.now() - 29 * 1000, 'twitter-minute').should.equal('0m');
|
|
184
|
-
timeAgo.format(Date.now() - 60 * 1000, 'twitter-minute').should.equal('1m');
|
|
185
|
-
|
|
192
|
+
timeAgo.format(Date.now() - 60 * 1000, 'twitter-minute').should.equal('1m');
|
|
193
|
+
// "twitter-first-minute".
|
|
186
194
|
timeAgo.format(Date.now() - 29 * 1000, 'twitter-first-minute').should.equal('');
|
|
187
|
-
timeAgo.format(Date.now() - 60 * 1000, 'twitter-first-minute').should.equal('1m');
|
|
188
|
-
|
|
189
|
-
timeAgo.format(Date.now() - 45 * 1000, 'approximate').should.equal('just now');
|
|
190
|
-
|
|
195
|
+
timeAgo.format(Date.now() - 60 * 1000, 'twitter-first-minute').should.equal('1m');
|
|
196
|
+
// "approximate".
|
|
197
|
+
timeAgo.format(Date.now() - 45 * 1000, 'approximate').should.equal('just now');
|
|
198
|
+
// "convenient" style was renamed to "approximate".
|
|
191
199
|
timeAgo.format(Date.now() - 45 * 1000, 'convenient').should.equal('just now');
|
|
192
|
-
timeAgo.format(Date.now() - 45 * 1000, 'round').should.equal('45 seconds ago');
|
|
193
|
-
|
|
200
|
+
timeAgo.format(Date.now() - 45 * 1000, 'round').should.equal('45 seconds ago');
|
|
201
|
+
// "default" style was renamed to "round".
|
|
194
202
|
timeAgo.format(Date.now() - 45 * 1000, 'default').should.equal('45 seconds ago');
|
|
195
|
-
timeAgo.format(Date.now() - 29 * 1000, 'round-minute').should.equal('just now');
|
|
196
|
-
|
|
203
|
+
timeAgo.format(Date.now() - 29 * 1000, 'round-minute').should.equal('just now');
|
|
204
|
+
// "time" style was renamed to "approximate-time".
|
|
197
205
|
timeAgo.format(Date.now() - 2 * 60 * 1000, 'time').should.equal('2 minutes');
|
|
198
206
|
timeAgo.format(Date.now() - 2 * 60 * 1000, 'approximate-time').should.equal('2 minutes');
|
|
199
207
|
timeAgo.format(Date.now(), 'exotic').should.equal('just now');
|
|
@@ -213,11 +221,9 @@ describe("javascript-time-ago", function () {
|
|
|
213
221
|
});
|
|
214
222
|
it('should not accept anything but Dates and timestamps', function () {
|
|
215
223
|
var timeAgo = new TimeAgo('en');
|
|
216
|
-
|
|
217
224
|
var thrower = function thrower() {
|
|
218
225
|
return timeAgo.format('Jan 14, 2017');
|
|
219
226
|
};
|
|
220
|
-
|
|
221
227
|
thrower.should["throw"]('Unsupported relative time formatter input: string, Jan 14, 2017');
|
|
222
228
|
});
|
|
223
229
|
it('should return an empty string if the specified units are not available in locale data', function () {
|
|
@@ -227,28 +233,45 @@ describe("javascript-time-ago", function () {
|
|
|
227
233
|
}).should.equal('');
|
|
228
234
|
});
|
|
229
235
|
it('should format for a style with "custom" function', function () {
|
|
230
|
-
var timeAgo = new TimeAgo('en');
|
|
231
|
-
|
|
236
|
+
var timeAgo = new TimeAgo('en');
|
|
232
237
|
timeAgo.format(Date.now(), {
|
|
238
|
+
// `custom` returns a string
|
|
233
239
|
custom: function custom(_ref) {
|
|
234
240
|
var now = _ref.now,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
241
|
+
time = _ref.time,
|
|
242
|
+
date = _ref.date,
|
|
243
|
+
locale = _ref.locale;
|
|
238
244
|
return locale;
|
|
239
245
|
}
|
|
240
|
-
}).should.equal('en');
|
|
241
|
-
|
|
246
|
+
}).should.equal('en');
|
|
242
247
|
timeAgo.format(Date.now(), {
|
|
248
|
+
// `custom` returns `undefined`
|
|
243
249
|
custom: function custom(_ref2) {
|
|
244
250
|
var now = _ref2.now,
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
251
|
+
time = _ref2.time,
|
|
252
|
+
date = _ref2.date,
|
|
253
|
+
locale = _ref2.locale;
|
|
248
254
|
return;
|
|
249
255
|
}
|
|
250
256
|
}).should.equal('just now');
|
|
251
257
|
});
|
|
258
|
+
it('should throw an error when formating for a style with "custom" function and `getTimeToNextUpdate: true` parameter is passed', function () {
|
|
259
|
+
var timeAgo = new TimeAgo('en');
|
|
260
|
+
expect(function () {
|
|
261
|
+
timeAgo.format(Date.now(), {
|
|
262
|
+
// `custom` returns a string.
|
|
263
|
+
custom: function custom(_ref3) {
|
|
264
|
+
var now = _ref3.now,
|
|
265
|
+
time = _ref3.time,
|
|
266
|
+
date = _ref3.date,
|
|
267
|
+
locale = _ref3.locale;
|
|
268
|
+
return locale;
|
|
269
|
+
}
|
|
270
|
+
}, {
|
|
271
|
+
getTimeToNextUpdate: true
|
|
272
|
+
});
|
|
273
|
+
}).to["throw"]('not supported');
|
|
274
|
+
});
|
|
252
275
|
it('should format future dates', function () {
|
|
253
276
|
new TimeAgo('en').format(Date.now() + 60 * 60 * 1000).should.equal('in 1 hour');
|
|
254
277
|
new TimeAgo('ru').format(Date.now() + 60 * 1000).should.equal('через 1 минуту');
|
|
@@ -258,7 +281,9 @@ describe("javascript-time-ago", function () {
|
|
|
258
281
|
new TimeAgo('en').format(Date.now()).should.equal('just now');
|
|
259
282
|
new TimeAgo('en').format(Date.now(), 'approximate', {
|
|
260
283
|
future: true
|
|
261
|
-
}).should.equal('in a moment');
|
|
284
|
+
}).should.equal('in a moment');
|
|
285
|
+
|
|
286
|
+
// Non-"now" unit, "long" style.
|
|
262
287
|
// const style = {
|
|
263
288
|
// gradation: [{
|
|
264
289
|
// factor: 1,
|
|
@@ -268,8 +293,8 @@ describe("javascript-time-ago", function () {
|
|
|
268
293
|
// }
|
|
269
294
|
// new TimeAgo('en').format(Date.now(), style).should.equal('0 seconds ago')
|
|
270
295
|
// new TimeAgo('en').format(Date.now(), style, { future: true }).should.equal('in 0 seconds')
|
|
271
|
-
// Non-"now" unit, "mini" style.
|
|
272
296
|
|
|
297
|
+
// Non-"now" unit, "mini" style.
|
|
273
298
|
var style2 = {
|
|
274
299
|
style: [{
|
|
275
300
|
unit: 'year'
|
|
@@ -328,9 +353,65 @@ describe("javascript-time-ago", function () {
|
|
|
328
353
|
}).should.equal('in 0 seconds');
|
|
329
354
|
english['mini'].second = secondLabels;
|
|
330
355
|
});
|
|
356
|
+
it('should refresh the label when `refresh` parameter is passed', function () {
|
|
357
|
+
var refreshedTimes = 0;
|
|
358
|
+
var timeAgo = new TimeAgo('en');
|
|
359
|
+
// in 1 second -> in 0 seconds.
|
|
360
|
+
var _timeAgo$format = timeAgo.format(1000, 'twitter', {
|
|
361
|
+
refresh: function refresh(text) {
|
|
362
|
+
if (refreshedTimes === 0) {
|
|
363
|
+
expect(text).to.equal('0s');
|
|
364
|
+
} else {
|
|
365
|
+
throw new Error('Refresh should have been cancelled');
|
|
366
|
+
}
|
|
367
|
+
refreshedTimes++;
|
|
368
|
+
},
|
|
369
|
+
now: 0,
|
|
370
|
+
round: 'floor'
|
|
371
|
+
}),
|
|
372
|
+
_timeAgo$format2 = _slicedToArray(_timeAgo$format, 2),
|
|
373
|
+
text = _timeAgo$format2[0],
|
|
374
|
+
cancelRefresh = _timeAgo$format2[1];
|
|
375
|
+
expect(text).to.equal('1s');
|
|
376
|
+
expect(cancelRefresh).to.be.a('function');
|
|
377
|
+
// Sidenote: `timeToNextUpdate` is `1`.
|
|
378
|
+
var timeToNextUpdate = 1;
|
|
379
|
+
return delay(timeToNextUpdate + 1).then(function () {
|
|
380
|
+
expect(refreshedTimes).to.equal(1);
|
|
381
|
+
cancelRefresh();
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
it('should get time to next update (capped)', function () {
|
|
385
|
+
var timeAgo = new TimeAgo('en');
|
|
386
|
+
// in 1 second -> in 0 seconds.
|
|
387
|
+
timeAgo.format(0.5 * 365 * 24 * 60 * 60 * 1000, 'twitter', {
|
|
388
|
+
getTimeToNextUpdate: true,
|
|
389
|
+
now: 0,
|
|
390
|
+
round: 'floor'
|
|
391
|
+
}).should.deep.equal(['Jul 2', 2147483647]);
|
|
392
|
+
});
|
|
393
|
+
it('should get time to next update (capped)', function () {
|
|
394
|
+
var timeAgo = new TimeAgo('en');
|
|
395
|
+
// in 1 second -> in 0 seconds.
|
|
396
|
+
timeAgo.format(0.5 * 365 * 24 * 60 * 60 * 1000, 'twitter', {
|
|
397
|
+
getTimeToNextUpdate: true,
|
|
398
|
+
getTimeToNextUpdateUncapped: true,
|
|
399
|
+
now: 0,
|
|
400
|
+
round: 'floor'
|
|
401
|
+
}).should.deep.equal(['Jul 2', 15681600001]);
|
|
402
|
+
});
|
|
403
|
+
it('should get time to next update (uncapped)', function () {
|
|
404
|
+
var timeAgo = new TimeAgo('en');
|
|
405
|
+
// in 1 second -> in 0 seconds.
|
|
406
|
+
timeAgo.format(1000, 'twitter', {
|
|
407
|
+
getTimeToNextUpdate: true,
|
|
408
|
+
now: 0,
|
|
409
|
+
round: 'floor'
|
|
410
|
+
}).should.deep.equal(['1s', 1]);
|
|
411
|
+
});
|
|
331
412
|
it('should get time to next update (round: "floor")', function () {
|
|
332
|
-
var timeAgo = new TimeAgo('en');
|
|
333
|
-
|
|
413
|
+
var timeAgo = new TimeAgo('en');
|
|
414
|
+
// in 1 second -> in 0 seconds.
|
|
334
415
|
timeAgo.format(1000, 'twitter', {
|
|
335
416
|
getTimeToNextUpdate: true,
|
|
336
417
|
now: 0,
|
|
@@ -338,62 +419,63 @@ describe("javascript-time-ago", function () {
|
|
|
338
419
|
}).should.deep.equal(['1s', 1]);
|
|
339
420
|
});
|
|
340
421
|
it('should get time to next update (round: "round")', function () {
|
|
341
|
-
var timeAgo = new TimeAgo('en');
|
|
342
|
-
|
|
422
|
+
var timeAgo = new TimeAgo('en');
|
|
423
|
+
// in 1 second -> in 0 seconds.
|
|
343
424
|
timeAgo.format(1000, 'twitter', {
|
|
344
425
|
getTimeToNextUpdate: true,
|
|
345
426
|
now: 0
|
|
346
427
|
}).should.deep.equal(['1s', 501]);
|
|
347
428
|
});
|
|
348
429
|
it('should get time to next update ("mini-now" style) (round: "floor")', function () {
|
|
349
|
-
var timeAgo = new TimeAgo('en');
|
|
350
|
-
|
|
430
|
+
var timeAgo = new TimeAgo('en');
|
|
431
|
+
// In 1 minute.
|
|
351
432
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
352
433
|
getTimeToNextUpdate: true,
|
|
353
434
|
now: 0,
|
|
354
435
|
round: 'floor'
|
|
355
|
-
}).should.deep.equal(['1m', 1]);
|
|
356
|
-
|
|
436
|
+
}).should.deep.equal(['1m', 1]);
|
|
437
|
+
// Almost in 1 minute.
|
|
357
438
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
358
439
|
getTimeToNextUpdate: true,
|
|
359
440
|
now: 1,
|
|
360
441
|
round: 'floor'
|
|
361
|
-
}).should.deep.equal(['59s', 1000]);
|
|
362
|
-
|
|
442
|
+
}).should.deep.equal(['59s', 1000]);
|
|
443
|
+
// In 1 second.
|
|
363
444
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
364
445
|
getTimeToNextUpdate: true,
|
|
365
446
|
now: 59 * 1000,
|
|
366
447
|
round: 'floor'
|
|
367
|
-
}).should.deep.equal(['1s', 1]);
|
|
368
|
-
|
|
448
|
+
}).should.deep.equal(['1s', 1]);
|
|
449
|
+
// Almost in 1 second.
|
|
369
450
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
370
451
|
getTimeToNextUpdate: true,
|
|
371
452
|
now: 59 * 1000 + 1,
|
|
372
453
|
round: 'floor'
|
|
373
|
-
}).should.deep.equal(['now',
|
|
374
|
-
|
|
454
|
+
}).should.deep.equal(['now',
|
|
455
|
+
// Right after zero point.
|
|
456
|
+
1000]);
|
|
457
|
+
// Zero point (future to past).
|
|
375
458
|
// `future: true`.
|
|
376
|
-
|
|
377
459
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
378
460
|
getTimeToNextUpdate: true,
|
|
379
461
|
now: 60 * 1000,
|
|
380
462
|
future: true,
|
|
381
463
|
round: 'floor'
|
|
382
|
-
}).should.deep.equal(['now', 1]);
|
|
464
|
+
}).should.deep.equal(['now', 1]);
|
|
465
|
+
// Zero point (future to past).
|
|
383
466
|
// `future: false`.
|
|
384
|
-
|
|
385
467
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
386
468
|
getTimeToNextUpdate: true,
|
|
387
469
|
now: 60 * 1000,
|
|
388
470
|
round: 'floor'
|
|
389
|
-
}).should.deep.equal(['now', 1000]);
|
|
390
|
-
|
|
471
|
+
}).should.deep.equal(['now', 1000]);
|
|
472
|
+
// Right after zero point (past).
|
|
391
473
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
392
474
|
getTimeToNextUpdate: true,
|
|
393
475
|
now: 60 * 1000 + 1,
|
|
394
476
|
round: 'floor'
|
|
395
|
-
}).should.deep.equal(['now', 1000 - 1]);
|
|
396
|
-
|
|
477
|
+
}).should.deep.equal(['now', 1000 - 1]);
|
|
478
|
+
// 1 second ago.
|
|
397
479
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
398
480
|
getTimeToNextUpdate: true,
|
|
399
481
|
now: 60 * 1000 + 1000,
|
|
@@ -401,57 +483,59 @@ describe("javascript-time-ago", function () {
|
|
|
401
483
|
}).should.deep.equal(['1s', 1000]);
|
|
402
484
|
});
|
|
403
485
|
it('should get time to next update ("mini-now" style) (round: "round")', function () {
|
|
404
|
-
var timeAgo = new TimeAgo('en');
|
|
405
|
-
|
|
486
|
+
var timeAgo = new TimeAgo('en');
|
|
487
|
+
// In 1 minute.
|
|
406
488
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
407
489
|
getTimeToNextUpdate: true,
|
|
408
490
|
now: 0
|
|
409
|
-
}).should.deep.equal(['1m', 500 + 1]);
|
|
410
|
-
|
|
491
|
+
}).should.deep.equal(['1m', 500 + 1]);
|
|
492
|
+
// Almost in 1 minute.
|
|
411
493
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
412
494
|
getTimeToNextUpdate: true,
|
|
413
495
|
now: 500 + 1
|
|
414
|
-
}).should.deep.equal(['59s', 1000]);
|
|
415
|
-
|
|
496
|
+
}).should.deep.equal(['59s', 1000]);
|
|
497
|
+
// In 1 second.
|
|
416
498
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
417
499
|
getTimeToNextUpdate: true,
|
|
418
500
|
now: 59.5 * 1000
|
|
419
|
-
}).should.deep.equal(['1s', 1]);
|
|
420
|
-
|
|
501
|
+
}).should.deep.equal(['1s', 1]);
|
|
502
|
+
// Almost in 1 second.
|
|
421
503
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
422
504
|
getTimeToNextUpdate: true,
|
|
423
505
|
now: 59.5 * 1000 + 1
|
|
424
|
-
}).should.deep.equal(['now',
|
|
425
|
-
|
|
506
|
+
}).should.deep.equal(['now',
|
|
507
|
+
// Right after zero point.
|
|
508
|
+
500]);
|
|
509
|
+
// Zero point (future to past).
|
|
426
510
|
// `future: true`.
|
|
427
|
-
|
|
428
511
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
429
512
|
getTimeToNextUpdate: true,
|
|
430
513
|
now: 60 * 1000,
|
|
431
514
|
future: true
|
|
432
|
-
}).should.deep.equal(['now', 1]);
|
|
515
|
+
}).should.deep.equal(['now', 1]);
|
|
516
|
+
// Zero point (future to past).
|
|
433
517
|
// `future: false`.
|
|
434
|
-
|
|
435
518
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
436
519
|
getTimeToNextUpdate: true,
|
|
437
520
|
now: 60 * 1000
|
|
438
|
-
}).should.deep.equal(['now', 500]);
|
|
439
|
-
|
|
521
|
+
}).should.deep.equal(['now', 500]);
|
|
522
|
+
// Right after zero point (past).
|
|
440
523
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
441
524
|
getTimeToNextUpdate: true,
|
|
442
525
|
now: 60 * 1000 + 1
|
|
443
|
-
}).should.deep.equal(['now', 500 - 1]);
|
|
444
|
-
|
|
526
|
+
}).should.deep.equal(['now', 500 - 1]);
|
|
527
|
+
// 1 second ago.
|
|
445
528
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
446
529
|
getTimeToNextUpdate: true,
|
|
447
530
|
now: 60 * 1000 + 500
|
|
448
531
|
}).should.deep.equal(['1s', 1000]);
|
|
449
532
|
});
|
|
450
533
|
it('should get time to next update (first step has non-zero "minTime") (round: "floor")', function () {
|
|
451
|
-
var timeAgo = new TimeAgo('en');
|
|
534
|
+
var timeAgo = new TimeAgo('en');
|
|
535
|
+
|
|
536
|
+
// Future.
|
|
452
537
|
// Inside the first step.
|
|
453
538
|
// Updates soon.
|
|
454
|
-
|
|
455
539
|
timeAgo.format(60 * 1000, {
|
|
456
540
|
steps: [{
|
|
457
541
|
formatAs: 'minute',
|
|
@@ -462,10 +546,11 @@ describe("javascript-time-ago", function () {
|
|
|
462
546
|
}, {
|
|
463
547
|
getTimeToNextUpdate: true,
|
|
464
548
|
now: -0.5 * 1000
|
|
465
|
-
}).should.deep.equal(['1m', 0.5 * 1000 + 1]);
|
|
549
|
+
}).should.deep.equal(['1m', 0.5 * 1000 + 1]);
|
|
550
|
+
|
|
551
|
+
// Future.
|
|
466
552
|
// Outside of the first step.
|
|
467
553
|
// Updates right after zero point.
|
|
468
|
-
|
|
469
554
|
timeAgo.format(60 * 1000, {
|
|
470
555
|
steps: [{
|
|
471
556
|
formatAs: 'minute',
|
|
@@ -476,10 +561,11 @@ describe("javascript-time-ago", function () {
|
|
|
476
561
|
}, {
|
|
477
562
|
getTimeToNextUpdate: true,
|
|
478
563
|
now: 1 * 1000
|
|
479
|
-
}).should.deep.equal(['', 59 * 1000 + 1]);
|
|
564
|
+
}).should.deep.equal(['', 59 * 1000 + 1]);
|
|
565
|
+
|
|
566
|
+
// Zero point.
|
|
480
567
|
// Outside of the first step.
|
|
481
568
|
// Updates at the first step's `minTime`.
|
|
482
|
-
|
|
483
569
|
timeAgo.format(60 * 1000, {
|
|
484
570
|
steps: [{
|
|
485
571
|
formatAs: 'minute',
|
|
@@ -490,10 +576,11 @@ describe("javascript-time-ago", function () {
|
|
|
490
576
|
}, {
|
|
491
577
|
getTimeToNextUpdate: true,
|
|
492
578
|
now: 60 * 1000
|
|
493
|
-
}).should.deep.equal(['', 60 * 1000]);
|
|
579
|
+
}).should.deep.equal(['', 60 * 1000]);
|
|
580
|
+
|
|
581
|
+
// Past.
|
|
494
582
|
// Inside the first step.
|
|
495
583
|
// Updates at the next minute.
|
|
496
|
-
|
|
497
584
|
timeAgo.format(60 * 1000, {
|
|
498
585
|
steps: [{
|
|
499
586
|
formatAs: 'minute',
|
|
@@ -504,50 +591,51 @@ describe("javascript-time-ago", function () {
|
|
|
504
591
|
}, {
|
|
505
592
|
getTimeToNextUpdate: true,
|
|
506
593
|
now: 60 * 1000 + 60 * 1000
|
|
507
|
-
}).should.deep.equal(['1m', 60 * 1000]);
|
|
594
|
+
}).should.deep.equal(['1m', 60 * 1000]);
|
|
508
595
|
|
|
596
|
+
// Almost in 1 minute.
|
|
509
597
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
510
598
|
getTimeToNextUpdate: true,
|
|
511
599
|
now: 1,
|
|
512
600
|
round: 'floor'
|
|
513
|
-
}).should.deep.equal(['59s', 1000]);
|
|
514
|
-
|
|
601
|
+
}).should.deep.equal(['59s', 1000]);
|
|
602
|
+
// In 1 second.
|
|
515
603
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
516
604
|
getTimeToNextUpdate: true,
|
|
517
605
|
now: 59 * 1000,
|
|
518
606
|
round: 'floor'
|
|
519
|
-
}).should.deep.equal(['1s', 1]);
|
|
607
|
+
}).should.deep.equal(['1s', 1]);
|
|
608
|
+
// Almost in 1 second.
|
|
520
609
|
// Updates right after the zero point.
|
|
521
|
-
|
|
522
610
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
523
611
|
getTimeToNextUpdate: true,
|
|
524
612
|
now: 59 * 1000 + 1,
|
|
525
613
|
round: 'floor'
|
|
526
|
-
}).should.deep.equal(['now', 1000]);
|
|
614
|
+
}).should.deep.equal(['now', 1000]);
|
|
615
|
+
// Zero point (future to past).
|
|
527
616
|
// `future: true`.
|
|
528
617
|
// Updates right after zero point.
|
|
529
|
-
|
|
530
618
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
531
619
|
getTimeToNextUpdate: true,
|
|
532
620
|
now: 60 * 1000,
|
|
533
621
|
future: true,
|
|
534
622
|
round: 'floor'
|
|
535
|
-
}).should.deep.equal(['now', 1]);
|
|
623
|
+
}).should.deep.equal(['now', 1]);
|
|
624
|
+
// Zero point (future to past).
|
|
536
625
|
// `future: false`.
|
|
537
626
|
// Updates at the next second.
|
|
538
|
-
|
|
539
627
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
540
628
|
getTimeToNextUpdate: true,
|
|
541
629
|
now: 60 * 1000,
|
|
542
630
|
round: 'floor'
|
|
543
|
-
}).should.deep.equal(['now', 1000]);
|
|
544
|
-
|
|
631
|
+
}).should.deep.equal(['now', 1000]);
|
|
632
|
+
// Right after zero point (past).
|
|
545
633
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
546
634
|
getTimeToNextUpdate: true,
|
|
547
635
|
now: 60 * 1000 + 1,
|
|
548
636
|
round: 'floor'
|
|
549
|
-
}).should.deep.equal(['now', 1000 - 1]);
|
|
550
|
-
|
|
637
|
+
}).should.deep.equal(['now', 1000 - 1]);
|
|
638
|
+
// 1 second ago.
|
|
551
639
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
552
640
|
getTimeToNextUpdate: true,
|
|
553
641
|
now: 60 * 1000 + 1000,
|
|
@@ -559,8 +647,8 @@ describe("javascript-time-ago", function () {
|
|
|
559
647
|
timeAgo.format(Date.now(), {
|
|
560
648
|
labels: 'long',
|
|
561
649
|
steps: [{
|
|
562
|
-
format: function format(date, locale,
|
|
563
|
-
var formatAs =
|
|
650
|
+
format: function format(date, locale, _ref4) {
|
|
651
|
+
var formatAs = _ref4.formatAs;
|
|
564
652
|
return formatAs('second', 1);
|
|
565
653
|
}
|
|
566
654
|
}]
|
|
@@ -569,8 +657,8 @@ describe("javascript-time-ago", function () {
|
|
|
569
657
|
it('should support `polyfill: false` option', function () {
|
|
570
658
|
var timeAgo = new TimeAgo('en', {
|
|
571
659
|
polyfill: false
|
|
572
|
-
});
|
|
573
|
-
|
|
660
|
+
});
|
|
661
|
+
// Still uses "now" labels, even when not polyfilled.
|
|
574
662
|
timeAgo.format(0, 'round', {
|
|
575
663
|
now: 0
|
|
576
664
|
}).should.equal('just now');
|
|
@@ -622,12 +710,17 @@ describe("javascript-time-ago", function () {
|
|
|
622
710
|
TimeAgo.addDefaultLocale({
|
|
623
711
|
locale: 'el'
|
|
624
712
|
});
|
|
625
|
-
TimeAgo.getDefaultLocale().should.equal('el');
|
|
626
|
-
|
|
713
|
+
TimeAgo.getDefaultLocale().should.equal('el');
|
|
714
|
+
// Doesn't throw an error because the same locale is already specified as default.
|
|
627
715
|
TimeAgo.addDefaultLocale({
|
|
628
716
|
locale: 'el'
|
|
629
|
-
});
|
|
630
|
-
|
|
717
|
+
});
|
|
718
|
+
// Could throw an error or output an error message because another locale is already specified as default.
|
|
719
|
+
// expect(() => {
|
|
720
|
+
TimeAgo.addDefaultLocale({
|
|
721
|
+
locale: 'es'
|
|
722
|
+
});
|
|
723
|
+
// }).to.throw('but you have already added "el" as the default locale.')
|
|
631
724
|
TimeAgo.setDefaultLocale('en');
|
|
632
725
|
});
|
|
633
726
|
it('should support "floor" rounding', function () {
|
|
@@ -658,4 +751,9 @@ describe("javascript-time-ago", function () {
|
|
|
658
751
|
}).should.equal('2m');
|
|
659
752
|
});
|
|
660
753
|
});
|
|
754
|
+
function delay(delayTime) {
|
|
755
|
+
return new Promise(function (resolve) {
|
|
756
|
+
setTimeout(resolve, delayTime);
|
|
757
|
+
});
|
|
758
|
+
}
|
|
661
759
|
//# sourceMappingURL=TimeAgo.test.js.map
|