cscg24-guacamole

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

get.js (728B)


      1import { normalizeUnits } from '../units/aliases';
      2import absFloor from '../utils/abs-floor';
      3
      4export function get(units) {
      5    units = normalizeUnits(units);
      6    return this.isValid() ? this[units + 's']() : NaN;
      7}
      8
      9function makeGetter(name) {
     10    return function () {
     11        return this.isValid() ? this._data[name] : NaN;
     12    };
     13}
     14
     15var milliseconds = makeGetter('milliseconds'),
     16    seconds = makeGetter('seconds'),
     17    minutes = makeGetter('minutes'),
     18    hours = makeGetter('hours'),
     19    days = makeGetter('days'),
     20    months = makeGetter('months'),
     21    years = makeGetter('years');
     22
     23export { milliseconds, seconds, minutes, hours, days, months, years };
     24
     25export function weeks() {
     26    return absFloor(this.days() / 7);
     27}