Skip to content

Instantly share code, notes, and snippets.

@joseph-allen
Last active August 9, 2016 12:48
Show Gist options
  • Save joseph-allen/4a64cf12e8d99a89aa2d2c06c5ec32f3 to your computer and use it in GitHub Desktop.
Save joseph-allen/4a64cf12e8d99a89aa2d2c06c5ec32f3 to your computer and use it in GitHub Desktop.
converts TV times to useful times
fs = require('fs');
moment = require('moment');
var dates = []
fs.readFile('times.js', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
dates = data.split('\n');
dates = dates.map(function(item){
console.log(moment(item,'DD/MM/YYYY HHmm').unix())
return moment(item,'DD/MM/YYYY HHmm').unix();
})
var outputText = 'var slots = [\n';
dates.forEach(function(date){
if(!isNaN(date)){
outputText += '\t' + date + '000,\n';
}
})
outputText = outputText.substring(0, outputText.length - 2);
outputText +='\n]';
fs.writeFile("output.txt", outputText, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment