List of usage examples for java.util Calendar roll
public void roll(int field, int amount)
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // display the current calendar System.out.println("Month is " + cal.get(Calendar.MONTH)); // roll month cal.roll(Calendar.MONTH, 2); // print result after rolling System.out.println("Month is " + cal.get(Calendar.MONTH)); // roll downwards cal.roll(Calendar.MONTH, -4); // print result System.out.println("Month is " + cal.get(Calendar.MONTH)); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // displays the current calendar System.out.println("Month is " + cal.get(Calendar.MONTH)); // roll month cal.roll(Calendar.MONTH, true); // print result after rolling System.out.println("Month is " + cal.get(Calendar.MONTH)); // roll downwards cal.roll(Calendar.MONTH, false); // print result after rolling down System.out.println("Month is " + cal.get(Calendar.MONTH)); }
From source file:test.Testing.java
public static void main(String[] args) throws Exception { //////////////////////////////////////////////////////////////////////////////////////////// // Setup/*w ww. jav a 2s . c o m*/ //////////////////////////////////////////////////////////////////////////////////////////// String key = "CHANGEME: YOUR_API_KEY"; String secret = "CHANGEME: YOUR_API_SECRET"; String version = "preview1"; String practiceid = "000000"; APIConnection api = new APIConnection(version, key, secret, practiceid); api.authenticate(); // If you want to set the practice ID after construction, this is how. // api.setPracticeID("000000"); //////////////////////////////////////////////////////////////////////////////////////////// // GET without parameters //////////////////////////////////////////////////////////////////////////////////////////// JSONArray customfields = (JSONArray) api.GET("/customfields"); System.out.println("Custom fields:"); for (int i = 0; i < customfields.length(); i++) { System.out.println("\t" + customfields.getJSONObject(i).get("name")); } //////////////////////////////////////////////////////////////////////////////////////////// // GET with parameters //////////////////////////////////////////////////////////////////////////////////////////// SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); Calendar today = Calendar.getInstance(); Calendar nextyear = Calendar.getInstance(); nextyear.roll(Calendar.YEAR, 1); Map<String, String> search = new HashMap<String, String>(); search.put("departmentid", "82"); search.put("startdate", format.format(today.getTime())); search.put("enddate", format.format(nextyear.getTime())); search.put("appointmenttypeid", "2"); search.put("limit", "1"); JSONObject open_appts = (JSONObject) api.GET("/appointments/open", search); System.out.println(open_appts.toString()); JSONObject appt = open_appts.getJSONArray("appointments").getJSONObject(0); System.out.println("Open appointment:"); System.out.println(appt.toString()); // add keys to make appt usable for scheduling appt.put("appointmenttime", appt.get("starttime")); appt.put("appointmentdate", appt.get("date")); //////////////////////////////////////////////////////////////////////////////////////////// // POST with parameters //////////////////////////////////////////////////////////////////////////////////////////// Map<String, String> patient_info = new HashMap<String, String>(); patient_info.put("lastname", "Foo"); patient_info.put("firstname", "Jason"); patient_info.put("address1", "123 Any Street"); patient_info.put("city", "Cambridge"); patient_info.put("countrycode3166", "US"); patient_info.put("departmentid", "1"); patient_info.put("dob", "6/18/1987"); patient_info.put("language6392code", "declined"); patient_info.put("maritalstatus", "S"); patient_info.put("race", "declined"); patient_info.put("sex", "M"); patient_info.put("ssn", "*****1234"); patient_info.put("zip", "02139"); JSONArray new_patient = (JSONArray) api.POST("/patients", patient_info); String new_patient_id = new_patient.getJSONObject(0).getString("patientid"); System.out.println("New patient id:"); System.out.println(new_patient_id); //////////////////////////////////////////////////////////////////////////////////////////// // PUT with parameters //////////////////////////////////////////////////////////////////////////////////////////// Map<String, String> appointment_info = new HashMap<String, String>(); appointment_info.put("appointmenttypeid", "82"); appointment_info.put("departmentid", "1"); appointment_info.put("patientid", new_patient_id); JSONArray booked = (JSONArray) api.PUT("/appointments/" + appt.getString("appointmentid"), appointment_info); System.out.println("Booked:"); System.out.println(booked.toString()); //////////////////////////////////////////////////////////////////////////////////////////// // POST without parameters //////////////////////////////////////////////////////////////////////////////////////////// JSONObject checked_in = (JSONObject) api .POST("/appointments/" + appt.getString("appointmentid") + "/checkin"); System.out.println("Check-in:"); System.out.println(checked_in.toString()); //////////////////////////////////////////////////////////////////////////////////////////// // DELETE with parameters //////////////////////////////////////////////////////////////////////////////////////////// Map<String, String> delete_params = new HashMap<String, String>(); delete_params.put("departmentid", "1"); JSONObject chart_alert = (JSONObject) api.DELETE("/patients/" + new_patient_id + "/chartalert", delete_params); System.out.println("Removed chart alert:"); System.out.println(chart_alert.toString()); //////////////////////////////////////////////////////////////////////////////////////////// // DELETE without parameters //////////////////////////////////////////////////////////////////////////////////////////// JSONObject photo = (JSONObject) api.DELETE("/patients/" + new_patient_id + "/photo"); System.out.println("Removed photo:"); System.out.println(photo.toString()); //////////////////////////////////////////////////////////////////////////////////////////// // There are no PUTs without parameters //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// // Error conditions //////////////////////////////////////////////////////////////////////////////////////////// JSONObject bad_path = (JSONObject) api.GET("/nothing/at/this/path"); System.out.println("GET /nothing/at/this/path:"); System.out.println(bad_path.toString()); JSONObject missing_parameters = (JSONObject) api.GET("/appointments/open"); System.out.println("Missing parameters:"); System.out.println(missing_parameters.toString()); //////////////////////////////////////////////////////////////////////////////////////////// // Testing token refresh // // NOTE: this test takes an hour, so it's disabled by default. Change false to true to run. //////////////////////////////////////////////////////////////////////////////////////////// if (false) { String old_token = api.getToken(); System.out.println("Old token: " + old_token); JSONObject before_refresh = (JSONObject) api.GET("/departments"); // Wait 3600 seconds = 1 hour for token to expire. try { Thread.sleep(3600 * 1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } JSONObject after_refresh = (JSONObject) api.GET("/departments"); System.out.println("New token: " + api.getToken()); } }
From source file:Main.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.set(Calendar.DAY_OF_MONTH, 1); // day of week for first date of month int weekOfFirstDate = calendar.get(Calendar.WEEK_OF_YEAR); int lastDateOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); calendar.set(Calendar.DAY_OF_MONTH, lastDateOfMonth); // day of week for last date of month int weekOfLastDate = calendar.get(Calendar.WEEK_OF_YEAR); calendar.roll(Calendar.MONTH, false); int lastDateOfPrevMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); int weeksToDisplay = weekOfLastDate - weekOfFirstDate + 1; int[] days = new int[weeksToDisplay * 7]; int firstDayPosition = 3; // fill previous month int x = lastDateOfPrevMonth; for (int i = firstDayPosition - 1; i >= 0; i--) { days[i] = x--;/* w ww .j a v a 2 s .c om*/ } // fill current month for (int i = 1; i < lastDateOfMonth + 1; i++) { days[firstDayPosition - 1 + i] = i; } // fill next month int j = 1; for (int i = lastDateOfMonth + firstDayPosition; i < days.length; i++) { days[i] = j++; } for (int i = 0; i < days.length; i++) { if (i % 7 == 0) { System.out.println(); } System.out.print(days[i] + "\t"); } }
From source file:Main.java
public static Calendar getNextStart() { Calendar cc = Calendar.getInstance(); cc.roll(Calendar.HOUR, 1); cc.set(Calendar.MINUTE, 0);/*from w w w . ja va 2 s . c om*/ cc.set(Calendar.SECOND, 0); return cc; }
From source file:Main.java
/** * Method to check if a date is tomorrow * /*from w w w . j a v a 2 s . c o m*/ * @param theDate * the date to see if it is tomorrow * @return true of it is tomorrow */ public static boolean isTomorrow(Date theDate) { // Get a calendar with the events start time GregorianCalendar theCalendar = new GregorianCalendar(); theCalendar.setTime(theDate); // Get a calendar with current system time and change its value so it // can be used in comparison with the given date. Calendar tmpDate = Calendar.getInstance(); tmpDate.roll(Calendar.DAY_OF_YEAR, true); return tmpDate.get(Calendar.YEAR) == theCalendar.get(Calendar.YEAR) && tmpDate.get(Calendar.DAY_OF_YEAR) == theCalendar.get(Calendar.DAY_OF_YEAR); }
From source file:Main.java
public static boolean isTomorrow(Calendar cal) { Calendar tomorrow = Calendar.getInstance(Locale.getDefault()); tomorrow.roll(Calendar.DAY_OF_YEAR, true); return cal.get(Calendar.DAY_OF_YEAR) == tomorrow.get(Calendar.DAY_OF_YEAR) && cal.get(Calendar.YEAR) == tomorrow.get(Calendar.YEAR); }
From source file:Main.java
public static boolean isYesterday(Calendar cal) { Calendar yesterday = Calendar.getInstance(Locale.getDefault()); yesterday.roll(Calendar.DAY_OF_YEAR, false); return cal.get(Calendar.DAY_OF_YEAR) == yesterday.get(Calendar.DAY_OF_YEAR) && cal.get(Calendar.YEAR) == yesterday.get(Calendar.YEAR); }
From source file:Main.java
public static int getCurrentMonthDay() { // calendar.getActualMaximum(Calendar.DAY_OF_MONTH), Calendar a = Calendar.getInstance(); a.set(Calendar.DATE, 1);//from w ww . j a v a 2 s . c om a.roll(Calendar.DATE, -1); int maxDate = a.get(Calendar.DATE); return maxDate; }
From source file:org.lieuofs.extraction.etatpays.ExtractionPays.java
private static List<EtatTerritoirePersistant> filtre(List<EtatTerritoirePersistant> listeOriginal) { List<EtatTerritoirePersistant> listeFiltree = new ArrayList<EtatTerritoirePersistant>(); for (EtatTerritoirePersistant etatTerritoire : listeOriginal) { // On slectionne tous les tats territoire reconnu il ya moins de 2 ans Calendar cal = Calendar.getInstance(); cal.roll(Calendar.YEAR, -5); Date ilYa5an = cal.getTime(); Date dateReconnaissance = etatTerritoire.getDateReconnaissance(); if (null != dateReconnaissance && dateReconnaissance.compareTo(ilYa5an) > 0) { listeFiltree.add(etatTerritoire); }//from w ww .j av a 2s . c om } return listeFiltree; }