All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.darwinsys.util.DateSimple Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy