35f5084005
git-subtree-dir: backend git-subtree-mainline:dc11190527git-subtree-split:acae976622
17 lines
391 B
Go
17 lines
391 B
Go
package utils
|
|
|
|
import "time"
|
|
|
|
// CalcAge سن رو از تاریخ تولد حساب میکنه (نسبت به الان)
|
|
func CalcAge(birthDate *time.Time) int {
|
|
if birthDate == nil {
|
|
return 0
|
|
}
|
|
now := time.Now()
|
|
age := now.Year() - birthDate.Year()
|
|
if now.Month() < birthDate.Month() || (now.Month() == birthDate.Month() && now.Day() < birthDate.Day()) {
|
|
age--
|
|
}
|
|
return age
|
|
}
|