List of usage examples for org.joda.time Minutes minutesBetween
public static Minutes minutesBetween(ReadablePartial start, ReadablePartial end)
Minutes
representing the number of whole minutes between the two specified partial datetimes. From source file:org.mythtv.android.presentation.view.adapter.phone.UpcomingProgramsAdapter.java
License:Open Source License
@Override public void onBindViewHolder(ProgramViewHolder holder, final int position) { final ProgramModel programModel = this.programsCollection.get(position); holder.textViewTitle.setText(programModel.getTitle()); holder.textViewSubTitle.setText(programModel.getSubTitle()); holder.textViewDate.setText(programModel.getStartTime().withZone(DateTimeZone.getDefault()) .toString(DateTimeFormat.patternForStyle("MS", Locale.getDefault()))); holder.textViewDuration.setText(context.getResources().getString(R.string.minutes, Minutes.minutesBetween(programModel.getStartTime(), programModel.getEndTime()).getMinutes())); }
From source file:org.ojbc.web.portal.controllers.PortalController.java
License:RPL License
UserLogonInfo getUserLogonInfo(Element assertionElement) { UserLogonInfo userLogonInfo = new UserLogonInfo(); if (assertionElement == null) { log.warn("assertionElement was null, returning empty UserLogonInfo"); return userLogonInfo; }//from ww w . j ava2 s .com try { debugPrintAssertion(assertionElement); String instantString = (String) xPath.evaluate("/saml2:Assertion/saml2:AuthnStatement/@AuthnInstant", assertionElement, XPathConstants.STRING); DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); DateTime authnInstant = fmt.parseDateTime(instantString); int minutesOnline = Minutes.minutesBetween(authnInstant, new DateTime()).getMinutes(); int hoursOnline = (int) minutesOnline / 60; minutesOnline = minutesOnline % 60; userLogonInfo.timeOnlineString = String.valueOf(hoursOnline) + ":" + (minutesOnline < 10 ? "0" : "") + String.valueOf(minutesOnline); String userLastName = (String) xPath.evaluate( "/saml2:Assertion/saml2:AttributeStatement[1]/saml2:Attribute[@Name='gfipm:2.0:user:SurName']/saml2:AttributeValue/text()", assertionElement, XPathConstants.STRING); String userFirstName = (String) xPath.evaluate( "/saml2:Assertion/saml2:AttributeStatement[1]/saml2:Attribute[@Name='gfipm:2.0:user:GivenName']/saml2:AttributeValue/text()", assertionElement, XPathConstants.STRING); String userAgency = (String) xPath.evaluate( "/saml2:Assertion/saml2:AttributeStatement[1]/saml2:Attribute[@Name='gfipm:2.0:user:EmployerName']/saml2:AttributeValue/text()", assertionElement, XPathConstants.STRING); String sEmail = (String) xPath.evaluate( "/saml2:Assertion/saml2:AttributeStatement[1]/saml2:Attribute[@Name='gfipm:2.0:user:EmailAddressText']/saml2:AttributeValue/text()", assertionElement, XPathConstants.STRING); userLogonInfo.userNameString = (userFirstName == null ? "" : userFirstName) + " " + (userLastName == null ? "" : userLastName) + " / " + (userAgency == null ? "" : userAgency); userLogonInfo.emailAddress = sEmail; } catch (Exception e) { e.printStackTrace(); } return userLogonInfo; }
From source file:org.openmrs.module.appointmentscheduling.api.impl.AppointmentServiceImpl.java
License:Open Source License
@Override @Transactional(readOnly = true)//from w ww . j a v a 2 s . c om public Integer getTimeLeftInTimeSlot(TimeSlot timeSlot) { if (timeSlot == null) { return null; } Integer minutes = Minutes .minutesBetween(new DateTime(timeSlot.getStartDate()), new DateTime(timeSlot.getEndDate())) .getMinutes(); for (Appointment appointment : Context.getService(AppointmentService.class) .getAppointmentsInTimeSlotThatAreNotCancelled(timeSlot)) { minutes = minutes - appointment.getAppointmentType().getDuration(); } return minutes; }
From source file:org.openmrs.module.pihmalawi.reporting.definition.data.converter.DurationConverter.java
License:Open Source License
/** * @see DataConverter#convert(Object)/*w w w . j a v a 2s. c om*/ */ public Object convert(Object original) { if (original != null) { DateTime from = new DateTime((Date) original); if (durationToDate == null) { durationToDate = new Date(); } DateTime to = new DateTime(durationToDate); if (durationUnit == DurationUnit.YEARS) { return Years.yearsBetween(from, to).getYears(); } else if (durationUnit == DurationUnit.MONTHS) { return Months.monthsBetween(from, to).getMonths(); } else if (durationUnit == DurationUnit.WEEKS) { return Weeks.weeksBetween(from, to).getWeeks(); } else if (durationUnit == DurationUnit.DAYS) { return Days.daysBetween(from, to).getDays(); } else if (durationUnit == DurationUnit.HOURS) { return Hours.hoursBetween(from, to).getHours(); } else if (durationUnit == DurationUnit.MINUTES) { return Minutes.minutesBetween(from, to).getMinutes(); } else if (durationUnit == DurationUnit.SECONDS) { return Seconds.secondsBetween(from, to).getSeconds(); } else { throw new IllegalArgumentException("Unable to convert with duration unit: " + durationUnit); } } return null; }
From source file:org.openvpms.archetype.i18n.time.DateDurationFormatter.java
License:Open Source License
/** * Formats the duration between two timestamps. * <p/>/* w w w . j a v a 2 s.co m*/ * NOTE: this currently doesn't do anything sensible for from > to. Possible solution would be to simply * reverse the times, and then prepend a - between each field using the * * @param from the starting time * @param to the ending time * @return the formatted duration */ protected String format(DateTime from, DateTime to) { int years = 0; int months = 0; int weeks = 0; int days = 0; int hours = 0; int minutes = 0; DateTime start = from; if (showYears) { years = Years.yearsBetween(start, to).getYears(); start = start.plusYears(years); } if (showMonths) { months = Months.monthsBetween(start, to).getMonths(); start = start.plusMonths(months); } if (showWeeks) { weeks = Weeks.weeksBetween(start, to).getWeeks(); start = start.plusWeeks(weeks); } if (showDays) { days = Days.daysBetween(start, to).getDays(); start = start.plusDays(days); } if (showHours) { hours = Hours.hoursBetween(start, to).getHours(); start = start.plusHours(hours); } if (showMinutes) { minutes = Minutes.minutesBetween(start, to).getMinutes(); } Period period = new Period(years, months, weeks, days, hours, minutes, 0, 0); return formatter.print(period); }
From source file:org.openvpms.web.workspace.workflow.appointment.AppointmentCRUDWindow.java
License:Open Source License
/** * Returns the duration in minutes between two times. * * @param startTime the start time//from ww w.j a v a 2 s .c o m * @param endTime the end time * @return the duration in minutes */ private int getDuration(Date startTime, Date endTime) { return Minutes.minutesBetween(new DateTime(startTime), new DateTime(endTime)).getMinutes(); }
From source file:org.optaplanner.examples.driverallot.domain.solver.RouteTripDistance.java
License:Apache License
private double timeDifferenceMilitaryFormat(int timeEnd, int timeStart) throws ParseException { SimpleDateFormat format = new SimpleDateFormat("hhmm"); String timeEndString = String.valueOf(timeEnd); if (timeEndString.length() < 4) timeEndString = "0" + timeEndString; Date startDate = format.parse(timeEndString); String timeStartString = String.valueOf(timeStart); if (timeStartString.length() < 4) timeStartString = "0" + timeStartString; Date endDate = format.parse(timeStartString); DateTime jdStartDate = new DateTime(startDate); DateTime jdEndDate = new DateTime(endDate); int hours = Hours.hoursBetween(jdStartDate, jdEndDate).getHours(); if (hours < 0) hours = Hours.hoursBetween(jdEndDate, jdStartDate).getHours(); //System.out.println(hours); hours = hours % 24;/* w w w. j a va2s.c o m*/ int minutes = Minutes.minutesBetween(jdStartDate, jdEndDate).getMinutes(); if (minutes < 0) minutes = Minutes.minutesBetween(jdEndDate, jdStartDate).getMinutes(); //System.out.println(minutes); minutes = minutes % 60; //System.out.println(timeEndString + " " + timeStartString + " " + hours + " " + minutes); return hours * 60 + minutes; }
From source file:org.venice.beachfront.bfapi.services.UserProfileService.java
License:Apache License
/** * Every 5 minutes, scan for expired API Keys that have not been used recently. Invalidate these keys if they are * older than the threshold./*from w ww .ja v a 2 s . c om*/ */ @Scheduled(fixedDelay = 300000, initialDelay = 60000) public void reapExpiredApiKeys() { piazzaLogger.log("Performing Periodic Reaping of Expired API Keys", Severity.INFORMATIONAL); for (UserProfile userProfile : userProfileDao.findAll()) { // Check the last Access time and compare it with the threshold if (userProfile.getApiKey() != null) { // If the account has never been accessed, set the last access time to the creation time (Legacy) if (userProfile.getLastAccessed() == null) { userProfile.setLastAccessed(userProfile.getCreatedOn()); saveUserProfile(userProfile); } if (Minutes.minutesBetween(userProfile.getLastAccessed(), new DateTime()) .getMinutes() >= API_KEY_TIMEOUT_MINUTES) { // Expire the Key piazzaLogger.log(String.format("Server-side timeout of key for user %s due to inactivity.", userProfile.getName()), Severity.INFORMATIONAL); this.invalidateKey(userProfile); } } } }
From source file:org.wso2.analytics.esb.util.TimeRangeUtils.java
License:Open Source License
public static String getSuitableTimeRangeUnit(long from, long to) { DateTime fromTime = new DateTime(from); DateTime toTime = new DateTime(to); RangeUnit range;/*from w ww. j av a 2s . c o m*/ if (Months.monthsBetween(fromTime, toTime).getMonths() >= INTERVAL) { range = RangeUnit.MONTH; } else if (Days.daysBetween(fromTime, toTime).getDays() >= INTERVAL) { range = RangeUnit.DAY; } else if (Hours.hoursBetween(fromTime, toTime).getHours() >= INTERVAL) { range = RangeUnit.HOUR; } else if (Minutes.minutesBetween(fromTime, toTime).getMinutes() >= INTERVAL) { range = RangeUnit.MINUTE; } else { range = RangeUnit.SECOND; } return range.name(); }
From source file:projectresurrection.Eve.java
public static void main(String args[]) { init();//from ww w . j ava2s . c om listener = new Listener(); voice = new VoiceSynthesis(); clock = new Clock(Clock.BRAIN, Clock.UPDATE, (String) preferences.get("time zone")); gui = new GUI(GUI.DEFAULT); gui.start(GUI.DEFAULT); while (true) { if (!commands.isEmpty()) { String command = commands.poll(); prevCommands.add(command); switch (command) { case "what is the current weather": Clock.addCommand("kill"); List currentWeather = Weather.getCurrent(); sb = "The Current Tempurature is " + currentWeather.get(1) + " degrees fahrenheit and " + ((currentWeather.get(2).equals("Thunderstorm In Vicinity")) ? "there is a " : "is ") + currentWeather.get(2); if (!currentWeather.get(3).equals("0")) { sb += ", with wind traveling at " + currentWeather.get(3) + " miles per hour "; switch ((String) currentWeather.get(5)) { case "N": sb += "North"; break; case "NNE": sb += "North North East"; break; case "NE": sb += "North East"; break; case "ENE": sb += "East North East"; break; case "E": sb += "East"; break; case "ESE": sb += "East South East"; break; case "SE": sb += "South East"; break; case "SSE": sb += "South South East"; break; case "S": sb += "South"; break; case "SSW": sb += "South South West"; break; case "SW": sb += "South West"; break; case "WSW": sb += "West South West"; break; case "W": sb += "West"; break; case "WNW": sb += "West North West"; break; case "NW": sb += "North West"; break; case "NNW": sb += "North North West"; break; } } voice.say(sb); break; case "what time is it": date = new DateTime(clock.getCurrent()); voice.say( "It is " + date.getHourOfDay() % 12 + ":" + ((date.getMinuteOfHour() < 10) ? "oh " : "") + date.getMinuteOfHour() + ((date.getHourOfDay() > 12) ? " P.M." : " A.M.")); break; case "what is the date": date = new DateTime(clock.getCurrent()); sb = "It is the "; switch (date.getDayOfMonth()) { case 1: sb += "first"; break; case 2: sb += "second"; break; case 3: sb += "third"; break; case 4: sb += "fourth"; break; case 5: sb += "fifth"; break; case 6: sb += "sixth"; break; case 7: sb += "seventh"; break; case 8: sb += "eighth"; break; case 9: sb += "ninth"; break; case 10: sb += "tenth"; break; case 11: sb += "eleventh"; break; case 12: sb += "twelth"; break; case 13: sb += "thirteenth"; break; case 14: sb += "fourteenth"; break; case 15: sb += "fifteenth"; break; case 16: sb += "sixteenth"; break; case 17: sb += "seventeenth"; break; case 18: sb += "eighteenth"; break; case 19: sb += "nineteenth"; break; case 20: sb += "twentieth"; break; case 21: sb += "twenty-first"; break; case 22: sb += "twenty-second"; break; case 23: sb += "twenty-third"; break; case 24: sb += "twenty-fourth"; break; case 25: sb += "twenty-fifth"; break; case 26: sb += "twenty-sixth"; break; case 27: sb += "twenty-seventh"; break; case 28: sb += "twenty-eighth"; break; case 29: sb += "twenty-ninth"; break; case 30: sb += "thirtieth"; break; case 31: sb += "thirty-first"; break; } sb += " of "; switch (date.getMonthOfYear()) { case 1: sb += "January"; break; case 2: sb += "Feburary"; break; case 3: sb += "March"; break; case 4: sb += "April"; break; case 5: sb += "May"; break; case 6: sb += "June"; break; case 7: sb += "July"; break; case 8: sb += "August"; break; case 9: sb += "September"; break; case 10: sb += "October"; break; case 11: sb += "November"; break; case 12: sb += "December"; break; } sb += ", " + date.getYear(); voice.say(sb); break; case "what day is it": date = new DateTime(clock.getCurrent()); sb = "Today is "; switch (date.getDayOfWeek()) { case (1): sb += "Mondaay"; break; case (2): sb += "Tuesdaay"; break; case (3): sb += "Wednesdaay"; break; case (4): sb += "Thursdaay"; break; case (5): sb += "Fridaay"; break; case (6): sb += "Saturdaay"; break; case (7): sb += "Sundaay"; break; } voice.say(sb); break; case "create a reminder": break; case "how old are you": sb = "I am "; DateTime current = clock.getCurrent(); Period diff = new Period(birth, current); int days = Days.daysBetween(birth, current).getDays(); int hours = Hours.hoursBetween(birth, current).getHours() % 24; int minutes = Minutes.minutesBetween(birth, current).getMinutes() % 60; int seconds = Seconds.secondsBetween(birth, current).getSeconds() % 60; switch (days) { case 0: sb += ""; break; case 1: if (hours == 0 && minutes == 0 && seconds == 0) { sb += days + " day old."; } else { sb += days + " day, "; } break; default: if (hours == 0 && minutes == 0 && seconds == 0) { sb += days + " days old."; } else { sb += days + " days, "; } break; } switch (hours) { case 0: sb += ""; break; case 1: if (minutes == 0 && seconds == 0) { sb += "and " + hours + " hour old."; } else { sb += hours + " hour, "; break; } break; default: if (minutes == 0 && seconds == 0) { sb += "and " + hours + " hours old."; } else { sb += hours + " hours, "; } break; } switch (minutes) { case 0: sb += ""; break; case 1: if (seconds == 0) { sb += "and " + minutes + " minute old."; } else { sb += minutes + " minute, "; } break; default: if (seconds == 0) { sb += "and " + minutes + " minutes old."; } else { sb += minutes + " minutes, "; } break; } switch (seconds) { case 0: sb += ""; break; case 1: sb += "and " + seconds + " second old."; default: sb += "and " + seconds + " seconds old."; break; } voice.say(sb); break; case "change preferences": updatePref(); break; case "": voice.say("Lee dul lee dul lee dul leeee"); break; case "repeat": voice.repeatSlow(); break; default: voice.say(command); break; } } else { try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } }