public static String durationFormater(long duration) { Duration yourDuration = new Duration(duration); Period period = yourDuration.toPeriod(); PeriodFormatter minutesAndSeconds = new PeriodFormatterBuilder() .printZeroAlways() .appendMinutes() .minimumPrintedDigits(2) .appendSeparator(":") .appendSeconds() .minimumPrintedDigits(2) .toFormatter(); return minutesAndSeconds.print(period); }
private void repeatUpdateStats() { TextView view = (TextView) findViewById(R.id.totalClicks); view.setText(String.valueOf(clicks.getClicks())); view = (TextView) findViewById(R.id.timeDisplay); view.setText(periodFormat.print(period.normalizedStandard())); }
/** * Creates a new <code>Weeks</code> by parsing a string in the ISO8601 format 'PnW'. * * <p>The parse will accept the full ISO syntax of PnYnMnWnDTnHnMnS however only the weeks * component may be non-zero. If any other component is non-zero, an exception will be thrown. * * @param periodStr the period string, null returns zero * @return the period in weeks * @throws IllegalArgumentException if the string format is invalid */ @FromString public static Weeks parseWeeks(String periodStr) { if (periodStr == null) { return Weeks.ZERO; } Period p = PARSER.parsePeriod(periodStr); return Weeks.weeks(p.getWeeks()); }
@Override public void setMessage(IMessage msg, boolean incomming) { super.setMessage(msg, incomming); boolean playing = message.getPlaying(); View convertView = this; final IMessage.Audio audio = (IMessage.Audio) msg.content; AudioHolder audioHolder = new AudioHolder(convertView); if (playing) { AnimationDrawable voiceAnimation; if (incomming) { audioHolder.control.setImageResource(R.anim.voice_from_icon); } else { audioHolder.control.setImageResource(R.anim.voice_to_icon); } voiceAnimation = (AnimationDrawable) audioHolder.control.getDrawable(); voiceAnimation.start(); } else { if (incomming) { audioHolder.control.setImageResource(R.drawable.ease_chatfrom_voice_playing); } else { audioHolder.control.setImageResource(R.drawable.ease_chatto_voice_playing); } } Period period = new Period().withSeconds((int) audio.duration); PeriodFormatter periodFormatter = new PeriodFormatterBuilder() .appendMinutes() .appendSeparator(":") .appendSeconds() .appendSuffix("\"") .toFormatter(); audioHolder.duration.setText(periodFormatter.print(period)); // boolean uploading = msg.getUploading(); // if (uploading) { // uploadingProgressBar.setVisibility(View.VISIBLE); // } else { // uploadingProgressBar.setVisibility(View.GONE); // } convertView.requestLayout(); }
public String getRuntime(Timestamp start, Timestamp end) { Duration duration = new Duration(end.getTime() - start.getTime()); // in milliseconds PeriodFormatter formatter = new PeriodFormatterBuilder() .appendDays() .appendSuffix("d ") .appendHours() .appendSuffix("h ") .appendMinutes() .appendSuffix("m ") .appendSeconds() .appendSuffix("s") .toFormatter(); String formattedDuration = formatter.print(duration.toPeriod()); if (formattedDuration.isEmpty()) { return "0s"; } return formattedDuration; }
/** {@inheritDoc} */ @Override public Number parse(String source) throws ParseException { if (source == null || source.length() == 0) { return null; } try { return formatter.parsePeriod(source).toDurationFrom(new Instant(0)).getMillis(); } catch (Throwable t) { throw new ParseException(t.getMessage(), 0); } }
/** {@inheritDoc} */ @Override public String format(Number value) { if (value == null) { return null; } try { return formatter.print(new Period(0, value.longValue())); } catch (Throwable t) { return null; } }
public String toString(String keywordName) { /* Use the same format as the one initially provided. I.e. if a * relative time period was set initially, we want a relative period * to come back out. Otherwise it is a different search */ String operator = getOperator(); if ("=".equals(operator)) operator = ""; String string = keywordName + ":\"" + operator; if (mPeriod != null) { return string + periodParser.print(mPeriod) + '"'; } else { return string + mDateTime.toString(sLocalFormat) + '"'; } }
public String getTimeSinceCreated() { Period period = new Period(new DateTime(getCreated()), new DateTime()); PeriodFormatter formatter = new PeriodFormatterBuilder() .appendYears() .appendSuffix(" year", " years") .appendSeparator(" ") .appendMonths() .appendSuffix(" month", " months") .appendSeparator(" ") .appendDays() .appendSuffix(" day", " days") .appendSeparator(" ") .appendHours() .appendSuffix(" hour", " hours") .appendSeparator(" ") .printZeroAlways() .appendMinutes() .appendSuffix(" minute", " minutes") .appendSuffix(" ago") .toFormatter(); return formatter.print(period); }
protected void actionAdjustment() { String result = (String) JOptionPane.showInputDialog(this, "Enter an adjustment", "0 00:00:00.000"); if (result != null && !result.isEmpty()) { try { Period adjustment = format_short.parsePeriod(result); DateTime start = new DateTime(); DateTime end = start.plus(adjustment); TimeSpan ts = new TimeSpan(start, end); times.add(ts); period = period.plus(adjustment); updateTimes(); } catch (IllegalArgumentException ex) { JOptionPane.showMessageDialog(this, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE); } } }
@Override public String describe() { if (mDateTime != null) return prettyFormatter.print(mDateTime); else return periodParser.print(mPeriod); }
private String getPrintableTtl(long ttl) { return PERIOD_FORMATTER.print(new Period(ttl).normalizedStandard(PeriodType.dayTime())); }
@RequestMapping(value = "/studies/{study}/validateAndTestRule", method = RequestMethod.POST) public @ResponseBody org.openclinica.ns.rules_test.v31.RulesTest create( @RequestBody org.openclinica.ns.rules_test.v31.RulesTest ruleTest, Model model, HttpSession session, @PathVariable("study") String studyOid) throws Exception { ResourceBundleProvider.updateLocale(new Locale("en_US")); RulesPostImportContainer rpic = mapRulesToRulesPostImportContainer(ruleTest.getRules()); StudyDAO studyDao = new StudyDAO(dataSource); StudyBean currentStudy = studyDao.findByOid(studyOid); UserAccountBean userAccount = getUserAccount(); mayProceed(userAccount, currentStudy); getRulePostImportContainerService(currentStudy, userAccount); rpic = getRulePostImportContainerService(currentStudy, userAccount).validateRuleDefs(rpic); rpic = getRulePostImportContainerService(currentStudy, userAccount).validateRuleSetDefs(rpic); Response response = new Response(); response.setValid(Boolean.TRUE); if (rpic.getInValidRuleDefs().size() > 0 || rpic.getInValidRuleSetDefs().size() > 0) { response.setValid(Boolean.FALSE); for (AuditableBeanWrapper<RuleBean> beanWrapper : rpic.getInValidRuleDefs()) { for (String error : beanWrapper.getImportErrors()) { org.openclinica.ns.response.v31.MessagesType messageType = new MessagesType(); messageType.setMessage(error); response.getMessages().add(messageType); } } for (AuditableBeanWrapper<RuleSetBean> beanWrapper : rpic.getInValidRuleSetDefs()) { for (String error : beanWrapper.getImportErrors()) { org.openclinica.ns.response.v31.MessagesType messageType = new MessagesType(); messageType.setMessage(error); response.getMessages().add(messageType); } } } HashMap<String, String> p = new HashMap<String, String>(); for (ParameterType parameterType : ruleTest.getParameters()) { p.put(parameterType.getKey(), parameterType.getValue()); } ExpressionObjectWrapper eow = new ExpressionObjectWrapper( dataSource, currentStudy, rpic.getRuleDefs().get(0).getExpression(), rpic.getRuleSets().get(0)); ExpressionProcessor ep = ExpressionProcessorFactory.createExpressionProcessor(eow); // Run expression with populated HashMap DateTime start = new DateTime(); HashMap<String, String> result = ep.testEvaluateExpression(p); DateTime end = new DateTime(); Duration dur = new Duration(start, end); PeriodFormatter yearsAndMonths = new PeriodFormatterBuilder() .printZeroAlways() .appendSecondsWithMillis() .appendSuffix(" second", " seconds") .toFormatter(); yearsAndMonths.print(dur.toPeriod()); // Run expression with empty HashMap to check rule validity, because // using illegal test values will cause invalidity HashMap<String, String> k = new HashMap<String, String>(); HashMap<String, String> theResult = ep.testEvaluateExpression(k); ruleTest.getParameters().clear(); for (Map.Entry<String, String> entry : result.entrySet()) { ParameterType parameterType = new ParameterType(); parameterType.setKey(entry.getKey()); parameterType.setValue(entry.getValue()); ruleTest.getParameters().add(parameterType); } // if (theResult.get("ruleValidation").equals("rule_valid") && // result.get("ruleValidation").equals("rule_invalid")) { // result.put("ruleValidation", "rule_valid"); // result.put("ruleEvaluatesTo", resword.getString("test_rules_rule_fail") + " " + // result.get("ruleValidationFailMessage")); // result.remove("ruleValidationFailMessage"); // } // Put on screen // request.setAttribute("duration", yearsAndMonths.print(dur.toPeriod())); RulesTestMessagesType messageType = new RulesTestMessagesType(); messageType.setKey("duration"); messageType.setValue(yearsAndMonths.print(dur.toPeriod())); ruleTest.getRulesTestMessages().add(messageType); return ruleTest; }
public static String formatDuration(long duration) { return TIME_FORMATTER.print(new Period(0, duration / 1000000)); }