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.AccessLevel;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
|
import lombok.ToString;
|
||||||
import lombok.experimental.FieldDefaults;
|
import lombok.experimental.FieldDefaults;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
@FieldDefaults(level = AccessLevel.PUBLIC, makeFinal = true)
|
@FieldDefaults(level = AccessLevel.PUBLIC, makeFinal = true)
|
||||||
@Builder
|
@Builder
|
||||||
|
@ToString
|
||||||
public class Person {
|
public class Person {
|
||||||
String displayName;
|
String displayName;
|
||||||
String firstName;
|
String firstName;
|
||||||
@ -17,4 +20,17 @@ public class Person {
|
|||||||
LocalDate birthDate;
|
LocalDate birthDate;
|
||||||
Housing housing;
|
Housing housing;
|
||||||
boolean isMarried;
|
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