Refine search
/** * Gets the string that says how long since this build has started. * * @return * string like "3 minutes" "1 day" etc. */ public @Nonnull String getTimestampString() { long duration = new GregorianCalendar().getTimeInMillis()-timestamp; return Util.getPastTimeString(duration); }
/** * Sets the gregorian calendar day of the month for this {@code Date} object. * * @param day * the day of the month. * * @deprecated Use {@code Calendar.set(Calendar.DATE, day)} instead. */ @Deprecated public void setDate(int day) { GregorianCalendar cal = new GregorianCalendar(milliseconds); cal.set(Calendar.DATE, day); milliseconds = cal.getTimeInMillis(); }
/** * Sets the gregorian calendar year since 1900 for this {@code Date} object. * * @param year * the year since 1900. * * @deprecated Use {@code Calendar.set(Calendar.YEAR, year + 1900)} instead. */ @Deprecated public void setYear(int year) { GregorianCalendar cal = new GregorianCalendar(milliseconds); cal.set(Calendar.YEAR, year + 1900); milliseconds = cal.getTimeInMillis(); }
/** * Sets the gregorian calendar hour of the day for this {@code Date} object. * * @param hour * the hour of the day. * * @deprecated Use {@code Calendar.set(Calendar.HOUR_OF_DAY, hour)} instead. */ @Deprecated public void setHours(int hour) { GregorianCalendar cal = new GregorianCalendar(milliseconds); cal.set(Calendar.HOUR_OF_DAY, hour); milliseconds = cal.getTimeInMillis(); }
/** * Sets the gregorian calendar second of the minute for this {@code Date} object. * * @param second * the seconds. * * @deprecated Use {@code Calendar.set(Calendar.SECOND, second)} instead. */ @Deprecated public void setSeconds(int second) { GregorianCalendar cal = new GregorianCalendar(milliseconds); cal.set(Calendar.SECOND, second); milliseconds = cal.getTimeInMillis(); }
/** * Sets the gregorian calendar minute of the hour for this {@code Date} object. * * @param minute * the minutes. * * @deprecated Use {@code Calendar.set(Calendar.MINUTE, minute)} instead. */ @Deprecated public void setMinutes(int minute) { GregorianCalendar cal = new GregorianCalendar(milliseconds); cal.set(Calendar.MINUTE, minute); milliseconds = cal.getTimeInMillis(); }
/** * Sets the gregorian calendar month for this {@code Date} object. * * @param month * the month. * * @deprecated Use {@code Calendar.set(Calendar.MONTH, month)} instead. */ @Deprecated public void setMonth(int month) { GregorianCalendar cal = new GregorianCalendar(milliseconds); cal.set(Calendar.MONTH, month); milliseconds = cal.getTimeInMillis(); }
/** * Returns a human-readable string representation of when this user was last active. */ public String getLastChangeTimeString() { if(lastChange==null) return "N/A"; long duration = new GregorianCalendar().getTimeInMillis()- ordinal(); return Util.getTimeSpanString(duration); }
/** * Constructs a new {@code Date} initialized to midnight in the default {@code TimeZone} on * the specified date. * * @param year * the year, 0 is 1900. * @param month * the month, 0 - 11. * @param day * the day of the month, 1 - 31. * * @deprecated Use {@link GregorianCalendar#GregorianCalendar(int, int, int)} instead. */ @Deprecated public Date(int year, int month, int day) { GregorianCalendar cal = new GregorianCalendar(false); cal.set(1900 + year, month, day); milliseconds = cal.getTimeInMillis(); }
public static long dateInSeconds(String timeZoneId, int year, int month, int day, int hour, int minute, int second) { TimeZone timeZone = TimeZone.getTimeZone(timeZoneId); GregorianCalendar calendar = new GregorianCalendar(year, month, day, hour, minute, second); calendar.setTimeZone(timeZone); return calendar.getTimeInMillis() / 1000; }
/** * Constructs a new {@code Date} initialized to the specified date and time in the * default {@code TimeZone}. * * @param year * the year, 0 is 1900. * @param month * the month, 0 - 11. * @param day * the day of the month, 1 - 31. * @param hour * the hour of day, 0 - 23. * @param minute * the minute of the hour, 0 - 59. * * @deprecated Use {@link GregorianCalendar#GregorianCalendar(int, int, int, int, int)} instead. */ @Deprecated public Date(int year, int month, int day, int hour, int minute) { GregorianCalendar cal = new GregorianCalendar(false); cal.set(1900 + year, month, day, hour, minute); milliseconds = cal.getTimeInMillis(); }
/** * Constructs a new {@code Date} initialized to the specified date and time in the * default {@code TimeZone}. * * @param year * the year, 0 is 1900. * @param month * the month, 0 - 11. * @param day * the day of the month, 1 - 31. * @param hour * the hour of day, 0 - 23. * @param minute * the minute of the hour, 0 - 59. * @param second * the second of the minute, 0 - 59. * * @deprecated Use {@link GregorianCalendar#GregorianCalendar(int, int, int, int, int, int)} * instead. */ @Deprecated public Date(int year, int month, int day, int hour, int minute, int second) { GregorianCalendar cal = new GregorianCalendar(false); cal.set(1900 + year, month, day, hour, minute, second); milliseconds = cal.getTimeInMillis(); }
/** * Given a start time, computes the next time when the wallclock will reach * a certain hour of the day, on a certain day of the week Eg: From today, * when is the next Saturday, 12PM ? * * @param startTime start time * @param targetDay day of the week to choose * @param targetHour hour of the day to choose * @return calendar object representing the target time */ public static GregorianCalendar getCalendarForNextRun(GregorianCalendar startTime, int targetDay, int targetHour) { long startTimeMs = startTime.getTimeInMillis(); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(startTimeMs); // adjust time to targetHour on startDay cal.set(Calendar.HOUR_OF_DAY, targetHour); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); // check if we are past the targetHour for the current day if(cal.get(Calendar.DAY_OF_WEEK) != targetDay || cal.getTimeInMillis() < startTimeMs) { do { cal.add(Calendar.DAY_OF_YEAR, 1); } while(cal.get(Calendar.DAY_OF_WEEK) != targetDay); } return cal; }
/** * Reduce the size of the list by only leaving relatively new ones. * This also removes on-going builds, as RSS cannot be used to publish information * if it changes. * <em>Warning:</em> this method mutates the original list and then returns it. */ public RunList<R> newBuilds() { GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.DAY_OF_YEAR, -7); final long t = cal.getTimeInMillis(); // can't publish on-going builds return filter(new Predicate<R>() { public boolean apply(R r) { return !r.isBuilding(); } }) // put at least 10 builds, but otherwise ignore old builds .limit(new CountingPredicate<R>() { public boolean apply(int index, R r) { return index < 10 || r.getTimeInMillis() >= t; } }); } }
/** * Returns the millisecond value of the specified date and time in GMT. * * @param year * the year, 0 is 1900. * @param month * the month, 0 - 11. * @param day * the day of the month, 1 - 31. * @param hour * the hour of day, 0 - 23. * @param minute * the minute of the hour, 0 - 59. * @param second * the second of the minute, 0 - 59. * @return the date and time in GMT in milliseconds. * * @deprecated Use code like this instead:<code> * Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); * cal.set(year + 1900, month, day, hour, minute, second); * cal.getTime().getTime();</code> */ @Deprecated public static long UTC(int year, int month, int day, int hour, int minute, int second) { GregorianCalendar cal = new GregorianCalendar(false); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.set(1900 + year, month, day, hour, minute, second); return cal.getTimeInMillis(); }
private static long utcTimeSeconds(int year, int month, int day, int hour, int min, int secs) { GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); calendar.set(year, month, day, hour, min, secs); return calendar.getTimeInMillis() / 1000; }
GregorianCalendar calendar = new GregorianCalendar(getGMT()); calendar.setTimeInMillis(instant); calendar.set(Calendar.MONTH, iMonthOfYear - 1); if (calendar.getTimeInMillis() <= instant) { calendar.add(Calendar.YEAR, 1); setDayOfMonthNext(calendar); if (calendar.getTimeInMillis() <= instant) { calendar.add(Calendar.YEAR, 1); calendar.set(Calendar.MONTH, iMonthOfYear - 1); return calendar.getTimeInMillis() - offset;
GregorianCalendar calendar = new GregorianCalendar(getGMT()); calendar.setTimeInMillis(instant); calendar.set(Calendar.MONTH, iMonthOfYear - 1); if (calendar.getTimeInMillis() >= instant) { calendar.add(Calendar.YEAR, -1); setDayOfMonthPrevious(calendar); if (calendar.getTimeInMillis() >= instant) { calendar.add(Calendar.YEAR, -1); calendar.set(Calendar.MONTH, iMonthOfYear - 1); return calendar.getTimeInMillis() - offset;
GregorianCalendar gc = new GregorianCalendar(); gc.set(year, month, day, hh, mm, ss); gc.setTimeZone(GMT); return gc.getTimeInMillis();
@Test public void maxValue() { TimeZone tz = TimeZone.getTimeZone("UTC"); GregorianCalendar calendar = new GregorianCalendar(tz); calendar.set(9999, Calendar.DECEMBER, 31, 23, 59, 59); java.sql.Timestamp expectedMin = new java.sql.Timestamp(calendar.getTimeInMillis()); expectedMin.setNanos(999999999); assertThat(Timestamp.MAX_VALUE.getSeconds()).isEqualTo(calendar.getTimeInMillis() / 1000L); assertThat(Timestamp.MAX_VALUE.getNanos()).isEqualTo(999999999); }