/** * @param label Label as prefix * @param date * @return <label>: <date> */ public static String getUTCDate(final String label, final Date date) { if (date == null) { return label + ":"; } final DateHolder dh = new DateHolder(date); return label + ": " + DateHelper.TECHNICAL_ISO_UTC.get().format(dh.getDate()); }
@Override public Object clone() { final DateHolder res = new DateHolder(); res.calendar = (Calendar) this.calendar.clone(); // res.calendar.setTime(this.calendar.getTime()); res.precision = this.precision; return res; }
@Override public boolean equals(final Object obj) { if (obj instanceof DateHolder) { final DateHolder other = (DateHolder) obj; if (other.getTimeInMillis() == getTimeInMillis() && other.getPrecision() == getPrecision()) { return true; } } return false; }
@Override public SearchFilter setStopTimeOfModification(final Date stopTimeOfLastModification) { if (stopTimeOfLastModification == null) { super.setStopTimeOfModification(null); return this; } final DateHolder dh = new DateHolder(stopTimeOfLastModification, DatePrecision.MILLISECOND); dh.setEndOfDay(); super.setStopTimeOfModification(dh.getDate()); return this; }
/** * @param startTime Start time or null. * @param stopTime Stop time or null. */ public static String getUTCDates(final Date startTime, final Date stopTime) { final StringBuffer buf = new StringBuffer(); final DateHolder start = startTime != null ? new DateHolder(startTime) : null; final DateHolder stop = stopTime != null ? new DateHolder(stopTime) : null; if (start != null) { buf.append(DateHelper.TECHNICAL_ISO_UTC.get().format(start.getDate())); if (stop != null) { buf.append(" - "); } } if (stop != null) { buf.append(DateHelper.TECHNICAL_ISO_UTC.get().format(stop.getDate())); } return buf.toString(); }
private void calculate() { DateHolder dateHolder = new DateHolder(cal, DatePrecision.DAY); year = dateHolder.getYear(); month = dateHolder.getMonth(); dateHolder.setBeginOfMonth(); begin = dateHolder.getDate(); // Storing begin of month. dateHolder.setEndOfMonth(); end = dateHolder.getDate(); // Storing end of month. dateHolder.setDate(begin); // reset to begin of month dateHolder.computeTime(); dateHolder.setBeginOfWeek(); // get first week (with days of previous month) weeks = new ArrayList<WeekHolder>(); do { WeekHolder week = new WeekHolder(dateHolder.getCalendar(), month); weeks.add(week); dateHolder.add(Calendar.WEEK_OF_YEAR, 1); } while (dateHolder.getMonth() == month); }
private void assertFields(final DateHolder day) { assertEquals("Hours of day should be 0", 0, day.getHourOfDay()); assertEquals("Minutes should be 0", 0, day.getMinute()); assertEquals("Seconds should be 0", 0, day.getSecond()); assertEquals("Millis should be 0", 0, day.getMilliSecond()); }
private TimesheetDO createNewSheet() { return new TimesheetDO() .setUser(getUser(TEST_USER)) .setStartDate(date.getDate()) .setStopTime(date.add(Calendar.MINUTE, 15).getTimestamp()); }
/** * Stops calculation for more than 500 years. * * @param other * @return other.days - this.days. */ public int daysBetween(final Date other) { final DateHolder o = new DateHolder(calendar); o.setDate(other); return daysBetween(o); }
public int daysBetween(final DateHolder other) { final DateHolder from, to; if (this.getTimeInMillis() < other.getTimeInMillis()) { from = this; to = other; } else { from = other; to = this; } int result = 0; final int toYear = to.getYear(); final DateHolder dh = new DateHolder(from.getDate()); int endlessLoopProtection = 0; while (dh.getYear() < toYear) { final int fromDay = dh.getDayOfYear(); dh.setMonth(Calendar.DECEMBER); dh.setDayOfMonth(31); result += dh.getDayOfYear() - fromDay + 1; dh.add(Calendar.DAY_OF_MONTH, 1); if (++endlessLoopProtection > 5000) { throw new IllegalArgumentException("Days between doesn's support more than 5000 years"); } } result += to.getDayOfYear() - dh.getDayOfYear(); if (this.getTimeInMillis() < other.getTimeInMillis()) { return result; } else { return -result; } }
/** * Has the given date the same day? The given date will be converted into a calendar (clone from * this) with same time zone. * * @param date * @return */ public boolean isSameDay(final DateHolder date) { return getYear() == date.getYear() && getDayOfYear() == date.getDayOfYear(); }
/** * Has the given date the same day? The given date will be converted into a calendar (clone from * this) with same time zone. * * @param date * @return */ public boolean isSameDay(final Date date) { final DateHolder other = new DateHolder(this.calendar); other.setDate(date); return isSameDay(other); }
public boolean isBetween(final DateHolder from, final DateHolder to) { final Date fromDate = from != null ? from.getDate() : null; final Date toDate = to != null ? to.getDate() : null; return isBetween(fromDate, toDate); }
public boolean after(final DateHolder date) { return this.getDate().after(date.getDate()); }
public boolean before(final DateHolder date) { return this.getDate().before(date.getDate()); }