nymag/byline-nunjucks

View on GitHub
filters/dates/formatUTCDate.js

Summary

Maintainability
A
0 mins
Test Coverage
'use strict';
var moment = require('moment'),
  defaultFormat = 'M/D/YYYY [at] h:mm a';

/**
 * Formats a date with moment.js
 *
 * @param  {*} date
 * @param {string} [format]
 * @return {string}
 */
module.exports = function (date, format) {
  format = format || defaultFormat;

  // moment defaults to using the local time
  return moment.utc(date).format(format);
};

module.exports.setMoment = function (instance) {
  moment = instance;
};

module.exports.getMoment = function () {
  return moment;
};

module.exports.getDefaultFormat = function () {
  return defaultFormat;
};