com.darwinsys.util.DateSimple Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of darwinsys-api Show documentation
Show all versions of darwinsys-api Show documentation
Ian Darwin's assorted Java stuff,
assembled as an API.
package com.darwinsys.util;
import java.util.Calendar;
import java.util.GregorianCalendar;
/**
* DateSimple represents YYYY-MM-DD without all the overhead and
* deprecated baggage of java.util.Date.
* Objects of this type are immutable.
*/
@Deprecated // Use Java 8 date/time API
public class DateSimple {
int year;
int month;
int day;
/**
* @param year The year
* @param month The Month
* @param day The Day of Month
*/
public DateSimple(int year, int month, int day) {
super();
this.year = year;
this.month = month;
this.day = day;
}
public DateSimple() {
Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
}
public int getDay() {
return day;
}
public int getMonth() {
return month;
}
public int getYear() {
return year;
}
public Calendar getCalendar() {
return new GregorianCalendar(year, month, day);
}
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof DateSimple)) {
return false;
}
DateSimple d = (DateSimple) obj;
return year == d.year && month == d.month && day == d.day;
}
@Override
public int hashCode() {
return year<<16 | month << 8 | day;
}
}