Skip to content

Instantly share code, notes, and snippets.

@deptno
Created April 18, 2016 02:47
Show Gist options
  • Save deptno/b6aa9e07267f3cc5bcebf6ee1c0f6454 to your computer and use it in GitHub Desktop.
Save deptno/b6aa9e07267f3cc5bcebf6ee1c0f6454 to your computer and use it in GitHub Desktop.
만 나이 계산기 군대 빼고
#!/usr/bin/env node
function howOldAreYou(birth, employment, joinArmy, discharge) {
if (arguments.length !== 4) {
console.log(`arguments[yyyy-mm-dd]: 생일, 취업일, 입대, 전역`);
process.exit();
}
var dateBirth = new Date(birth);
var dateEmployment = new Date(employment);
var dateJoinArmy = new Date(joinArmy);
var dateDischarge = new Date(discharge);
var interval = new Date(dateEmployment - dateBirth - (dateDischarge - dateJoinArmy));
interval.setYear(interval.getYear() - 70);
return interval;
}
if (process.argv.indexOf(__filename) !== -1) {
var dateInterval = howOldAreYou.apply(null, process.argv.slice(2));
console.log(`${dateInterval.getYear()}년 ${dateInterval.getMonth()}월 ${dateInterval.getDate()}일`);
} else {
module.exports = function howOldAreYou(birth, employment, joinArmy, discharge) {
return howOldAreYou.apply(null, arguments);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment