Skip to content

Instantly share code, notes, and snippets.

@davidowens
Last active July 26, 2016 13:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidowens/b1702e479d79b2865a1e47572580f6d5 to your computer and use it in GitHub Desktop.
Save davidowens/b1702e479d79b2865a1e47572580f6d5 to your computer and use it in GitHub Desktop.
Repack Moment.js data, limited to a subset of zones
import gulp from 'gulp';
import moment from 'moment-timezone/moment-timezone';
import 'moment-timezone/moment-timezone-utils';
import fs from 'fs';
import config from '../../config';
const inputFile = 'node_modules/moment-timezone/data/unpacked/latest.json';
const outputFile = 'app/lib/moment-timezone-data.json';
const start = 2014;
const end = moment().add(5, 'years').year();
function buildMomentData(callback) {
const momentData = JSON.parse(fs.readFileSync(inputFile).toString());
const requiredTimeZones = [].concat(config.get('requiredTimeZones'), ['Zulu', 'UTC']);
const trimmedMomentData = Object.assign({}, momentData);
trimmedMomentData.zones = [];
requiredTimeZones.forEach(zone => {
const zoneData = momentData.zones.find(momentZone => momentZone.name === zone);
const trimmedZoneData = moment.tz.filterYears(zoneData, start, end);
trimmedMomentData.zones.push(trimmedZoneData);
});
trimmedMomentData.zones = trimmedMomentData.zones.map(zoneData => moment.tz.pack(zoneData));
fs.writeFile(outputFile, JSON.stringify(trimmedMomentData));
callback();
}
gulp.task('moment', function (callback) {
buildMomentData(callback);
});
import moment from '../../node_modules/moment-timezone/moment-timezone';
moment.tz.load(require('./moment-timezone-data.json'));
export default moment;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment