We need age, and it better show debugging info.
This commit is contained in:
parent
7ae12fd42f
commit
9d064a5a36
@ -3,13 +3,16 @@ package pl.amu.edu.demo.data;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@FieldDefaults(level = AccessLevel.PUBLIC, makeFinal = true)
|
||||
@Builder
|
||||
@ToString
|
||||
public class Person {
|
||||
String displayName;
|
||||
String firstName;
|
||||
@ -17,4 +20,17 @@ public class Person {
|
||||
LocalDate birthDate;
|
||||
Housing housing;
|
||||
boolean isMarried;
|
||||
|
||||
public int getAge() {
|
||||
var birthYear = Objects.requireNonNull(birthDate).getYear();
|
||||
var now = LocalDate.now();
|
||||
var baseDifference = now.getYear() - birthYear;
|
||||
if (birthDate.getMonthValue() > now.getMonthValue() ||
|
||||
(birthDate.getMonthValue() == now.getMonthValue() &&
|
||||
birthDate.getDayOfMonth() >= now.getDayOfMonth())) {
|
||||
return baseDifference;
|
||||
}
|
||||
return baseDifference - 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user