-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrelative-time.min.js
More file actions
9 lines (8 loc) · 909 Bytes
/
Copy pathrelative-time.min.js
File metadata and controls
9 lines (8 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
/**
* @yaireo/relative-time - javascript function to transform timestamp or date to local relative-time
*
* @version v1.1.0
* @author Yair Even-Or <vsync.design@gmail.com>
* @homepage https://github.com/yairEO/relative-time
*/
!function(e,o){var t=t||{};"function"==typeof t&&t.amd?t([],o):"object"==typeof exports&&"object"==typeof module?module.exports=o():"object"==typeof exports?exports.RelativeTime=o():e.RelativeTime=o()}(this,function(){const e={year:31536e6,month:2628e6,day:864e5,hour:36e5,minute:6e4,second:1e3},o="en",t={numeric:"auto"};function n(e){e={locale:(e=e||{}).locale||o,options:{...t,...e.options}},this.rtf=new Intl.RelativeTimeFormat(e.locale,e.options)}return n.prototype={from(o,t){const n=o-(t||new Date);for(let o in e)if(Math.abs(n)>e[o]||"second"==o)return this.rtf.format(Math.round(n/e[o]),o)}},n.from=function(e,o,t){return new n(t?{locale:t}:{}).from(e,o)},n});