List of usage examples for org.joda.time DateTime plusMinutes
public DateTime plusMinutes(int minutes)
From source file:com.cloudhopper.commons.util.time.DateTimePeriod.java
License:Apache License
/** * Converts this period to a list of five minute periods. Partial five minute periods will not be * included. For example, a period of "January 20, 2009 7 to 8 AM" will return a list * of 12 five minute periods - one for each 5 minute block of time 0, 5, 10, 15, etc. * On the other hand, a period of "January 20, 2009 at 13:04" would return an empty list since partial * five minute periods are not included. * @return A list of five minute periods contained within this period *//*from ww w .ja va 2 s .c om*/ public List<DateTimePeriod> toFiveMinutes() { ArrayList<DateTimePeriod> list = new ArrayList<DateTimePeriod>(); // default "current" five minutes to start datetime DateTime currentStart = getStart(); // calculate "next" five minutes DateTime nextStart = currentStart.plusMinutes(5); // continue adding until we've reached the end while (nextStart.isBefore(getEnd()) || nextStart.isEqual(getEnd())) { // its okay to add the current list.add(new DateTimeFiveMinutes(currentStart, nextStart)); // increment both currentStart = nextStart; nextStart = currentStart.plusMinutes(5); } return list; }
From source file:com.cloudhopper.commons.util.time.DateTimePeriod.java
License:Apache License
static public DateTimePeriod createFiveMinutes(DateTime start) { DateTime end = start.plusMinutes(5); return new DateTimeFiveMinutes(start, end); }
From source file:com.coderoad.automation.common.util.DateUtil.java
License:Open Source License
/** * Gets the calendar./*from w w w. j a va2s . co m*/ * * @param startTime the start time * @param minutes the minutes * @param pattern the pattern * @return the calendar */ public static Calendar getCalendar(Calendar startTime, int minutes, final String pattern) { Calendar endTime = null; DateTime start = new DateTime(startTime); DateTime end = start.plusMinutes(minutes); DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); fmt = fmt.withZoneUTC(); endTime = parseToUTCCalendar(fmt.print(end), pattern); return endTime; }
From source file:com.cronutils.model.time.ExecutionTime.java
License:Apache License
/** * If date is not match, will return next closest match. * If date is match, will return this date. * @param date - reference DateTime instance - never null; * @return DateTime instance, never null. Value obeys logic specified above. * @throws NoSuchValueException/*www . j a va2 s. c o m*/ */ DateTime nextClosestMatch(DateTime date) throws NoSuchValueException { List<Integer> year = yearsValueGenerator.generateCandidates(date.getYear(), date.getYear()); TimeNode days = null; int lowestMonth = months.getValues().get(0); int lowestHour = hours.getValues().get(0); int lowestMinute = minutes.getValues().get(0); int lowestSecond = seconds.getValues().get(0); NearestValue nearestValue; DateTime newDate; if (year.isEmpty()) { int newYear = yearsValueGenerator.generateNextValue(date.getYear()); days = generateDays(cronDefinition, new DateTime(newYear, lowestMonth, 1, 0, 0)); return initDateTime(yearsValueGenerator.generateNextValue(date.getYear()), lowestMonth, days.getValues().get(0), lowestHour, lowestMinute, lowestSecond, date.getZone()); } if (!months.getValues().contains(date.getMonthOfYear())) { nearestValue = months.getNextValue(date.getMonthOfYear(), 0); int nextMonths = nearestValue.getValue(); if (nearestValue.getShifts() > 0) { newDate = new DateTime(date.getYear(), 1, 1, 0, 0, 0, date.getZone()) .plusYears(nearestValue.getShifts()); return nextClosestMatch(newDate); } if (nearestValue.getValue() < date.getMonthOfYear()) { date = date.plusYears(1); } days = generateDays(cronDefinition, new DateTime(date.getYear(), nextMonths, 1, 0, 0)); return initDateTime(date.getYear(), nextMonths, days.getValues().get(0), lowestHour, lowestMinute, lowestSecond, date.getZone()); } days = generateDays(cronDefinition, date); if (!days.getValues().contains(date.getDayOfMonth())) { nearestValue = days.getNextValue(date.getDayOfMonth(), 0); if (nearestValue.getShifts() > 0) { newDate = new DateTime(date.getYear(), date.getMonthOfYear(), 1, 0, 0, 0, date.getZone()) .plusMonths(nearestValue.getShifts()); return nextClosestMatch(newDate); } if (nearestValue.getValue() < date.getDayOfMonth()) { date = date.plusMonths(1); } return initDateTime(date.getYear(), date.getMonthOfYear(), nearestValue.getValue(), lowestHour, lowestMinute, lowestSecond, date.getZone()); } if (!hours.getValues().contains(date.getHourOfDay())) { nearestValue = hours.getNextValue(date.getHourOfDay(), 0); int nextHours = nearestValue.getValue(); if (nearestValue.getShifts() > 0) { newDate = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 0, 0, 0, date.getZone()).plusDays(nearestValue.getShifts()); return nextClosestMatch(newDate); } if (nearestValue.getValue() < date.getHourOfDay()) { date = date.plusDays(1); } return initDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), nextHours, lowestMinute, lowestSecond, date.getZone()); } if (!minutes.getValues().contains(date.getMinuteOfHour())) { nearestValue = minutes.getNextValue(date.getMinuteOfHour(), 0); int nextMinutes = nearestValue.getValue(); if (nearestValue.getShifts() > 0) { newDate = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), 0, 0, date.getZone()).plusHours(nearestValue.getShifts()); return nextClosestMatch(newDate); } if (nearestValue.getValue() < date.getMinuteOfHour()) { date = date.plusHours(1); } return initDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), nextMinutes, lowestSecond, date.getZone()); } if (!seconds.getValues().contains(date.getSecondOfMinute())) { nearestValue = seconds.getNextValue(date.getSecondOfMinute(), 0); int nextSeconds = nearestValue.getValue(); if (nearestValue.getShifts() > 0) { newDate = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), date.getMinuteOfHour(), 0, date.getZone()) .plusMinutes(nearestValue.getShifts()); return nextClosestMatch(newDate); } if (nearestValue.getValue() < date.getSecondOfMinute()) { date = date.plusMinutes(1); } return initDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), date.getMinuteOfHour(), nextSeconds, date.getZone()); } return date; }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Gets the calendar.// w ww . j a va 2 s . c o m * @param startTime the start time * @param minutes the minutes * @return the calendar */ public static Calendar getCalendar(Calendar startTime, int minutes) { Calendar endTime = null; DateTime start = new DateTime(startTime); DateTime end = start.plusMinutes(minutes); DateTimeFormatter fmt = DateTimeFormat.forPattern(DATE_FMT_FULL); fmt = fmt.withZoneUTC(); endTime = parseToUTCCalendar(fmt.print(end), DATE_FMT_FULL); return endTime; }
From source file:com.google.cloud.iot.examples.HttpExample.java
License:Apache License
/** Create a RSA-based JWT for the given project id, signed with the given private key. */ private static String createJwtRsa(String projectId, String privateKeyFile) throws Exception { DateTime now = new DateTime(); // Create a JWT to authenticate this device. The device will be disconnected after the token // expires, and will have to reconnect with a new token. The audience field should always be set // to the GCP project id. JwtBuilder jwtBuilder = Jwts.builder().setIssuedAt(now.toDate()).setExpiration(now.plusMinutes(20).toDate()) .setAudience(projectId);/*from w w w .j a v a 2 s . c o m*/ byte[] keyBytes = Files.readAllBytes(Paths.get(privateKeyFile)); PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes); KeyFactory kf = KeyFactory.getInstance("RSA"); return jwtBuilder.signWith(SignatureAlgorithm.RS256, kf.generatePrivate(spec)).compact(); }
From source file:com.google.cloud.iot.examples.HttpExample.java
License:Apache License
/** Create an ES-based JWT for the given project id, signed with the given private key. */ private static String createJwtEs(String projectId, String privateKeyFile) throws Exception { DateTime now = new DateTime(); // Create a JWT to authenticate this device. The device will be disconnected after the token // expires, and will have to reconnect with a new token. The audience field should always be set // to the GCP project id. JwtBuilder jwtBuilder = Jwts.builder().setIssuedAt(now.toDate()).setExpiration(now.plusMinutes(20).toDate()) .setAudience(projectId);// ww w .j av a2s. co m byte[] keyBytes = Files.readAllBytes(Paths.get(privateKeyFile)); PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes); KeyFactory kf = KeyFactory.getInstance("ES256"); return jwtBuilder.signWith(SignatureAlgorithm.ES256, kf.generatePrivate(spec)).compact(); }
From source file:com.google.cloud.solutions.rtdp.Simulator.java
License:Apache License
private static String createJwt(String projectId, String privateKeyFile, String algorithm) throws Exception { DateTime now = new DateTime(); JwtBuilder jwtBuilder = Jwts.builder().setIssuedAt(now.toDate()).setExpiration(now.plusMinutes(60).toDate()) .setAudience(projectId);//w w w .j a va 2 s. c om if (algorithm.equals("RS256")) { PrivateKey privateKey = loadKeyFile(privateKeyFile, "RSA"); return jwtBuilder.signWith(SignatureAlgorithm.RS256, privateKey).compact(); } else if (algorithm.equals("ES256")) { PrivateKey privateKey = loadKeyFile(privateKeyFile, "EC"); return jwtBuilder.signWith(SignatureAlgorithm.ES256, privateKey).compact(); } else { throw new IllegalArgumentException( "Invalid algorithm " + algorithm + ". Should be one of 'RS256' or 'ES256'."); } }
From source file:com.kopysoft.chronos.activities.QuickBreakActivity.java
License:Open Source License
private void updateDatabase() { int hour, min; TimePicker inTime = (TimePicker) findViewById(R.id.timePicker); Spinner timeSpinner = (Spinner) findViewById(R.id.timeSpinner); Spinner taskSpinner = (Spinner) findViewById(R.id.spinner); inTime.clearFocus();/* w ww. ja v a 2 s .c om*/ hour = inTime.getCurrentHour(); min = inTime.getCurrentMinute(); Task inTask = tasks.get(taskSpinner.getSelectedItemPosition()); DateTime date1 = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), hour, min); Chronos chrono = new Chronos(this); Job thisJob = chrono.getAllJobs().get(0); DateTime startOfPP = thisJob.getStartOfPayPeriod(); if (startOfPP.getSecondOfDay() > date1.getSecondOfDay()) { date1 = date1.plusDays(1); } Punch startPunch = new Punch(thisJob, inTask, date1); DateTime endDate; switch (timeSpinner.getSelectedItemPosition()) { case (0): endDate = date1.plusMinutes(5); break; case (1): endDate = date1.plusMinutes(10); break; case (2): endDate = date1.plusMinutes(15); break; case (3): endDate = date1.plusMinutes(30); break; case (4): endDate = date1.plusMinutes(45); break; case (5): endDate = date1.plusMinutes(60); break; default: endDate = date1.plusMinutes(1); } Punch endPunch = new Punch(thisJob, inTask, endDate); if (enableLog) Log.d(TAG, "Date Time: " + startPunch.getTime().getMillis()); Log.d(TAG, "Start Punch" + startPunch.getTime()); Log.d(TAG, "End Punch" + endPunch.getTime()); chrono.insertPunch(startPunch); chrono.insertPunch(endPunch); chrono.close(); //int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour }
From source file:com.marand.thinkmed.medications.administration.impl.AdministrationTaskCreatorImpl.java
License:Open Source License
private List<NewTaskRequestDto> createTasksForConstantComplexTherapyWithRate(final String patientId, final ConstantComplexTherapyDto therapy, final Interval taskCreationInterval, final Map<HourMinuteDto, TherapyDoseDto> timesWithDosesMap, final AdministrationTaskCreateActionEnum action) { final List<NewTaskRequestDto> taskRequests = new ArrayList<>(); if (!timesWithDosesMap.isEmpty()) { Pair<DateTime, TherapyDoseDto> next = getNextAdministrationTimeWithDose(action, therapy, taskCreationInterval.getStart(), timesWithDosesMap, action.isTaskCreationIntervalStartIncluded()); DateTime nextTaskTime = next.getFirst(); final int duration = therapy.getDoseElement().getDuration(); while (!isAfterTherapyEnd(therapy, nextTaskTime)) { if (nextTaskTime.isAfter(taskCreationInterval.getEnd())) { break; }//from ww w. ja v a 2 s. c o m final String groupUUId = action == AdministrationTaskCreateActionEnum.PREVIEW_TIMES_ON_NEW_PRESCRIPTION ? null : administrationUtils .generateGroupUUId(Opt.of(therapy.getStart()).orElseGet(DateTime::now)); taskRequests.add(createMedicationTaskRequestWithGroupUUId(patientId, groupUUId, therapy, AdministrationTypeEnum.START, nextTaskTime, next.getSecond())); final DateTime plannedStopTaskTime = nextTaskTime.plusMinutes(duration); final DateTime actualStopTaskTime = isAfterTherapyEnd(therapy, plannedStopTaskTime) ? therapy.getEnd() : plannedStopTaskTime; taskRequests.add(createMedicationTaskRequestWithGroupUUId(patientId, groupUUId, therapy, AdministrationTypeEnum.STOP, actualStopTaskTime, null)); next = getNextAdministrationTimeWithDose(action, therapy, nextTaskTime, timesWithDosesMap, false); nextTaskTime = next.getFirst(); } } return taskRequests; }