import java.util.Calendar;
import java.util.Date;
+import java.util.Locale;
-public class SimpleDate {
- public int year;
- public int month;
- public int day;
+public class SimpleDate implements Comparable<SimpleDate> {
+ public final int year;
+ public final int month;
+ public final int day;
public SimpleDate(int y, int m, int d) {
year = y;
month = m;
if (date == null)
return false;
- if (year != date.year)
- return false;
- if (month != date.month)
- return false;
- if (day != date.day)
- return false;
-
- return true;
+ return ((year == date.year) && (month == date.month) && (day == date.day));
}
public boolean earlierThan(@NonNull SimpleDate date) {
if (year < date.year)
return false;
return (day > date.day);
}
+ public int compareTo(SimpleDate date) {
+ int res = Integer.compare(year, date.year);
+ if (res != 0)
+ return res;
+
+ res = Integer.compare(month, date.month);
+ if (res != 0)
+ return res;
+
+ return Integer.compare(day, date.day);
+ }
+ public Calendar asCalendar() {
+ final Calendar calendar = Calendar.getInstance();
+ calendar.set(year, month, day);
+ return calendar;
+ }
+ public String toString() {
+ return String.format(Locale.US, "%d-%02d-%02d", year, month, day);
+ }
}