cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

relative.js (842B)


      1export var defaultRelativeTime = {
      2    future: 'in %s',
      3    past: '%s ago',
      4    s: 'a few seconds',
      5    ss: '%d seconds',
      6    m: 'a minute',
      7    mm: '%d minutes',
      8    h: 'an hour',
      9    hh: '%d hours',
     10    d: 'a day',
     11    dd: '%d days',
     12    w: 'a week',
     13    ww: '%d weeks',
     14    M: 'a month',
     15    MM: '%d months',
     16    y: 'a year',
     17    yy: '%d years',
     18};
     19
     20import isFunction from '../utils/is-function';
     21
     22export function relativeTime(number, withoutSuffix, string, isFuture) {
     23    var output = this._relativeTime[string];
     24    return isFunction(output)
     25        ? output(number, withoutSuffix, string, isFuture)
     26        : output.replace(/%d/i, number);
     27}
     28
     29export function pastFuture(diff, output) {
     30    var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
     31    return isFunction(format) ? format(output) : format.replace(/%s/i, output);
     32}