Answer the question
In order to leave comments, you need to log in
How to find out what an incoming parameter is in a function, in someone else's code?
In the yearsDiff(dt)
@dt function - what is that value?
// @passportDate - дата выдачи паспорта
// @dudeDate - дата рождения чувака
function checkPassportDate(passportDate, dudeDate)
{
var dob = new Date(dudeDate.replace(/(\d{2}).(\d{2}).(\d{4})/, "$3-$2-$1"));
var pssprtDate = new Date(passportDate.replace(/(\d{2}).(\d{2}).(\d{4})/, "$3-$2-$1"));
var pDate20 = new Date(dob);
pDate20.setFullYear(pDate20.getFullYear() + 20);
var pDate45 = new Date(dob);
pDate45.setFullYear(pDate45.getFullYear() + 45);
var ageDude = parseInt(yearsDiff(new Date(dudeDate.replace(/(\d{2}).(\d{2}).(\d{4})/, "$3-$2-$1"))));
// первая смена паспорта
if (ageDude >= 20 && ageDude < 45) {
if (pssprtDate < pDate20) { return false; }
}
// вторая смена паспорта
if (ageDude >= 45) {
if (pssprtDate < pDate45) { return false; }
}
return true;
}
// разница в годах между текущей датой и @dt
function yearsDiff(dt)
{
if (dt > new Date()) { return 0; }
var crntDate = new Date();
var yearDiff = parseInt(crntDate.getFullYear() - dt.getFullYear());
// прошёл уже текущий год или ещё нет
var dat4check = new Date(dt);
dat4check.setFullYear(crntDate.getFullYear());
if (dat4check > crntDate) { yearDiff--; }
if (yearDiff <= 0) { return 0; }
if (yearDiff === 1)
{
var monthDiff = parseInt(crntDate.getMonth() - dt.getMonth());
if (monthDiff >= 0)
{
if (monthDiff == 0) {
var dayDiff = parseInt(crntDate.getDate() - dt.getDate());
if (dayDiff > 0) { return yearDiff; }
else { return 0; }
}
else {
return crntDate.getFullYear() - dt.getFullYear();
}
}
else { return 0; }
}
else { return yearDiff; }
}
Answer the question
In order to leave comments, you need to log in
Here dt is an object of type Date, considering how it is used in the code.
In general, see how the function you are interested in is called.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question