Liam
ee6456e4d8
Some checks failed
Deploy to Dokku / docker (ubuntu-latest) (push) Has been cancelled
47 lines
1.1 KiB
Java
47 lines
1.1 KiB
Java
package cc.fascinated.bat.features.birthday;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.Getter;
|
|
import lombok.NoArgsConstructor;
|
|
import lombok.Setter;
|
|
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
|
|
/**
|
|
* @author Fascinated (fascinated7)
|
|
*/
|
|
@AllArgsConstructor
|
|
@NoArgsConstructor
|
|
@Getter
|
|
@Setter
|
|
public class UserBirthday {
|
|
/**
|
|
* The user's birthday
|
|
*/
|
|
private Date birthday;
|
|
|
|
/**
|
|
* If the birthday should be hidden
|
|
*/
|
|
private boolean hidden;
|
|
|
|
/**
|
|
* Calculates the age of the user
|
|
*
|
|
* @return the age of the user
|
|
*/
|
|
public int calculateAge() {
|
|
Calendar birthdayCalendar = Calendar.getInstance();
|
|
birthdayCalendar.setTime(this.getBirthday());
|
|
Calendar today = Calendar.getInstance();
|
|
int age = today.get(Calendar.YEAR) - birthdayCalendar.get(Calendar.YEAR);
|
|
|
|
// Check if the birthday hasn't occurred yet this year
|
|
if (today.get(Calendar.DAY_OF_YEAR) < birthdayCalendar.get(Calendar.DAY_OF_YEAR)) {
|
|
age--;
|
|
}
|
|
return age;
|
|
}
|
|
}
|