Last active
July 26, 2016 13:50
-
-
Save davidowens/b1702e479d79b2865a1e47572580f6d5 to your computer and use it in GitHub Desktop.
Repack Moment.js data, limited to a subset of zones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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