public Date calculate(int era, int year, int month, int day, int hours, int minutes, int secs, int millisecs, boolean addOneDay, TimeZone tz) { if (calendar == null) { calendar = new GregorianCalendar(tz, Locale.US); calendar.setLenient(false); calendar.setGregorianChange(new Date(Long.MIN_VALUE)); // never use Julian calendar } else { // At least on Java 6, calendar.getTimeZone is slow due to a bug, so we need lastlySetTimeZone. if (lastlySetTimeZone != tz) { // Deliberately `!=` instead of `!<...>.equals()` calendar.setTimeZone(tz); lastlySetTimeZone = tz; } } calendar.set(Calendar.ERA, era); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.HOUR_OF_DAY, hours); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.SECOND, secs); calendar.set(Calendar.MILLISECOND, millisecs); if (addOneDay) { calendar.add(Calendar.DAY_OF_MONTH, 1); } return calendar.getTime(); }
c = getCalendar(tz); c.setLenient(false); try { return convertToMillis(c, year, month, day, hour, minute, second, millis); c.setLenient(true); return convertToMillis(c, year, month, day, hour, minute, second, millis);
static GregorianCalendar newGreg() { GregorianCalendar retCal = new GregorianCalendar(Locale.ENGLISH); retCal.setTimeZone(new SimpleTimeZone(0, "UTC")); retCal.setLenient(false); retCal.set(Calendar.MILLISECOND, 0); return retCal; }
/** * Builds a new instance from a year/month/day specification. * * <p>This method is not lenient, i.e. '2014-12-32' will not be treated as '2015-01-01', but * instead throw an {@code IllegalArgumentException}. * * @param year the year in ISO format (see {@link LocalDate this class's Javadoc}). * @param month the month. It is 1-based (e.g. 1 for January). * @param dayOfMonth the day of the month. * @return the new instance. * @throws IllegalArgumentException if the corresponding date does not exist in the ISO8601 * calendar. */ public static LocalDate fromYearMonthDay(int year, int month, int dayOfMonth) { int calendarYear = (year <= 0) ? -year + 1 : year; int calendarEra = (year <= 0) ? GregorianCalendar.BC : GregorianCalendar.AD; GregorianCalendar calendar = isoCalendar(); // We can't allow leniency because that could mess with our year shift above (for example if the // arguments were 0, 12, 32) calendar.setLenient(false); calendar.clear(); calendar.set(calendarYear, month - 1, dayOfMonth, 0, 0, 0); calendar.set(Calendar.ERA, calendarEra); LocalDate date = fromMillisSinceEpoch(calendar.getTimeInMillis()); date.calendar = calendar; return date; }
public Date getStartDate() { Date date = null; if (startMonth > 0) { GregorianCalendar gc = new GregorianCalendar(startYear, startMonth - 1, startDay); gc.setLenient(true); date = new Date(gc.getTimeInMillis()); startYear = gc.get(Calendar.YEAR); startMonth = gc.get(Calendar.MONTH) + 1; startDay = gc.get(Calendar.DATE); } return date; }
static GregorianCalendar newGreg() { GregorianCalendar retCal = new GregorianCalendar(Locale.ENGLISH); retCal.setTimeZone(new SimpleTimeZone(0, "UTC")); retCal.setLenient(false); retCal.set(Calendar.MILLISECOND, 0); return retCal; }
/** * @param month January = 1 */ public static boolean isValidDate(final int year, final int month, final int day) { try { final GregorianCalendar cal = new GregorianCalendar(); cal.setLenient(false); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month - 1); cal.set(Calendar.DATE, day); cal.getTimeInMillis(); // throws Exception } catch (final Exception ex) { return false; } return true; }
static GregorianCalendar newGreg() { GregorianCalendar retCal = new GregorianCalendar(Locale.ENGLISH); retCal.setTimeZone(new SimpleTimeZone(0, "UTC")); retCal.setLenient(false); retCal.set(Calendar.MILLISECOND, 0); return retCal; }
/** * Method to set the lenient setting * @param lenient Whether it is lenient */ public void setLenient(boolean lenient) { super.setLenient(lenient); makeDirty(); }
static GregorianCalendar newGreg() { GregorianCalendar retCal = new GregorianCalendar(Locale.ENGLISH); retCal.setTimeZone(new SimpleTimeZone(0, "UTC")); retCal.setLenient(false); retCal.set(Calendar.MILLISECOND, 0); return retCal; }
public Date getEndDate(boolean increment) { Date date = null; if (endMonth > 0) { GregorianCalendar gc = new GregorianCalendar(endYear, endMonth - 1, endDay); gc.setLenient(true); endYear = gc.get(Calendar.YEAR); endMonth = gc.get(Calendar.MONTH) + 1; endDay = gc.get(Calendar.DATE); // The date should be incremented if we are comparing with timestamps, // because the default time of a date is 0:00:00:000 if (increment) gc.add(Calendar.DATE, 1); date = new Date(gc.getTimeInMillis()); } return date; }
public String toString(DateMask mask, DateSeparator separator, long date) { gc.setLenient(true); gc.clear(); gc.setTimeInMillis(date); int year = gc.get(Calendar.YEAR); int month = gc.get(Calendar.MONTH) + 1; int day = gc.get(Calendar.DAY_OF_MONTH); return toString(mask, separator, day, month, year); }
/** * Updates the dialog's controls with the passed in date. * * @param cal The date to be displayed. */ private void setDate(GregorianCalendar cal, boolean fromDateField) { date = cal; date.setLenient(false); ready = true; monthLabel.setText(monthNames.get(cal.get(Calendar.MONTH))); yearLabel.setText("" + cal.get(Calendar.YEAR)); dateField.setText(MMDDYYYY.format(date.getTime())); updateDayGrid(fromDateField); }
/** * Get a Java Calendar object corresponding to this time, on a reference date */ public GregorianCalendar getCalendar() { // create a calendar using the specified timezone int tz = (hasTimezone() ? getTimezoneInMinutes() : 0); TimeZone zone = new SimpleTimeZone(tz * 60000, "LLL"); GregorianCalendar calendar = new GregorianCalendar(zone); calendar.setLenient(false); // use a reference date of 1972-12-31 int year = 1972; int month = 11; int day = 31; calendar.set(year, month, day, hour, minute, second); calendar.set(Calendar.MILLISECOND, microsecond / 1000); calendar.set(Calendar.ZONE_OFFSET, tz * 60000); calendar.set(Calendar.DST_OFFSET, 0); calendar.getTime(); return calendar; }
/** * Get a Java Calendar object corresponding to this time, on a reference date */ public GregorianCalendar getCalendar() { // create a calendar using the specified timezone int tz = (hasTimezone() ? getTimezoneInMinutes() : 0); TimeZone zone = new SimpleTimeZone(tz * 60000, "LLL"); GregorianCalendar calendar = new GregorianCalendar(zone); calendar.setLenient(false); // use a reference date of 1972-12-31 int year = 1972; int month = 11; int day = 31; calendar.set(year, month, day, hour, minute, second); calendar.set(Calendar.MILLISECOND, microsecond / 1000); calendar.set(Calendar.ZONE_OFFSET, tz * 60000); calendar.set(Calendar.DST_OFFSET, 0); calendar.getTime(); return calendar; }
public GregorianCalendar getCalendar() { int tz = (hasTimezone() ? getTimezoneInMinutes() : 0); TimeZone zone = new SimpleTimeZone(tz * 60000, "LLL"); GregorianCalendar calendar = new GregorianCalendar(zone); calendar.setGregorianChange(new Date(Long.MIN_VALUE)); calendar.clear(); calendar.setLenient(false); int yr = year; if (year <= 0) { yr = 1 - year; calendar.set(Calendar.ERA, GregorianCalendar.BC); } calendar.set(yr, month - 1, day); calendar.set(Calendar.ZONE_OFFSET, tz * 60000); calendar.set(Calendar.DST_OFFSET, 0); calendar.getTime(); return calendar; }
private static Date createDate(GregorianCalendar cal, int tzOffset, boolean negative, int year, int month, int day, int hours, int minutes, int seconds, int milliseconds) { cal.setLenient(false); cal.setGregorianChange(new Date(Long.MIN_VALUE)); cal.clear(); // Using a time zone of "GMT+XX:YY" doesn't work with JDK 1.1, so we have to do it like this. cal.set(Calendar.ZONE_OFFSET, tzOffset); cal.set(Calendar.DST_OFFSET, 0); cal.set(Calendar.ERA, negative ? GregorianCalendar.BC : GregorianCalendar.AD); // months in ISO8601 start with 1; months in Java start with 0 month -= 1; cal.set(year, month, day, hours, minutes, seconds); cal.set(Calendar.MILLISECOND, milliseconds); checkDate(cal.isLeapYear(year), month, day); // for GCJ return cal.getTime(); }
public GregorianCalendar getCalendar() { int tz = (hasTimezone() ? getTimezoneInMinutes() : 0); TimeZone zone = new SimpleTimeZone(tz * 60000, "LLL"); GregorianCalendar calendar = new GregorianCalendar(zone); calendar.setGregorianChange(new Date(Long.MIN_VALUE)); calendar.clear(); calendar.setLenient(false); int yr = year; if (year <= 0) { yr = 1 - year; calendar.set(Calendar.ERA, GregorianCalendar.BC); } calendar.set(yr, month - 1, day); calendar.set(Calendar.ZONE_OFFSET, tz * 60000); calendar.set(Calendar.DST_OFFSET, 0); calendar.getTime(); return calendar; }
private static Date createDate(GregorianCalendar cal, int tzOffset, boolean negative, int year, int month, int day, int hours, int minutes, int seconds, int milliseconds) { cal.setLenient(false); cal.setGregorianChange(new Date(Long.MIN_VALUE)); cal.clear(); // Using a time zone of "GMT+XX:YY" doesn't work with JDK 1.1, so we have to do it like this. cal.set(Calendar.ZONE_OFFSET, tzOffset); cal.set(Calendar.DST_OFFSET, 0); cal.set(Calendar.ERA, negative ? GregorianCalendar.BC : GregorianCalendar.AD); // months in ISO8601 start with 1; months in Java start with 0 month -= 1; cal.set(year, month, day, hours, minutes, seconds); cal.set(Calendar.MILLISECOND, milliseconds); checkDate(cal.isLeapYear(year), month, day); // for GCJ return cal.getTime(); }
private static Date createDate(GregorianCalendar cal, int tzOffset, boolean negative, int year, int month, int day, int hours, int minutes, int seconds, int milliseconds) { cal.setLenient(false); cal.setGregorianChange(new Date(Long.MIN_VALUE)); cal.clear(); // Using a time zone of "GMT+XX:YY" doesn't work with JDK 1.1, so we have to do it like this. cal.set(Calendar.ZONE_OFFSET, tzOffset); cal.set(Calendar.DST_OFFSET, 0); cal.set(Calendar.ERA, negative ? GregorianCalendar.BC : GregorianCalendar.AD); // months in ISO8601 start with 1; months in Java start with 0 month -= 1; cal.set(year, month, day, hours, minutes, seconds); cal.set(Calendar.MILLISECOND, milliseconds); checkDate(cal.isLeapYear(year), month, day); // for GCJ return cal.getTime(); }