|
|
|
@ -30,10 +30,6 @@ public class DateTime {
|
|
|
|
|
this.timeZone = timeZone;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static DateTime now() {
|
|
|
|
|
return new DateTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime() {
|
|
|
|
|
this(DateTimeUtils.currentTimeMillis());
|
|
|
|
|
}
|
|
|
|
@ -70,10 +66,16 @@ public class DateTime {
|
|
|
|
|
return timestamp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime plusMonths(int interval) {
|
|
|
|
|
Calendar calendar = getCalendar();
|
|
|
|
|
calendar.add(Calendar.MONTH, interval);
|
|
|
|
|
return new DateTime(calendar);
|
|
|
|
|
public int getMillisOfDay() {
|
|
|
|
|
return (int) (timestamp - withMillisOfDay(0).getMillis());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getYear() {
|
|
|
|
|
return getCalendar().get(Calendar.YEAR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getMonthOfYear() {
|
|
|
|
|
return getCalendar().get(Calendar.MONTH) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getDayOfMonth() {
|
|
|
|
@ -84,24 +86,28 @@ public class DateTime {
|
|
|
|
|
return getCalendar().get(Calendar.DAY_OF_WEEK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime plusDays(int interval) {
|
|
|
|
|
return add(Calendar.DATE, interval);
|
|
|
|
|
public int getHourOfDay() {
|
|
|
|
|
return getCalendar().get(Calendar.HOUR_OF_DAY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getMinuteOfHour() {
|
|
|
|
|
return getCalendar().get(Calendar.MINUTE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isLastDayOfMonth() {
|
|
|
|
|
return getDayOfMonth() == getNumberOfDaysInMonth();
|
|
|
|
|
public int getSecondOfMinute() {
|
|
|
|
|
return getCalendar().get(Calendar.SECOND);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNumberOfDaysInMonth() {
|
|
|
|
|
return getCalendar().getActualMaximum(Calendar.DAY_OF_MONTH);
|
|
|
|
|
public DateTime withYear(int year) {
|
|
|
|
|
return with(Calendar.YEAR, year);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime withMillisOfSecond(int millisOfSecond) {
|
|
|
|
|
return with(Calendar.MILLISECOND, millisOfSecond);
|
|
|
|
|
public DateTime withMonthOfYear(int monthOfYear) {
|
|
|
|
|
return with(Calendar.MONTH, monthOfYear - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime withDayOfMonth(int dayOfMonth) {
|
|
|
|
|
return with(Calendar.DAY_OF_MONTH, dayOfMonth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime withHourOfDay(int hourOfDay) {
|
|
|
|
@ -116,68 +122,54 @@ public class DateTime {
|
|
|
|
|
return with(Calendar.SECOND, secondOfMinute);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getYear() {
|
|
|
|
|
return getCalendar().get(Calendar.YEAR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime minusMinutes(int minutes) {
|
|
|
|
|
return subtract(Calendar.MINUTE, minutes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isBefore(DateTime dateTime) {
|
|
|
|
|
return timestamp < dateTime.getMillis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getMillisOfDay() {
|
|
|
|
|
return (int) (timestamp - withMillisOfDay(0).getMillis());
|
|
|
|
|
public DateTime withMillisOfSecond(int millisOfSecond) {
|
|
|
|
|
return with(Calendar.MILLISECOND, millisOfSecond);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getMonthOfYear() {
|
|
|
|
|
return getCalendar().get(Calendar.MONTH) + 1;
|
|
|
|
|
public DateTime plusMonths(int interval) {
|
|
|
|
|
Calendar calendar = getCalendar();
|
|
|
|
|
calendar.add(Calendar.MONTH, interval);
|
|
|
|
|
return new DateTime(calendar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isAfter(DateTime dateTime) {
|
|
|
|
|
return timestamp > dateTime.getMillis();
|
|
|
|
|
public DateTime plusWeeks(int weeks) {
|
|
|
|
|
return add(Calendar.WEEK_OF_MONTH, weeks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime withYear(int year) {
|
|
|
|
|
return with(Calendar.YEAR, year);
|
|
|
|
|
public DateTime plusDays(int interval) {
|
|
|
|
|
return add(Calendar.DATE, interval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime withMonthOfYear(int monthOfYear) {
|
|
|
|
|
return with(Calendar.MONTH, monthOfYear - 1);
|
|
|
|
|
public DateTime plusHours(int hours) {
|
|
|
|
|
return add(Calendar.HOUR_OF_DAY, hours);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getHourOfDay() {
|
|
|
|
|
return getCalendar().get(Calendar.HOUR_OF_DAY);
|
|
|
|
|
public DateTime plusMinutes(int minutes) {
|
|
|
|
|
return add(Calendar.MINUTE, minutes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime withDayOfMonth(int dayOfMonth) {
|
|
|
|
|
return with(Calendar.DAY_OF_MONTH, dayOfMonth);
|
|
|
|
|
public DateTime minusDays(int days) {
|
|
|
|
|
return subtract(Calendar.DATE, days);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime plusMinutes(int minutes) {
|
|
|
|
|
return add(Calendar.MINUTE, minutes);
|
|
|
|
|
public DateTime minusMinutes(int minutes) {
|
|
|
|
|
return subtract(Calendar.MINUTE, minutes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime plusHours(int hours) {
|
|
|
|
|
return add(Calendar.HOUR_OF_DAY, hours);
|
|
|
|
|
public DateTime minusMillis(int millis) {
|
|
|
|
|
return new DateTime(timestamp - millis, timeZone);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime plusWeeks(int weeks) {
|
|
|
|
|
return add(Calendar.WEEK_OF_MONTH, weeks);
|
|
|
|
|
public boolean isAfter(DateTime dateTime) {
|
|
|
|
|
return timestamp > dateTime.getMillis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isBeforeNow() {
|
|
|
|
|
return timestamp < DateTimeUtils.currentTimeMillis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime minusMillis(int millis) {
|
|
|
|
|
return new DateTime(timestamp - millis, timeZone);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime minusDays(int days) {
|
|
|
|
|
return subtract(Calendar.DATE, days);
|
|
|
|
|
public boolean isBefore(DateTime dateTime) {
|
|
|
|
|
return timestamp < dateTime.getMillis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime toUTC() {
|
|
|
|
@ -188,6 +180,14 @@ public class DateTime {
|
|
|
|
|
return toTimeZone(TimeZone.getDefault());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isLastDayOfMonth() {
|
|
|
|
|
return getDayOfMonth() == getNumberOfDaysInMonth();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNumberOfDaysInMonth() {
|
|
|
|
|
return getCalendar().getActualMaximum(Calendar.DAY_OF_MONTH);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DateTime toTimeZone(TimeZone timeZone) {
|
|
|
|
|
Calendar current = getCalendar();
|
|
|
|
|
Calendar target = new GregorianCalendar(timeZone);
|
|
|
|
@ -195,10 +195,6 @@ public class DateTime {
|
|
|
|
|
return new DateTime(target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getSecondOfMinute() {
|
|
|
|
|
return getCalendar().get(Calendar.SECOND);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DateTime with(int field, int value) {
|
|
|
|
|
Calendar calendar = getCalendar();
|
|
|
|
|
calendar.set(field, value);
|
|
|
|
@ -251,12 +247,4 @@ public class DateTime {
|
|
|
|
|
public String toString() {
|
|
|
|
|
return toString("yyyy-MM-dd HH:mm:ss.SSSZ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getTimezoneOffset() {
|
|
|
|
|
return timeZone.getOffset(timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime plusMillis(int millis) {
|
|
|
|
|
return new DateTime(timestamp + millis, timeZone);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|