|
|
|
@ -17,44 +17,44 @@ public class Year { |
|
|
|
public Year(int year) { |
|
|
|
public Year(int year) { |
|
|
|
this(year, Locale.getDefault()); |
|
|
|
this(year, Locale.getDefault()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Year(int year, Locale locale) { |
|
|
|
public Year(int year, Locale locale) { |
|
|
|
if (year < 1900 || year >2100) { |
|
|
|
if (year < 1900 || year > 2100) { |
|
|
|
throw new IllegalArgumentException("Year value must be between 1900 and 2100"); |
|
|
|
throw new IllegalArgumentException("Year value must be between 1900 and 2100"); |
|
|
|
} |
|
|
|
} |
|
|
|
this.date = LocalDate.of(year, 1, 1); |
|
|
|
this.date = LocalDate.of(year, 1, 1); |
|
|
|
this.locale = locale; |
|
|
|
this.locale = locale; |
|
|
|
this.monthWeeks = new HashMap<>(); |
|
|
|
this.monthWeeks = new HashMap<>(); |
|
|
|
for (Month m: Month.values()) { |
|
|
|
for (Month m : Month.values()) { |
|
|
|
monthWeeks.put(m, new WeeksOfMonth(m, year)); |
|
|
|
monthWeeks.put(m, new WeeksOfMonth(m, year)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getYear() { |
|
|
|
public int getYear() { |
|
|
|
return date.getYear(); |
|
|
|
return date.getYear(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public CharSequence getMonth(Month month) { |
|
|
|
public CharSequence getMonth(Month month) { |
|
|
|
return month.getDisplayName(TextStyle.FULL_STANDALONE, locale); |
|
|
|
return month.getDisplayName(TextStyle.FULL_STANDALONE, locale); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Day of month, numeric for the specified by parameters. |
|
|
|
* Day of month, numeric for the specified by parameters. |
|
|
|
* @param month month of the day |
|
|
|
* |
|
|
|
* @param week 1-6th week of the month |
|
|
|
* @param month month of the day |
|
|
|
* @param dayOfWeek weekday of the week in the month. |
|
|
|
* @param week 1-6th week of the month |
|
|
|
* @return numeric value of the day of the month. |
|
|
|
* @param dayOfWeek weekday of the week in the month. |
|
|
|
|
|
|
|
* @return numeric value of the day of the month. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String getDay(Month month, short week, DayOfWeek dayOfWeek) { |
|
|
|
public String getDay(Month month, short week, DayOfWeek dayOfWeek) { |
|
|
|
|
|
|
|
|
|
|
|
WeeksOfMonth weeksOfMonth = monthWeeks.get(month); |
|
|
|
WeeksOfMonth weeksOfMonth = monthWeeks.get(month); |
|
|
|
if (week >= weeksOfMonth.weekCount()) { |
|
|
|
if (week > weeksOfMonth.weekCount()) { |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
Integer res = weeksOfMonth.getWeek(week - 1).get(dayOfWeek); |
|
|
|
Integer res = weeksOfMonth.getWeek(week - 1).get(dayOfWeek); |
|
|
|
|
|
|
|
|
|
|
|
return res == null ? "" : res.toString(); |
|
|
|
return res == null ? "" : res.toString(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|