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/commonjs/TimeAgo.test.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _TimeAgo = _interopRequireDefault(require("./TimeAgo.js"));
|
|
4
|
-
|
|
5
4
|
var _LocaleDataStore = require("./LocaleDataStore.js");
|
|
6
|
-
|
|
7
5
|
var _en = _interopRequireDefault(require("../locale/en.json"));
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
7
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
8
|
+
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."); }
|
|
9
|
+
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; } }
|
|
10
|
+
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; }
|
|
11
|
+
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; } }
|
|
12
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } // Load locale specific relative date/time messages
|
|
12
13
|
// Just so this function code is covered.
|
|
13
14
|
_TimeAgo["default"].setDefaultLocale('en');
|
|
14
|
-
|
|
15
15
|
describe("javascript-time-ago", function () {
|
|
16
16
|
it('should default to "round-minute" style', function () {
|
|
17
17
|
var timeAgo = new _TimeAgo["default"]('en');
|
|
@@ -48,8 +48,8 @@ describe("javascript-time-ago", function () {
|
|
|
48
48
|
}, {
|
|
49
49
|
future: true,
|
|
50
50
|
now: 0
|
|
51
|
-
}).should.equal('now');
|
|
52
|
-
|
|
51
|
+
}).should.equal('now');
|
|
52
|
+
// `flavour` is a legacy name of `labels` property.
|
|
53
53
|
timeAgo.format(0, {
|
|
54
54
|
flavour: 'mini'
|
|
55
55
|
}, {
|
|
@@ -69,8 +69,8 @@ describe("javascript-time-ago", function () {
|
|
|
69
69
|
}, {
|
|
70
70
|
future: true,
|
|
71
71
|
now: 0
|
|
72
|
-
}).should.equal('in 0 minutes');
|
|
73
|
-
|
|
72
|
+
}).should.equal('in 0 minutes');
|
|
73
|
+
// `gradation` is a legacy name of `steps` property.
|
|
74
74
|
timeAgo.format(0, {
|
|
75
75
|
gradation: [{
|
|
76
76
|
formatAs: 'minute'
|
|
@@ -96,9 +96,7 @@ describe("javascript-time-ago", function () {
|
|
|
96
96
|
var timeAgo = new _TimeAgo["default"]('en');
|
|
97
97
|
var englishNow = _en["default"].now;
|
|
98
98
|
delete _en["default"].now;
|
|
99
|
-
|
|
100
99
|
_TimeAgo["default"].addLocale(_en["default"]);
|
|
101
|
-
|
|
102
100
|
_en["default"].now = undefined;
|
|
103
101
|
timeAgo.format(Date.now(), {
|
|
104
102
|
labels: 'long'
|
|
@@ -129,9 +127,7 @@ describe("javascript-time-ago", function () {
|
|
|
129
127
|
_en["default"].now = {
|
|
130
128
|
now: 'now'
|
|
131
129
|
};
|
|
132
|
-
|
|
133
130
|
_TimeAgo["default"].addLocale(_en["default"]);
|
|
134
|
-
|
|
135
131
|
timeAgo.format(Date.now(), {
|
|
136
132
|
labels: 'long'
|
|
137
133
|
}).should.equal('now');
|
|
@@ -147,18 +143,16 @@ describe("javascript-time-ago", function () {
|
|
|
147
143
|
past: '{0} minute(s) ago',
|
|
148
144
|
future: 'in {0} minute(s)'
|
|
149
145
|
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
146
|
+
_TimeAgo["default"].addLocale(_en["default"]);
|
|
147
|
+
// Past.
|
|
154
148
|
timeAgo.format(Date.now() - 60 * 1000, {
|
|
155
149
|
labels: 'long-time'
|
|
156
|
-
}).should.equal('1 minute(s) ago');
|
|
157
|
-
|
|
150
|
+
}).should.equal('1 minute(s) ago');
|
|
151
|
+
// Future (covers an "else" branch).
|
|
158
152
|
timeAgo.format(Date.now() + 60 * 1000, {
|
|
159
153
|
labels: 'long-time'
|
|
160
|
-
}).should.equal('in 1 minute(s)');
|
|
161
|
-
|
|
154
|
+
}).should.equal('in 1 minute(s)');
|
|
155
|
+
// Undo.
|
|
162
156
|
_en["default"]['long-time'].minute = englishLongTimeMinute;
|
|
163
157
|
timeAgo.format(Date.now() - 60 * 1000, {
|
|
164
158
|
labels: 'long-time'
|
|
@@ -171,43 +165,43 @@ describe("javascript-time-ago", function () {
|
|
|
171
165
|
}).should.equal('in a moment');
|
|
172
166
|
});
|
|
173
167
|
it('should accept a string style name argument', function () {
|
|
174
|
-
var timeAgo = new _TimeAgo["default"]('en');
|
|
175
|
-
|
|
168
|
+
var timeAgo = new _TimeAgo["default"]('en');
|
|
169
|
+
// "mini".
|
|
176
170
|
timeAgo.format(Date.now() - 0 * 1000, 'mini').should.equal('0s');
|
|
177
|
-
timeAgo.format(Date.now() - 1 * 1000, 'mini').should.equal('1s');
|
|
178
|
-
|
|
171
|
+
timeAgo.format(Date.now() - 1 * 1000, 'mini').should.equal('1s');
|
|
172
|
+
// "mini-now".
|
|
179
173
|
timeAgo.format(Date.now() - 0 * 1000, 'mini-now').should.equal('now');
|
|
180
|
-
timeAgo.format(Date.now() - 1 * 1000, 'mini-now').should.equal('1s');
|
|
181
|
-
|
|
174
|
+
timeAgo.format(Date.now() - 1 * 1000, 'mini-now').should.equal('1s');
|
|
175
|
+
// "mini-minute-now".
|
|
182
176
|
timeAgo.format(Date.now() - 29 * 1000, 'mini-minute-now').should.equal('now');
|
|
183
|
-
timeAgo.format(Date.now() - 60 * 1000, 'mini-minute-now').should.equal('1m');
|
|
184
|
-
|
|
177
|
+
timeAgo.format(Date.now() - 60 * 1000, 'mini-minute-now').should.equal('1m');
|
|
178
|
+
// "mini-minute".
|
|
185
179
|
timeAgo.format(Date.now() - 29 * 1000, 'mini-minute').should.equal('0m');
|
|
186
|
-
timeAgo.format(Date.now() - 60 * 1000, 'mini-minute').should.equal('1m');
|
|
187
|
-
|
|
180
|
+
timeAgo.format(Date.now() - 60 * 1000, 'mini-minute').should.equal('1m');
|
|
181
|
+
// "twitter".
|
|
188
182
|
timeAgo.format(Date.now() - 0 * 1000, 'twitter').should.equal('0s');
|
|
189
|
-
timeAgo.format(Date.now() - 1 * 1000, 'twitter').should.equal('1s');
|
|
190
|
-
|
|
183
|
+
timeAgo.format(Date.now() - 1 * 1000, 'twitter').should.equal('1s');
|
|
184
|
+
// "twitter-now".
|
|
191
185
|
timeAgo.format(Date.now() - 0 * 1000, 'twitter-now').should.equal('now');
|
|
192
|
-
timeAgo.format(Date.now() - 1 * 1000, 'twitter-now').should.equal('1s');
|
|
193
|
-
|
|
186
|
+
timeAgo.format(Date.now() - 1 * 1000, 'twitter-now').should.equal('1s');
|
|
187
|
+
// "twitter-minute-now".
|
|
194
188
|
timeAgo.format(Date.now() - 29 * 1000, 'twitter-minute-now').should.equal('now');
|
|
195
|
-
timeAgo.format(Date.now() - 60 * 1000, 'twitter-minute-now').should.equal('1m');
|
|
196
|
-
|
|
189
|
+
timeAgo.format(Date.now() - 60 * 1000, 'twitter-minute-now').should.equal('1m');
|
|
190
|
+
// "twitter-minute".
|
|
197
191
|
timeAgo.format(Date.now() - 29 * 1000, 'twitter-minute').should.equal('0m');
|
|
198
|
-
timeAgo.format(Date.now() - 60 * 1000, 'twitter-minute').should.equal('1m');
|
|
199
|
-
|
|
192
|
+
timeAgo.format(Date.now() - 60 * 1000, 'twitter-minute').should.equal('1m');
|
|
193
|
+
// "twitter-first-minute".
|
|
200
194
|
timeAgo.format(Date.now() - 29 * 1000, 'twitter-first-minute').should.equal('');
|
|
201
|
-
timeAgo.format(Date.now() - 60 * 1000, 'twitter-first-minute').should.equal('1m');
|
|
202
|
-
|
|
203
|
-
timeAgo.format(Date.now() - 45 * 1000, 'approximate').should.equal('just now');
|
|
204
|
-
|
|
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".
|
|
205
199
|
timeAgo.format(Date.now() - 45 * 1000, 'convenient').should.equal('just now');
|
|
206
|
-
timeAgo.format(Date.now() - 45 * 1000, 'round').should.equal('45 seconds ago');
|
|
207
|
-
|
|
200
|
+
timeAgo.format(Date.now() - 45 * 1000, 'round').should.equal('45 seconds ago');
|
|
201
|
+
// "default" style was renamed to "round".
|
|
208
202
|
timeAgo.format(Date.now() - 45 * 1000, 'default').should.equal('45 seconds ago');
|
|
209
|
-
timeAgo.format(Date.now() - 29 * 1000, 'round-minute').should.equal('just now');
|
|
210
|
-
|
|
203
|
+
timeAgo.format(Date.now() - 29 * 1000, 'round-minute').should.equal('just now');
|
|
204
|
+
// "time" style was renamed to "approximate-time".
|
|
211
205
|
timeAgo.format(Date.now() - 2 * 60 * 1000, 'time').should.equal('2 minutes');
|
|
212
206
|
timeAgo.format(Date.now() - 2 * 60 * 1000, 'approximate-time').should.equal('2 minutes');
|
|
213
207
|
timeAgo.format(Date.now(), 'exotic').should.equal('just now');
|
|
@@ -227,11 +221,9 @@ describe("javascript-time-ago", function () {
|
|
|
227
221
|
});
|
|
228
222
|
it('should not accept anything but Dates and timestamps', function () {
|
|
229
223
|
var timeAgo = new _TimeAgo["default"]('en');
|
|
230
|
-
|
|
231
224
|
var thrower = function thrower() {
|
|
232
225
|
return timeAgo.format('Jan 14, 2017');
|
|
233
226
|
};
|
|
234
|
-
|
|
235
227
|
thrower.should["throw"]('Unsupported relative time formatter input: string, Jan 14, 2017');
|
|
236
228
|
});
|
|
237
229
|
it('should return an empty string if the specified units are not available in locale data', function () {
|
|
@@ -241,28 +233,45 @@ describe("javascript-time-ago", function () {
|
|
|
241
233
|
}).should.equal('');
|
|
242
234
|
});
|
|
243
235
|
it('should format for a style with "custom" function', function () {
|
|
244
|
-
var timeAgo = new _TimeAgo["default"]('en');
|
|
245
|
-
|
|
236
|
+
var timeAgo = new _TimeAgo["default"]('en');
|
|
246
237
|
timeAgo.format(Date.now(), {
|
|
238
|
+
// `custom` returns a string
|
|
247
239
|
custom: function custom(_ref) {
|
|
248
240
|
var now = _ref.now,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
241
|
+
time = _ref.time,
|
|
242
|
+
date = _ref.date,
|
|
243
|
+
locale = _ref.locale;
|
|
252
244
|
return locale;
|
|
253
245
|
}
|
|
254
|
-
}).should.equal('en');
|
|
255
|
-
|
|
246
|
+
}).should.equal('en');
|
|
256
247
|
timeAgo.format(Date.now(), {
|
|
248
|
+
// `custom` returns `undefined`
|
|
257
249
|
custom: function custom(_ref2) {
|
|
258
250
|
var now = _ref2.now,
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
251
|
+
time = _ref2.time,
|
|
252
|
+
date = _ref2.date,
|
|
253
|
+
locale = _ref2.locale;
|
|
262
254
|
return;
|
|
263
255
|
}
|
|
264
256
|
}).should.equal('just now');
|
|
265
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["default"]('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
|
+
});
|
|
266
275
|
it('should format future dates', function () {
|
|
267
276
|
new _TimeAgo["default"]('en').format(Date.now() + 60 * 60 * 1000).should.equal('in 1 hour');
|
|
268
277
|
new _TimeAgo["default"]('ru').format(Date.now() + 60 * 1000).should.equal('через 1 минуту');
|
|
@@ -272,7 +281,9 @@ describe("javascript-time-ago", function () {
|
|
|
272
281
|
new _TimeAgo["default"]('en').format(Date.now()).should.equal('just now');
|
|
273
282
|
new _TimeAgo["default"]('en').format(Date.now(), 'approximate', {
|
|
274
283
|
future: true
|
|
275
|
-
}).should.equal('in a moment');
|
|
284
|
+
}).should.equal('in a moment');
|
|
285
|
+
|
|
286
|
+
// Non-"now" unit, "long" style.
|
|
276
287
|
// const style = {
|
|
277
288
|
// gradation: [{
|
|
278
289
|
// factor: 1,
|
|
@@ -282,8 +293,8 @@ describe("javascript-time-ago", function () {
|
|
|
282
293
|
// }
|
|
283
294
|
// new TimeAgo('en').format(Date.now(), style).should.equal('0 seconds ago')
|
|
284
295
|
// new TimeAgo('en').format(Date.now(), style, { future: true }).should.equal('in 0 seconds')
|
|
285
|
-
// Non-"now" unit, "mini" style.
|
|
286
296
|
|
|
297
|
+
// Non-"now" unit, "mini" style.
|
|
287
298
|
var style2 = {
|
|
288
299
|
style: [{
|
|
289
300
|
unit: 'year'
|
|
@@ -319,7 +330,6 @@ describe("javascript-time-ago", function () {
|
|
|
319
330
|
});
|
|
320
331
|
it('should choose "future" variant of a label for `0` if "future: true" option is passed', function () {
|
|
321
332
|
_TimeAgo["default"].addLocale(_en["default"]);
|
|
322
|
-
|
|
323
333
|
var secondLabels = _en["default"]['mini'].second;
|
|
324
334
|
_en["default"]['mini'].second = {
|
|
325
335
|
past: '{0} seconds ago',
|
|
@@ -343,9 +353,65 @@ describe("javascript-time-ago", function () {
|
|
|
343
353
|
}).should.equal('in 0 seconds');
|
|
344
354
|
_en["default"]['mini'].second = secondLabels;
|
|
345
355
|
});
|
|
356
|
+
it('should refresh the label when `refresh` parameter is passed', function () {
|
|
357
|
+
var refreshedTimes = 0;
|
|
358
|
+
var timeAgo = new _TimeAgo["default"]('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["default"]('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["default"]('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["default"]('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
|
+
});
|
|
346
412
|
it('should get time to next update (round: "floor")', function () {
|
|
347
|
-
var timeAgo = new _TimeAgo["default"]('en');
|
|
348
|
-
|
|
413
|
+
var timeAgo = new _TimeAgo["default"]('en');
|
|
414
|
+
// in 1 second -> in 0 seconds.
|
|
349
415
|
timeAgo.format(1000, 'twitter', {
|
|
350
416
|
getTimeToNextUpdate: true,
|
|
351
417
|
now: 0,
|
|
@@ -353,62 +419,63 @@ describe("javascript-time-ago", function () {
|
|
|
353
419
|
}).should.deep.equal(['1s', 1]);
|
|
354
420
|
});
|
|
355
421
|
it('should get time to next update (round: "round")', function () {
|
|
356
|
-
var timeAgo = new _TimeAgo["default"]('en');
|
|
357
|
-
|
|
422
|
+
var timeAgo = new _TimeAgo["default"]('en');
|
|
423
|
+
// in 1 second -> in 0 seconds.
|
|
358
424
|
timeAgo.format(1000, 'twitter', {
|
|
359
425
|
getTimeToNextUpdate: true,
|
|
360
426
|
now: 0
|
|
361
427
|
}).should.deep.equal(['1s', 501]);
|
|
362
428
|
});
|
|
363
429
|
it('should get time to next update ("mini-now" style) (round: "floor")', function () {
|
|
364
|
-
var timeAgo = new _TimeAgo["default"]('en');
|
|
365
|
-
|
|
430
|
+
var timeAgo = new _TimeAgo["default"]('en');
|
|
431
|
+
// In 1 minute.
|
|
366
432
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
367
433
|
getTimeToNextUpdate: true,
|
|
368
434
|
now: 0,
|
|
369
435
|
round: 'floor'
|
|
370
|
-
}).should.deep.equal(['1m', 1]);
|
|
371
|
-
|
|
436
|
+
}).should.deep.equal(['1m', 1]);
|
|
437
|
+
// Almost in 1 minute.
|
|
372
438
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
373
439
|
getTimeToNextUpdate: true,
|
|
374
440
|
now: 1,
|
|
375
441
|
round: 'floor'
|
|
376
|
-
}).should.deep.equal(['59s', 1000]);
|
|
377
|
-
|
|
442
|
+
}).should.deep.equal(['59s', 1000]);
|
|
443
|
+
// In 1 second.
|
|
378
444
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
379
445
|
getTimeToNextUpdate: true,
|
|
380
446
|
now: 59 * 1000,
|
|
381
447
|
round: 'floor'
|
|
382
|
-
}).should.deep.equal(['1s', 1]);
|
|
383
|
-
|
|
448
|
+
}).should.deep.equal(['1s', 1]);
|
|
449
|
+
// Almost in 1 second.
|
|
384
450
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
385
451
|
getTimeToNextUpdate: true,
|
|
386
452
|
now: 59 * 1000 + 1,
|
|
387
453
|
round: 'floor'
|
|
388
|
-
}).should.deep.equal(['now',
|
|
389
|
-
|
|
454
|
+
}).should.deep.equal(['now',
|
|
455
|
+
// Right after zero point.
|
|
456
|
+
1000]);
|
|
457
|
+
// Zero point (future to past).
|
|
390
458
|
// `future: true`.
|
|
391
|
-
|
|
392
459
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
393
460
|
getTimeToNextUpdate: true,
|
|
394
461
|
now: 60 * 1000,
|
|
395
462
|
future: true,
|
|
396
463
|
round: 'floor'
|
|
397
|
-
}).should.deep.equal(['now', 1]);
|
|
464
|
+
}).should.deep.equal(['now', 1]);
|
|
465
|
+
// Zero point (future to past).
|
|
398
466
|
// `future: false`.
|
|
399
|
-
|
|
400
467
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
401
468
|
getTimeToNextUpdate: true,
|
|
402
469
|
now: 60 * 1000,
|
|
403
470
|
round: 'floor'
|
|
404
|
-
}).should.deep.equal(['now', 1000]);
|
|
405
|
-
|
|
471
|
+
}).should.deep.equal(['now', 1000]);
|
|
472
|
+
// Right after zero point (past).
|
|
406
473
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
407
474
|
getTimeToNextUpdate: true,
|
|
408
475
|
now: 60 * 1000 + 1,
|
|
409
476
|
round: 'floor'
|
|
410
|
-
}).should.deep.equal(['now', 1000 - 1]);
|
|
411
|
-
|
|
477
|
+
}).should.deep.equal(['now', 1000 - 1]);
|
|
478
|
+
// 1 second ago.
|
|
412
479
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
413
480
|
getTimeToNextUpdate: true,
|
|
414
481
|
now: 60 * 1000 + 1000,
|
|
@@ -416,57 +483,59 @@ describe("javascript-time-ago", function () {
|
|
|
416
483
|
}).should.deep.equal(['1s', 1000]);
|
|
417
484
|
});
|
|
418
485
|
it('should get time to next update ("mini-now" style) (round: "round")', function () {
|
|
419
|
-
var timeAgo = new _TimeAgo["default"]('en');
|
|
420
|
-
|
|
486
|
+
var timeAgo = new _TimeAgo["default"]('en');
|
|
487
|
+
// In 1 minute.
|
|
421
488
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
422
489
|
getTimeToNextUpdate: true,
|
|
423
490
|
now: 0
|
|
424
|
-
}).should.deep.equal(['1m', 500 + 1]);
|
|
425
|
-
|
|
491
|
+
}).should.deep.equal(['1m', 500 + 1]);
|
|
492
|
+
// Almost in 1 minute.
|
|
426
493
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
427
494
|
getTimeToNextUpdate: true,
|
|
428
495
|
now: 500 + 1
|
|
429
|
-
}).should.deep.equal(['59s', 1000]);
|
|
430
|
-
|
|
496
|
+
}).should.deep.equal(['59s', 1000]);
|
|
497
|
+
// In 1 second.
|
|
431
498
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
432
499
|
getTimeToNextUpdate: true,
|
|
433
500
|
now: 59.5 * 1000
|
|
434
|
-
}).should.deep.equal(['1s', 1]);
|
|
435
|
-
|
|
501
|
+
}).should.deep.equal(['1s', 1]);
|
|
502
|
+
// Almost in 1 second.
|
|
436
503
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
437
504
|
getTimeToNextUpdate: true,
|
|
438
505
|
now: 59.5 * 1000 + 1
|
|
439
|
-
}).should.deep.equal(['now',
|
|
440
|
-
|
|
506
|
+
}).should.deep.equal(['now',
|
|
507
|
+
// Right after zero point.
|
|
508
|
+
500]);
|
|
509
|
+
// Zero point (future to past).
|
|
441
510
|
// `future: true`.
|
|
442
|
-
|
|
443
511
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
444
512
|
getTimeToNextUpdate: true,
|
|
445
513
|
now: 60 * 1000,
|
|
446
514
|
future: true
|
|
447
|
-
}).should.deep.equal(['now', 1]);
|
|
515
|
+
}).should.deep.equal(['now', 1]);
|
|
516
|
+
// Zero point (future to past).
|
|
448
517
|
// `future: false`.
|
|
449
|
-
|
|
450
518
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
451
519
|
getTimeToNextUpdate: true,
|
|
452
520
|
now: 60 * 1000
|
|
453
|
-
}).should.deep.equal(['now', 500]);
|
|
454
|
-
|
|
521
|
+
}).should.deep.equal(['now', 500]);
|
|
522
|
+
// Right after zero point (past).
|
|
455
523
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
456
524
|
getTimeToNextUpdate: true,
|
|
457
525
|
now: 60 * 1000 + 1
|
|
458
|
-
}).should.deep.equal(['now', 500 - 1]);
|
|
459
|
-
|
|
526
|
+
}).should.deep.equal(['now', 500 - 1]);
|
|
527
|
+
// 1 second ago.
|
|
460
528
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
461
529
|
getTimeToNextUpdate: true,
|
|
462
530
|
now: 60 * 1000 + 500
|
|
463
531
|
}).should.deep.equal(['1s', 1000]);
|
|
464
532
|
});
|
|
465
533
|
it('should get time to next update (first step has non-zero "minTime") (round: "floor")', function () {
|
|
466
|
-
var timeAgo = new _TimeAgo["default"]('en');
|
|
534
|
+
var timeAgo = new _TimeAgo["default"]('en');
|
|
535
|
+
|
|
536
|
+
// Future.
|
|
467
537
|
// Inside the first step.
|
|
468
538
|
// Updates soon.
|
|
469
|
-
|
|
470
539
|
timeAgo.format(60 * 1000, {
|
|
471
540
|
steps: [{
|
|
472
541
|
formatAs: 'minute',
|
|
@@ -477,10 +546,11 @@ describe("javascript-time-ago", function () {
|
|
|
477
546
|
}, {
|
|
478
547
|
getTimeToNextUpdate: true,
|
|
479
548
|
now: -0.5 * 1000
|
|
480
|
-
}).should.deep.equal(['1m', 0.5 * 1000 + 1]);
|
|
549
|
+
}).should.deep.equal(['1m', 0.5 * 1000 + 1]);
|
|
550
|
+
|
|
551
|
+
// Future.
|
|
481
552
|
// Outside of the first step.
|
|
482
553
|
// Updates right after zero point.
|
|
483
|
-
|
|
484
554
|
timeAgo.format(60 * 1000, {
|
|
485
555
|
steps: [{
|
|
486
556
|
formatAs: 'minute',
|
|
@@ -491,10 +561,11 @@ describe("javascript-time-ago", function () {
|
|
|
491
561
|
}, {
|
|
492
562
|
getTimeToNextUpdate: true,
|
|
493
563
|
now: 1 * 1000
|
|
494
|
-
}).should.deep.equal(['', 59 * 1000 + 1]);
|
|
564
|
+
}).should.deep.equal(['', 59 * 1000 + 1]);
|
|
565
|
+
|
|
566
|
+
// Zero point.
|
|
495
567
|
// Outside of the first step.
|
|
496
568
|
// Updates at the first step's `minTime`.
|
|
497
|
-
|
|
498
569
|
timeAgo.format(60 * 1000, {
|
|
499
570
|
steps: [{
|
|
500
571
|
formatAs: 'minute',
|
|
@@ -505,10 +576,11 @@ describe("javascript-time-ago", function () {
|
|
|
505
576
|
}, {
|
|
506
577
|
getTimeToNextUpdate: true,
|
|
507
578
|
now: 60 * 1000
|
|
508
|
-
}).should.deep.equal(['', 60 * 1000]);
|
|
579
|
+
}).should.deep.equal(['', 60 * 1000]);
|
|
580
|
+
|
|
581
|
+
// Past.
|
|
509
582
|
// Inside the first step.
|
|
510
583
|
// Updates at the next minute.
|
|
511
|
-
|
|
512
584
|
timeAgo.format(60 * 1000, {
|
|
513
585
|
steps: [{
|
|
514
586
|
formatAs: 'minute',
|
|
@@ -519,50 +591,51 @@ describe("javascript-time-ago", function () {
|
|
|
519
591
|
}, {
|
|
520
592
|
getTimeToNextUpdate: true,
|
|
521
593
|
now: 60 * 1000 + 60 * 1000
|
|
522
|
-
}).should.deep.equal(['1m', 60 * 1000]);
|
|
594
|
+
}).should.deep.equal(['1m', 60 * 1000]);
|
|
523
595
|
|
|
596
|
+
// Almost in 1 minute.
|
|
524
597
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
525
598
|
getTimeToNextUpdate: true,
|
|
526
599
|
now: 1,
|
|
527
600
|
round: 'floor'
|
|
528
|
-
}).should.deep.equal(['59s', 1000]);
|
|
529
|
-
|
|
601
|
+
}).should.deep.equal(['59s', 1000]);
|
|
602
|
+
// In 1 second.
|
|
530
603
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
531
604
|
getTimeToNextUpdate: true,
|
|
532
605
|
now: 59 * 1000,
|
|
533
606
|
round: 'floor'
|
|
534
|
-
}).should.deep.equal(['1s', 1]);
|
|
607
|
+
}).should.deep.equal(['1s', 1]);
|
|
608
|
+
// Almost in 1 second.
|
|
535
609
|
// Updates right after the zero point.
|
|
536
|
-
|
|
537
610
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
538
611
|
getTimeToNextUpdate: true,
|
|
539
612
|
now: 59 * 1000 + 1,
|
|
540
613
|
round: 'floor'
|
|
541
|
-
}).should.deep.equal(['now', 1000]);
|
|
614
|
+
}).should.deep.equal(['now', 1000]);
|
|
615
|
+
// Zero point (future to past).
|
|
542
616
|
// `future: true`.
|
|
543
617
|
// Updates right after zero point.
|
|
544
|
-
|
|
545
618
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
546
619
|
getTimeToNextUpdate: true,
|
|
547
620
|
now: 60 * 1000,
|
|
548
621
|
future: true,
|
|
549
622
|
round: 'floor'
|
|
550
|
-
}).should.deep.equal(['now', 1]);
|
|
623
|
+
}).should.deep.equal(['now', 1]);
|
|
624
|
+
// Zero point (future to past).
|
|
551
625
|
// `future: false`.
|
|
552
626
|
// Updates at the next second.
|
|
553
|
-
|
|
554
627
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
555
628
|
getTimeToNextUpdate: true,
|
|
556
629
|
now: 60 * 1000,
|
|
557
630
|
round: 'floor'
|
|
558
|
-
}).should.deep.equal(['now', 1000]);
|
|
559
|
-
|
|
631
|
+
}).should.deep.equal(['now', 1000]);
|
|
632
|
+
// Right after zero point (past).
|
|
560
633
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
561
634
|
getTimeToNextUpdate: true,
|
|
562
635
|
now: 60 * 1000 + 1,
|
|
563
636
|
round: 'floor'
|
|
564
|
-
}).should.deep.equal(['now', 1000 - 1]);
|
|
565
|
-
|
|
637
|
+
}).should.deep.equal(['now', 1000 - 1]);
|
|
638
|
+
// 1 second ago.
|
|
566
639
|
timeAgo.format(60 * 1000, 'mini-now', {
|
|
567
640
|
getTimeToNextUpdate: true,
|
|
568
641
|
now: 60 * 1000 + 1000,
|
|
@@ -574,8 +647,8 @@ describe("javascript-time-ago", function () {
|
|
|
574
647
|
timeAgo.format(Date.now(), {
|
|
575
648
|
labels: 'long',
|
|
576
649
|
steps: [{
|
|
577
|
-
format: function format(date, locale,
|
|
578
|
-
var formatAs =
|
|
650
|
+
format: function format(date, locale, _ref4) {
|
|
651
|
+
var formatAs = _ref4.formatAs;
|
|
579
652
|
return formatAs('second', 1);
|
|
580
653
|
}
|
|
581
654
|
}]
|
|
@@ -584,8 +657,8 @@ describe("javascript-time-ago", function () {
|
|
|
584
657
|
it('should support `polyfill: false` option', function () {
|
|
585
658
|
var timeAgo = new _TimeAgo["default"]('en', {
|
|
586
659
|
polyfill: false
|
|
587
|
-
});
|
|
588
|
-
|
|
660
|
+
});
|
|
661
|
+
// Still uses "now" labels, even when not polyfilled.
|
|
589
662
|
timeAgo.format(0, 'round', {
|
|
590
663
|
now: 0
|
|
591
664
|
}).should.equal('just now');
|
|
@@ -634,19 +707,20 @@ describe("javascript-time-ago", function () {
|
|
|
634
707
|
});
|
|
635
708
|
it('should add default locale', function () {
|
|
636
709
|
_TimeAgo["default"].getDefaultLocale().should.equal('en');
|
|
637
|
-
|
|
638
710
|
_TimeAgo["default"].addDefaultLocale({
|
|
639
711
|
locale: 'el'
|
|
640
712
|
});
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
713
|
+
_TimeAgo["default"].getDefaultLocale().should.equal('el');
|
|
714
|
+
// Doesn't throw an error because the same locale is already specified as default.
|
|
645
715
|
_TimeAgo["default"].addDefaultLocale({
|
|
646
716
|
locale: 'el'
|
|
647
|
-
});
|
|
648
|
-
|
|
649
|
-
|
|
717
|
+
});
|
|
718
|
+
// Could throw an error or output an error message because another locale is already specified as default.
|
|
719
|
+
// expect(() => {
|
|
720
|
+
_TimeAgo["default"].addDefaultLocale({
|
|
721
|
+
locale: 'es'
|
|
722
|
+
});
|
|
723
|
+
// }).to.throw('but you have already added "el" as the default locale.')
|
|
650
724
|
_TimeAgo["default"].setDefaultLocale('en');
|
|
651
725
|
});
|
|
652
726
|
it('should support "floor" rounding', function () {
|
|
@@ -677,4 +751,9 @@ describe("javascript-time-ago", function () {
|
|
|
677
751
|
}).should.equal('2m');
|
|
678
752
|
});
|
|
679
753
|
});
|
|
754
|
+
function delay(delayTime) {
|
|
755
|
+
return new Promise(function (resolve) {
|
|
756
|
+
setTimeout(resolve, delayTime);
|
|
757
|
+
});
|
|
758
|
+
}
|
|
680
759
|
//# sourceMappingURL=TimeAgo.test.js.map
|