add function to calculate age with yob
This commit is contained in:
parent
674fd5773a
commit
2a5f7517f4
@ -19,4 +19,17 @@ func CalculateAge(birthdate, today time.Time) int {
|
|||||||
age--
|
age--
|
||||||
}
|
}
|
||||||
return age
|
return age
|
||||||
|
}
|
||||||
|
|
||||||
|
// CalculateAgeWithYOB calculates the age based on the given year of birth (YOB).
|
||||||
|
// It subtracts the YOB from the current year to determine the age.
|
||||||
|
//
|
||||||
|
// Parameters:
|
||||||
|
// yob: The year of birth as an integer.
|
||||||
|
//
|
||||||
|
// Returns:
|
||||||
|
// The calculated age as an integer.
|
||||||
|
func CalculateAgeWithYOB(yob int) int {
|
||||||
|
currentYear := time.Now().Year()
|
||||||
|
return currentYear - yob
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user