com.softicar.platform.common.date.YearType Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.date;
/**
* Enumeration of the types of years.
*
* There are only two types of years: leap and non-leap years, where a leap year
* contains an additional 29th day in February.
*
* @author Oliver Richers
*/
public enum YearType {
LEAP,
NON_LEAP;
/**
* Returns the type of the year with the specified index.
*
* @param year
* the absolute index of the year
* @return the type of the year
*/
public static YearType getForYear(int year) {
boolean isLeap = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
return isLeap? LEAP : NON_LEAP;
}
/**
* Returns the day count of this type of year.
*
* @return the number of days
*/
public int getDayCount() {
return this == LEAP? 366 : 365;
}
}