package com.jingsong.constants;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import java.text.SimpleDateFormat;
import java.time.Month;
import java.util.Date;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class DateConstants {
public static final long MILLISECOND = 1L;
public static final long SECOND = 1000 * MILLISECOND;
public static final long MINUTE = 60 * SECOND;
public static final long HOUR = 60 * MINUTE;
public static final long DAY = 24 * HOUR;
public static final long WEEK = 7 * DAY;
public static final long MONTH_COMMON = 30 * DAY;
public static final long YEAR_COMMON = 365 * DAY;
public static long MONTH_LOCAL() {
return MONTH_LOCAL_DAYS() * DAY;
}
public static long YEAR_LOCAL() {
return YEAR_LOCAL_DAYS() * DAY;
}
public static int MONTH_LOCAL_DAYS(){
String monthStr = new SimpleDateFormat("MM").format(new Date());
int thisMonth = Integer.valueOf(monthStr);
Month month = Month.JULY;
for (Month each : Month.values()) {
if (each.getValue() == thisMonth) {
month = each;
break;
}
}
return month.length(isLeapYear());
}
public static int YEAR_LOCAL_DAYS(){
return isLeapYear() ? 366 : 365;
}
private static boolean isLeapYear() {
String yearStr = new SimpleDateFormat("yyyy").format(new Date());
int thisYear = Integer.valueOf(yearStr);
return (thisYear % 4 == 0 && thisYear % 100 != 0) || (thisYear % 400 == 0);
}
}