UNPKG

carbonjs

Version:

Javascript date library alternative to Moment.js with the same modern API

1 lines 986 B
"use strict";const r=require("../constants"),t=require("../index"),e=[{l:"s",r:44,d:r.SECOND},{l:"m",r:89},{l:"mm",r:44,d:r.MINUTE},{l:"h",r:89},{l:"hh",r:21,d:r.HOUR},{l:"d",r:35},{l:"dd",r:25,d:r.DAY},{l:"M",r:45},{l:"MM",r:10,d:r.MONTH},{l:"y",r:17},{l:"yy",d:r.YEAR}],s=e.length,n=(r,n=!1,o,d=!1)=>{const a=o._locale.relativeTime;let i,l;for(let n=0;n<s;n+=1){const s=e[n];s.d&&(i=d?t.parse(r).diff(o,s.d,!0):o.diff(r,s.d,!0));const u=Math.ceil(Math.abs(i));if(u<=s.r||!s.r){l=a[s.l].replace("%d",u);break}}return n?l:(i>0?a.future:a.past).replace("%s",l)};module.exports=(r=>{r._en.relativeTime={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};const e=r.prototype;e.from=function(r,t){return n(r,t,this)},e.to=function(r,t){return n(r,t,this,!0)},e.fromNow=function(r){return this.from(t.parse(),r)},e.toNow=function(r){return this.to(t.parse(),r)}});