List of usage examples for java.util Calendar equals
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass") @Override public boolean equals(Object obj)
Calendar
to the specified Object
. From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // specify a date for one of them Calendar cal2 = new GregorianCalendar(2013, 06, 29); // compare the two calendars. boolean b = cal.equals(cal2); // print result System.out.println("Calendars are equal :" + b); }
From source file:fr.itinerennes.bundler.integration.onebusaway.GenerateStaticObaApiResults.java
public static void main(String[] args) throws IOException, GtfsException { final String url = args[0]; final String key = args[1]; final String gtfsFile = args[2]; final String out = args[3].replaceAll("/$", ""); final Map<String, String> agencyMapping = new HashMap<String, String>(); agencyMapping.put("1", "2"); final GtfsDao gtfs = GtfsUtils.load(new File(gtfsFile), agencyMapping); oba = new JsonOneBusAwayClient(new DefaultHttpClient(), url, key); gson = OneBusAwayGsonFactory.newInstance(true); final Calendar end = Calendar.getInstance(); end.set(2013, 11, 22, 0, 0);//from ww w . j av a2s. c om final Calendar start = Calendar.getInstance(); start.set(2013, 10, 4, 0, 0); final Calendar current = Calendar.getInstance(); current.setTime(start.getTime()); while (current.before(end) || current.equals(end)) { System.out.println(current.getTime()); for (final Stop stop : gtfs.getAllStops()) { final String stopId = stop.getId().toString(); final String dateDir = String.format("%04d/%02d/%02d", current.get(Calendar.YEAR), current.get(Calendar.MONTH) + 1, current.get(Calendar.DAY_OF_MONTH)); final String methodDir = String.format("%s/schedule-for-stop", out); final File outDir = new File(String.format("%s/%s", methodDir, dateDir)); outDir.mkdirs(); final File f = new File(outDir, String.format("%s.json", stopId)); final StopSchedule ss = oba.getScheduleForStop(stopId, current.getTime()); final String json = gson.toJson(ss); final Writer w = new PrintWriter(f); w.write(json); w.close(); } current.add(Calendar.DAY_OF_MONTH, 1); } final File outDir = new File(String.format("%s/trip-details", out)); outDir.mkdirs(); for (final Trip trip : gtfs.getAllTrips()) { final String tripId = trip.getId().toString(); final File f = new File(outDir, String.format("%s.json", tripId)); final TripSchedule ts = oba.getTripDetails(tripId); final String json = gson.toJson(ts); final Writer w = new PrintWriter(f); w.write(json); w.close(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyy"); Date date1 = sdf.parse("Thu Oct 03 07:47:22 2015"); Date date2 = sdf.parse("Mon Jul 05 08:47:22 2015"); System.out.println(sdf.format(date1)); System.out.println(sdf.format(date2)); Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(date1);//ww w. j ava2 s . c o m cal2.setTime(date2); if (cal1.after(cal2)) { System.out.println("Date1 is after Date2"); } if (cal1.before(cal2)) { System.out.println("Date1 is before Date2"); } if (cal1.equals(cal2)) { System.out.println("Date1 is equal Date2"); } }
From source file:Main.java
public static String formatDateDiff(Calendar fromDate, Calendar toDate) { boolean future = false; if (toDate.equals(fromDate)) { return ("now"); }//from w ww.jav a2 s . com if (toDate.after(fromDate)) { future = true; } StringBuilder sb = new StringBuilder(); int[] types = new int[] { Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND }; String[] names = new String[] { ("year"), ("years"), ("month"), ("months"), ("day"), ("days"), ("hour"), ("hours"), ("minute"), ("minutes"), ("second"), ("seconds") }; int accuracy = 0; for (int i = 0; i < types.length; i++) { if (accuracy > 2) { break; } int diff = dateDiff(types[i], fromDate, toDate, future); if (diff > 0) { accuracy++; sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]); } } if (sb.length() == 0) { return "now"; } return sb.toString().trim(); }
From source file:Main.java
/** * Null-safe version of date equality.//w ww .j av a 2 s . c o m * * @param c1 the first date * @param c2 the second date * @return true if equal, false if not */ public static boolean dateEquals(Calendar c1, Calendar c2) { if (c1 == null || c2 == null) return c1 == c2; else return c1.equals(c2); }
From source file:nl.strohalm.cyclos.utils.DateHelper.java
/** * checks if the two dates are on the same calendar day. *//*from www . j av a2s. co m*/ public static boolean sameDay(final Calendar first, final Calendar second) { final Calendar equalizedFirst = DateHelper.equalizeTime(first, second); return (equalizedFirst.equals(second)); }
From source file:nl.strohalm.cyclos.utils.DateHelper.java
/** * compares two Calendars on a certain precision level. <br> * For example, if you had the datetime of 12 Mar 2011 14:31:07.847, and a second datetime of 12 Mar 2011 14:31:11.734, they would evaluate as * equal on the Calendar.MINUTE level and above. They would evaluate as not equal on levels Calendar.SECOND and Calendar.MILLISECOND.<br> * Fields are rounded, so 12 Mar 2011 14:31:07.847 and 12 Mar 2011 14:31:08.123 would evaluate as equal on the Calendar.SECOND level. * @param cal1 if null, returns false// w ww.ja v a 2 s . com * @param cal2 if null, returns false * @param level, for example Calendar.MINUTE * @return true if equal on this level, false if not. */ public static boolean equals(final Calendar cal1, final Calendar cal2, final int level) { if (cal1 == null || cal2 == null) { return false; } final Calendar temp1 = DateUtils.round((Calendar) cal1.clone(), level); final Calendar temp2 = DateUtils.round((Calendar) cal2.clone(), level); return (temp1.equals(temp2)); }
From source file:com.sun.japex.report.ChartGenerator.java
/** * Compare two calendar instances from test suite reports ignoring * the time of the day.//from w ww . j a v a 2 s. c om */ static protected boolean onSameDate(TestSuiteReport r1, TestSuiteReport r2) { Calendar cc1 = (Calendar) r1.getDate().clone(); cc1.set(HOUR_OF_DAY, 0); cc1.set(MINUTE, 0); cc1.set(SECOND, 0); Calendar cc2 = (Calendar) r2.getDate().clone(); cc2.set(HOUR_OF_DAY, 0); cc2.set(MINUTE, 0); cc2.set(SECOND, 0); return cc1.equals(cc2); }
From source file:org.nuxeo.ecm.directory.sql.SQLDirectoryTestSuite.java
License:asdf
public static void assertCalendarEquals(Calendar expected, Calendar actual) throws Exception { if (expected.equals(actual)) { return;/* w w w .ja v a 2 s.c om*/ } // try without milliseconds for stupid MySQL if (stripMillis(expected).equals(stripMillis(actual))) { return; } assertEquals(expected, actual); // proper failure }
From source file:fr.paris.lutece.plugins.calendar.service.Utils.java
/** * Returns a date code corresponding to a calendar roll of one month * @param dateStart The date start// w ww . ja va 2s . c om * @param dateEnd The date end * @param arrayExcludedDays list of excluded days * @return A date code incremented with strDateRef parameter */ public static int getOccurrenceWithinTwoDates(Date dateStart, Date dateEnd, String[] arrayExcludedDays) { int cptDate = 0; Calendar calendar1 = new GregorianCalendar(); Calendar calendar2 = new GregorianCalendar(); calendar1.setTime(dateStart); calendar2.setTime(dateEnd); if (calendar1.equals(calendar2)) { String strDate = getDate(dateStart); if (isDayExcluded(getDayOfWeek(strDate), arrayExcludedDays)) { return cptDate; } return ++cptDate; } while (!calendar1.after(calendar2)) { if (!isDayExcluded(calendar1.get(Calendar.DAY_OF_WEEK), arrayExcludedDays)) { ++cptDate; } calendar1.add(Calendar.DATE, 1); } return cptDate; }