List of usage examples for org.joda.time Period Period
public Period(Object period)
From source file:org.openvpms.web.workspace.workflow.appointment.FreeAppointmentSlotQuery.java
License:Open Source License
/** * Returns a period for a time property. * * @param property the time property/* www . j av a 2 s.c o m*/ * @return the period, as the number of milliseconds for the day, or {@code null} if no time has been set. */ private Period getPeriod(Property property) { Date date = property.getDate(); return (date != null) ? new Period(new DateTime(date).getMillisOfDay()) : null; }
From source file:org.sakaiproject.accountvalidator.logic.impl.ValidationLogicImpl.java
License:Educational Community License
private String getFormattedExpirationMinutes() { int expirationMinutes = serverConfigurationService.getInt(MAX_PASSWORD_RESET_MINUTES, MAX_PASSWORD_RESET_MINUTES_DEFAULT); Period period = new Period(expirationMinutes * 60 * 1000); PeriodFormatter periodFormatter = PeriodFormat.wordBased(rl.getLocale()); return periodFormatter.print(period); }
From source file:org.sakaiproject.accountvalidator.tool.producers.PasswordResetProducer.java
License:Educational Community License
/** * Converts some number of minutes into a presentable String' * ie for English:/*www. j av a 2s .co m*/ * 122 minutes -> 2 hours 2 minutes * 121 minutes -> 2 hours 1 minute * 120 minutes -> 2 hours * 62 minutes -> 1 hour 2 minutes * 61 minutes -> 1 hour 1 minute * 60 minutes -> 1 hour * 2 minutes -> 2 minutes * 1 minutes -> 1 minute * 0 minutes -> 0 minutes * Works with other languages too. * @param totalMinutes some number of minutes * @return a presentable String representation of totalMinutes */ public String getFormattedMinutes(int totalMinutes) { // Create a joda time period (takes milliseconds) Period period = new Period(totalMinutes * 60 * 1000); // format the period for the locale /* * Covers English, Danish, Dutch, French, German, Japanese, Portuguese, and Spanish. * To translate into others, see http://joda-time.sourceforge.net/apidocs/org/joda/time/format/PeriodFormat.html#wordBased(java.util.Locale) * (ie. put the properties mentioned in http://joda-time.sourceforge.net/apidocs/src-html/org/joda/time/format/PeriodFormat.html#line.94 into the classpath resource bundle) */ PeriodFormatter periodFormatter = PeriodFormat.wordBased(getLocale()); return periodFormatter.print(period); }
From source file:org.sonatype.nexus.extender.NexusContextListener.java
License:Open Source License
@Override public void contextDestroyed(final ServletContextEvent event) { // event is ignored, apparently can also be null // remove our dynamic filter if (registration != null) { registration.unregister();/*from w ww . j a v a2 s .co m*/ registration = null; } // log uptime before triggering activity which may run into problems long uptime = ManagementFactory.getRuntimeMXBean().getUptime(); log.info("Uptime: {}", PeriodFormat.getDefault().print(new Period(uptime))); try { lifecycleManager.to(LOGGING); // dispose of JSR-250 components before logging goes injector.getInstance(BeanManager.class).unmanage(); lifecycleManager.to(BOOT); } catch (final Exception e) { log.error("Failed to stop nexus", e); } extender.doStop(); // stop tracking bundles if (servletContext != null) { servletContext = null; } injector = null; SharedMetricRegistries.remove("nexus"); }
From source file:org.sonatype.nexus.internal.app.NxApplication.java
License:Open Source License
@Override protected void doStop() throws Exception { // log uptime before triggering activity which may run into problems long uptime = ManagementFactory.getRuntimeMXBean().getUptime(); log.info("Uptime: {}", PeriodFormat.getDefault().print(new Period(uptime))); // Due to no dependency mechanism in NX for components, we need to fire off a hint about shutdown first eventBus.post(new NexusStoppingEvent(this)); // kill services + notify eventBus.post(new NexusStoppedEvent(this)); eventManager.stop();// ww w. ja v a 2s .c o m securitySystem.stop(); // must stop database services manually orientBootstrap.stop(); // dispose of JSR-250 beanManager.unmanage(); }
From source file:org.springframework.cloud.consul.discovery.HeartbeatProperties.java
License:Apache License
protected Period computeHearbeatInterval() { // heartbeat rate at ratio * ttl, but no later than ttl -1s and, (under lesser // priority), no sooner than 1s from now double interval = ttlValue * intervalRatio; double max = Math.max(interval, 1); int ttlMinus1 = ttlValue - 1; double min = Math.min(ttlMinus1, max); return new Period(Math.round(1000 * min)); }
From source file:org.starnub.utilities.time.DateAndTimes.java
License:Open Source License
public static String getPeriodFormattedFromMilliseconds(long duration, boolean printZeros, int digitCount, String... separators) {// w ww. j av a2 s .co m Period period = new Period(duration).normalizedStandard(); PeriodFormatterBuilder formatterBuilder = new PeriodFormatterBuilder().minimumPrintedDigits(digitCount); if (printZeros) { formatterBuilder.printZeroIfSupported(); } formatterBuilder.appendYears().appendSeparator(separators[0]).appendMonths().appendSeparator(separators[1]) .appendWeeks().appendSeparator(separators[2]).appendDays().appendSeparator(separators[3]) .appendHours().appendSeparator(separators[4]).appendMinutes().appendSeparator(separators[5]) .appendSeconds().appendLiteral(separators[6]); return formatterBuilder.toFormatter().print(period); }
From source file:org.starnub.utilities.time.DateAndTimes.java
License:Open Source License
public static String getPeriodFormattedFromMillisecondsSuffix(long duration, boolean printZeros, int digitCount, String... separators) {/*from w ww .j a va 2 s .c o m*/ Period period = new Period(duration).normalizedStandard(); PeriodFormatterBuilder formatterBuilder = new PeriodFormatterBuilder().minimumPrintedDigits(digitCount); if (printZeros) { formatterBuilder.printZeroIfSupported(); } formatterBuilder.appendYears().appendSuffix(separators[0], separators[1]).appendMonths() .appendSuffix(separators[2], separators[3]).appendWeeks().appendSuffix(separators[4], separators[5]) .appendDays().appendSuffix(separators[6], separators[7]).appendHours() .appendSuffix(separators[8], separators[9]).appendMinutes() .appendSuffix(separators[10], separators[11]).appendSeconds() .appendSuffix(separators[12], separators[13]); return formatterBuilder.toFormatter().print(period); }
From source file:org.tensin.sonos.helpers.TimeUtilities.java
License:Apache License
/** * TODO BUG durations longer than one day will not work. * /*from w w w. java2 s . c om*/ * @param duration * the duration * @return A String of the following format: h:MM:ss[.m+] */ public static String convertLongToDuration(final long duration) { final Period period = new Period(duration); return periodFormatter.print(period); }
From source file:org.thelq.pircbotx.commands.CountdownCommand.java
License:Open Source License
@Override public void onMessage(final MessageEvent event) throws Exception { if (!ListenerUtils.isCommand(event.getMessage(), "countdown")) return;//w w w .j a va 2s.c om ListenerUtils.incrimentCommands(event); Alarm existingAlarm = openAlarms.get(event.getUser()); if (existingAlarm != null) { event.respond("You already have a countdown open. Please wait for it to finish"); return; } //Split up the line String[] messageParts = event.getMessage().split(" ", 2); if (messageParts.length != 2 || messageParts[1].trim().length() == 0) { event.respond("No time passsed"); return; } //Parse Period parsePeriod; try { parsePeriod = periodFormatterSec.parsePeriod(messageParts[1]); } catch (IllegalArgumentException e) { try { parsePeriod = periodFormatterMinSec.parsePeriod(messageParts[1]); } catch (IllegalArgumentException ex) { event.respond("Cannot parse period"); throw ex; } } //Start the process DateTime alarmTime = new DateTime(DateTimeZone.UTC).plus(parsePeriod); Alarm alarm = new Alarm(alarmTime) { protected Logger log = LoggerFactory.getLogger(getClass()); @Override public List<Integer> getNotifySeconds(long totalSeconds) { List<Integer> notifyTimes = Lists.newArrayList(); for (int i = (int) (totalSeconds % 60); i >= 1; i--) notifyTimes.add(i * 60); notifyTimes.add(30); notifyTimes.add(10); notifyTimes.add(5); notifyTimes.add(2); return notifyTimes; } @Override public void onStart(long secondsTillNotify) { sendMessageNowAlarm("Countdown starting..."); } @Override public void onNotifyBefore(long secondsToWait) { log.debug("Waiting " + secondsToWait + " seconds to notify user " + event.getUser().getNick()); } @Override public void onNotify(long secondsRemain) { sendMessageNowAlarm(FORMATTER_REMAIN.print(new Period(1000 * secondsRemain)) + "remaining"); } @Override public void onEnd() { sendMessageNowAlarm("Done! Drift: " + calcDrift()); } protected void sendMessageNowAlarm(String message) { sendMessageNow(event.getBot(), event.getChannel(), event.getUser().getNick() + ": " + message); } }; openAlarms.put(event.getUser(), alarm); //Generate notify times List<Integer> notifyTimes = Lists.newArrayList(); alarm.countdown(); openAlarms.remove(event.getUser()); }