Skip to content

Instantly share code, notes, and snippets.

@omas
Created January 5, 2015 02:53
Show Gist options
  • Save omas/216d746c7b79ba44bea1 to your computer and use it in GitHub Desktop.
Save omas/216d746c7b79ba44bea1 to your computer and use it in GitHub Desktop.
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
//console.time('1');
var lines = chunk.split('\n')[0].toString().split('/').join('-');
var result = (function(date) {
var tmpYear = date.getFullYear();
while (tmpYear === date.getFullYear() && !canDivide(date)) {
date.setDate(date.getDate() + 1);
}
return [
date.getFullYear()
,('0' + (date.getMonth() + 1)).slice(-2)
,('0' + (date.getDate())).slice(-2)
].join('/');
function canDivide(date) {
var y = date.getFullYear();
var m = date.getMonth() + 1;
var d = date.getDate();
return (y % (m * d) === 0);
}
}(new Date(lines)));
console.log(result);
//console.timeEnd('1');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment