top: function top()

in lib/util.js [238:263]


    top: function top(date, fmt) {
      fmt = fmt || '%Y-%M-%dT%H:%m:%sZ';

      function pad(value) {
        return (value.toString().length < 2) ? '0' + value : value;
      };

      return fmt.replace(/%([a-zA-Z])/g, function (_, fmtCode) {
        switch (fmtCode) {
          case 'Y':
            return date.getUTCFullYear();
          case 'M':
            return pad(date.getUTCMonth() + 1);
          case 'd':
            return pad(date.getUTCDate());
          case 'H':
            return pad(date.getUTCHours());
          case 'm':
            return pad(date.getUTCMinutes());
          case 's':
            return pad(date.getUTCSeconds());
          default:
            throw new Error('Unsupported format code: ' + fmtCode);
        }
      });
    },