Created
July 24, 2015 14:22
-
-
Save pablomatiasgomez/91d2e3813bb1c308e9c6 to your computer and use it in GitHub Desktop.
Get the creation date for a generated mongo id
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
#!/usr/bin/env node | |
var getDate = function(id) { | |
return new Date(parseInt(id.toString().slice(0, 8), 16) * 1000); | |
} | |
if (process.argv.length > 2) { | |
process.argv.slice(2).forEach(function (val, i) { | |
console.log(val + ": " + getDate(val)); | |
}); | |
} else { | |
var readline = require('readline'); | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
terminal: false | |
}); | |
rl.on('line', function(line){ | |
console.log(getDate(line)); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment