List of usage examples for java.util GregorianCalendar add
@Override public void add(int field, int amount)
From source file:com.jmstudios.redmoon.receiver.AutomaticFilterChangeReceiver.java
public static void scheduleNextAlarm(Context context, String time, Intent operation) { GregorianCalendar calendar = new GregorianCalendar(); calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0])); calendar.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1])); GregorianCalendar now = new GregorianCalendar(); now.add(Calendar.SECOND, 1); if (calendar.before(now)) { calendar.add(Calendar.DATE, 1); }/*from w w w .j a v a 2 s. co m*/ if (DEBUG) Log.i(TAG, "Scheduling alarm for " + calendar.toString()); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, operation, 0); if (android.os.Build.VERSION.SDK_INT >= 19) { alarmManager.setExact(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent); } else { alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent); } }
From source file:org.bimserver.plugins.web.AbstractWebModulePlugin.java
private static Date makeExpiresDate() { GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.add(Calendar.DAY_OF_YEAR, 120); return gregorianCalendar.getTime(); }
From source file:com.sapienter.jbilling.server.user.validator.RepeatedPasswordValidator.java
/** * Queries the event_log table to check whether the user has already used * in the past the password he's trying to set now. * @param userId Id of the user whose password is being changed. * @return An array of <code>java.lang.String</code> containing the passwords * recently used by this user./* w ww . java 2s .c o m*/ */ private static String[] getPasswords(Integer userId) throws SQLException, NamingException { String[] passw = null; CachedRowSet cachedResults = new CachedRowSet(); JNDILookup jndi = JNDILookup.getFactory(); Connection conn = jndi.lookUpDataSource().getConnection(); cachedResults.setCommand(UserSQL.findUsedPasswords); GregorianCalendar date = new GregorianCalendar(); date.add(GregorianCalendar.YEAR, -2); cachedResults.setDate(1, new Date(date.getTimeInMillis())); cachedResults.setInt(2, userId); cachedResults.execute(conn); List<String> result = new ArrayList<String>(); while (cachedResults.next()) { result.add(cachedResults.getString(1)); } if (!result.isEmpty()) { passw = new String[result.size()]; int index = 0; for (Iterator i = result.iterator(); i.hasNext();) { passw[index] = (String) i.next(); index++; } } conn.close(); return passw; }
From source file:org.apache.ranger.common.DateUtil.java
public static Date getUTCDate(long epoh) { if (epoh == 0) { return null; }//w ww .j a v a 2 s .c om try { Calendar local = Calendar.getInstance(); int offset = local.getTimeZone().getOffset(epoh); GregorianCalendar utc = new GregorianCalendar(gmtTimeZone); utc.setTimeInMillis(epoh); utc.add(Calendar.MILLISECOND, -offset); return utc.getTime(); } catch (Exception ex) { return null; } }
From source file:org.apache.ranger.common.DateUtil.java
public static Date getUTCDate() { try {/*from w w w . jav a 2 s. c o m*/ Calendar local = Calendar.getInstance(); int offset = local.getTimeZone().getOffset(local.getTimeInMillis()); GregorianCalendar utc = new GregorianCalendar(gmtTimeZone); utc.setTimeInMillis(local.getTimeInMillis()); utc.add(Calendar.MILLISECOND, -offset); return utc.getTime(); } catch (Exception ex) { return null; } }
From source file:fr.ippon.wip.ltpa.token.LtpaLibrary.java
/** * Create a valid LTPA token for the specified user. * * @param username - the user to create the LTPA token for. * @param creationTime - the time the token becomes valid. * @param durationMinutes - the duration of the token validity in minutes. * @param ltpaSecretStr - the LTPA Domino Secret to use to create the token. * @return - base64 encoded LTPA token, ready for the cookie. * @throws NoSuchAlgorithmException//from w ww .j a v a2 s . co m */ public static String createLtpaToken(String username, GregorianCalendar creationTime, int durationMinutes, String ltpaSecretStr) throws NoSuchAlgorithmException { // create byte array buffers for both strings byte[] ltpaSecret = Base64.decodeBase64(ltpaSecretStr.getBytes()); byte[] usernameArray = username.getBytes(); byte[] workingBuffer = new byte[preUserDataLength + usernameArray.length + ltpaSecret.length]; // copy version into workingBuffer System.arraycopy(ltpaTokenVersion, 0, workingBuffer, 0, ltpaTokenVersion.length); GregorianCalendar expirationDate = (GregorianCalendar) creationTime.clone(); expirationDate.add(Calendar.MINUTE, durationMinutes); // copy creation date into workingBuffer String hex = dateStringFiller + Integer.toHexString((int) (creationTime.getTimeInMillis() / 1000)).toUpperCase(); System.arraycopy(hex.getBytes(), hex.getBytes().length - dateStringLength, workingBuffer, creationDatePosition, dateStringLength); // copy expiration date into workingBuffer hex = dateStringFiller + Integer.toHexString((int) (expirationDate.getTimeInMillis() / 1000)).toUpperCase(); System.arraycopy(hex.getBytes(), hex.getBytes().length - dateStringLength, workingBuffer, expirationDatePosition, dateStringLength); // copy user name into workingBuffer System.arraycopy(usernameArray, 0, workingBuffer, preUserDataLength, usernameArray.length); // copy the ltpaSecret into the workingBuffer System.arraycopy(ltpaSecret, 0, workingBuffer, preUserDataLength + usernameArray.length, ltpaSecret.length); byte[] hash = createHash(workingBuffer); // put the public data and the hash into the outputBuffer byte[] outputBuffer = new byte[preUserDataLength + usernameArray.length + hashLength]; System.arraycopy(workingBuffer, 0, outputBuffer, 0, preUserDataLength + usernameArray.length); System.arraycopy(hash, 0, outputBuffer, preUserDataLength + usernameArray.length, hashLength); return new String(Base64.encodeBase64(outputBuffer)); }
From source file:de.arago.rike.zombie.ZombieHelper.java
static String toPrettyJSON(List ticks) { List<OverdueMilestone> milestones = getOverdueMilestones(true); Collections.sort(milestones, new DoneSorter()); final List data = new ArrayList(); final Map open = new HashMap(); final Map in_progress = new HashMap(); final Map done = new HashMap(); data.add(open);//from w w w .j a v a2 s. co m data.add(in_progress); data.add(done); open.put("Label", "open"); open.put("color", "red"); in_progress.put("Label", "in_progress"); in_progress.put("color", "yellow"); done.put("Label", "done"); done.put("color", "green"); List openData = new ArrayList(); List in_progressData = new ArrayList(); List doneData = new ArrayList(); open.put("data", openData); in_progress.put("data", in_progressData); done.put("data", doneData); long now = new Date().getTime(); int i = 1; for (OverdueMilestone o : milestones) { Milestone stone = o.getMilestone(); ticks.add("<a href='/web/guest/rike/-/show/milestone/" + stone.getId() + "'>" + StringEscapeUtils.escapeHtml(stone.getTitle()) + "</a>"); GregorianCalendar c = new GregorianCalendar(); c.setTime(stone.getDueDate()); c.add(Calendar.HOUR_OF_DAY, -((o.getWorkLeftInHours() - o.getWorkInProgressInHours()) * 7 * 24) / stone.getPerformance()); long time1 = c.getTimeInMillis(); c.add(Calendar.HOUR_OF_DAY, -(o.getWorkInProgressInHours() * 7 * 24) / stone.getPerformance()); long time2 = c.getTimeInMillis(); c.add(Calendar.HOUR_OF_DAY, -(o.getWorkDoneInHours() * 7 * 24) / stone.getPerformance()); long time3 = c.getTimeInMillis(); List item = new ArrayList(); item.add(time1); item.add(i); item.add(stone.getDueDate().getTime()); item.add(""); openData.add(item); item = new ArrayList(); item.add(time2); item.add(i); item.add(time1); item.add(""); in_progressData.add(item); item = new ArrayList(); item.add(time3); item.add(i); item.add(time2); item.add(""); doneData.add(item); ++i; } return JSONArray.toJSONString(data); }
From source file:oscar.oscarLab.ca.all.upload.handlers.OscarToOscarHl7V2.AdtA09Handler.java
public static void handle(ADT_A09 message) throws HL7Exception { // algorithm/* w w w .j a v a 2 s . c o m*/ // ---------- // unparse the hl7 message so we know who's checking in and make sure it's a check in // look at appointments today for anyone with matching demographic info // flip appointment status to H // the 2 relavent segments // PID|1||hhhhhhhhhh^^^^^^199704^199903^BC||last_name^first_name^^^^^L||19750607 // PV1||P|||||||||^WAITING_ROOM checkPv1(message.getPV1()); // look for the patient four hours ago and four hours from now GregorianCalendar startTime = new GregorianCalendar(); startTime.add(GregorianCalendar.HOUR_OF_DAY, -checkInLateAllowance); GregorianCalendar endTime = new GregorianCalendar(); // add 24 because it's at the start of the day and it's exclusive of that day endTime.add(GregorianCalendar.HOUR_OF_DAY, 24 + checkInEarlyAllowance); // so this only sorts out the day ranges i.e. we could have just done a select from today but this way we bridge // people checking in at 11:50pm for an appointment at 1:00am. List<Appointment> appointments = appointmentDao.findByDateRange(startTime.getTime(), endTime.getTime()); logger.debug("Qualifying appointments found : " + appointments.size()); // adt messages can come in the form of pull PID's or just the chart number to switch // if the chart number exists then use the chart number, otherwise match demographic record. String chartNo = getChartNo(message); if (chartNo != null) { switchMatchingAppointment(chartNo, appointments); } else { Demographic demographic = DataTypeUtils.parsePid(message.getPID()); switchMatchingAppointment(demographic, appointments); } }
From source file:com.projity.util.DateTime.java
public static long midnightTomorrow() { GregorianCalendar cal = calendarInstance(); cal.add(Calendar.DATE, 1); return dayFloor(cal.getTimeInMillis()); }
From source file:org.mifos.calendar.CalendarUtils.java
public static DateTime getNextDateForDay(final DateTime startDate, final int every) { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate.toDate());//from ww w.j a v a2 s . co m gc.add(Calendar.DAY_OF_WEEK, every); return new DateTime(gc.getTime().getTime()); }