) { return this.print(duration, width, false, Integer.MAX_VALUE);
System.out.println(pt.printRelative(moment, paris)); System.out.println(pt.printRelative(now, paris)); System.out.println(pt.printRelative(shortTimeAgo, paris)); System.out.println(pt.printRelative(shortTimeAgo, Timezone.of(paris), precision)); DAYS, HOURS, MINUTES); System.out.println(pt.print(duration)); System.out.println(pt.print(duration, TextWidth.ABBREVIATED));
/** * <p>Determines that weeks will always be normalized to days. </p> * * @return changed copy of this instance * @since 2.0 */ /*[deutsch] * <p>Legt fest, daß Wochen immer zu Tagen normalisiert werden. </p> * * @return changed copy of this instance * @since 2.0 */ public PrettyTime withWeeksToDays() { if (this.weekToDays) { return this; } return new PrettyTime( this.locale, this.refClock, this.zeroDigit, this.minusSign, this.emptyUnit, true, this.shortStyle); }
return this.getEmptyRelativeString(precision); return this.getEmptyRelativeString(precision); pattern = this.getPastPattern(amount, (CalendarUnit) unit); } else { pattern = this.getPastPattern(amount, (ClockUnit) unit); pattern = this.getFuturePattern(amount, (CalendarUnit) unit); } else { pattern = this.getFuturePattern(amount, (ClockUnit) unit); return this.format(pattern, amount);
if (this.emptyUnit.isCalendrical()) { CalendarUnit unit = CalendarUnit.class.cast(this.emptyUnit); return this.print(0, unit, width); } else { ClockUnit unit = ClockUnit.class.cast(this.emptyUnit); return this.print(0, unit, width); pushDuration(values, duration, this.refClock, this.weekToDays); ) { IsoUnit unit = ((i == 7) ? NANOS : STD_UNITS[i]); parts.add(this.format(values[i], unit, negative, width)); count++;
public void sendRealtimeAgentHealth(Account account, List<JvmAgentStatus> statusList) { VelocityContext ctx = new VelocityContext(); ctx.put("username", account.username()); List<Cluster> clusters = new ArrayList<>(); statusList.forEach(jas -> { Cluster c = new Cluster(); c.name = jas.getAnalysis().name(); List<Jvm> jvms = new ArrayList<>(); jas.getJvms().forEach(p -> { Jvm jvm = new Jvm(); jvm.name = p.getKey(); Duration dur = Duration.of(p.getValue(), ClockUnit.SECONDS).with(Duration.STD_CLOCK_PERIOD); jvm.period = PrettyTime.of(Locale.ENGLISH).print(dur, TextWidth.ABBREVIATED); jvms.add(jvm); }); c.jvms = jvms; clusters.add(c); }); ctx.put("clusters", clusters); String template = config.readString(ConfigProperty.EMAIL_AGENT_HEALTH_TEMPLATE); StringWriter msg = new StringWriter((int) (template.length() * 1.5)); if (Velocity.evaluate(ctx, msg, account.username(), template)) { sendNotification(account, "Real-time Agent Health Status", msg.toString()); } else { LOG.info("Unable to generate velocity template for message."); } }
/** * <p>Formats given threeten object relative to the current time of * {@link #getReferenceClock()} as duration in at most second * precision or less. </p> * * @param zdt relative time * @return formatted output of relative time, either in past or in future * @see #printRelative(Instant, ZoneId) * @since 4.8 */ /*[deutsch] * <p>Formatiert den angegebenen Zeitpunkt in JSR-310-Schreibweise relativ zur aktuellen Zeit * der Referenzuhr {@link #getReferenceClock()} als Dauer in maximal * Sekundengenauigkeit. </p> * * @param zdt relative time * @return formatted output of relative time, either in past or in future * @see #printRelative(Instant, ZoneId) * @since 4.8 */ public String printRelative(ZonedDateTime zdt) { return this.printRelative(zdt.toInstant(), zdt.getZone()); }
private String printRelativeSeconds( Moment t1, Moment t2, long delta ) { if (t1.getPosixTime() >= START_1972 && t2.getPosixTime() >= START_1972) { delta = SI.SECONDS.between(t1, t2); // leap second correction } if (delta == 0) { return UnitPatterns.of(this.locale).getNowWord(); } long amount = Math.abs(delta); String pattern = ( (delta < 0) ? this.getPastPattern(amount, ClockUnit.SECONDS) : this.getFuturePattern(amount, ClockUnit.SECONDS)); return this.format(pattern, amount); }
/** * <p>Formats given duration in clock units. </p> * * @param amount count of units (quantity) * @param unit clock unit * @param width text width (ABBREVIATED as synonym for SHORT) * @return formatted output * @since 1.2 * @see #print(Duration, TextWidth) */ /*[deutsch] * <p>Formatiert die angegebene Dauer in Uhrzeiteinheiten. </p> * * @param amount Anzahl der Einheiten * @param unit Uhrzeiteinheit * @param width text width (ABBREVIATED as synonym for SHORT) * @return formatierte Ausgabe * @since 1.2 * @see #print(Duration, TextWidth) */ public String print( long amount, ClockUnit unit, TextWidth width ) { String pattern = UnitPatterns.of(this.locale).getPattern(width, this.getCategory(amount), unit); return this.format(pattern, amount); }
private String getFuturePattern( long amount, ClockUnit unit ) { UnitPatterns patterns = UnitPatterns.of(this.locale); PluralCategory category = this.getCategory(amount); return patterns.getPatternInFuture(category, this.shortStyle, unit); }
/** * <p>Determines the localized word for "today". </p> * * @return String * @since 3.24/4.20 */ /*[deutsch] * <p>Ermittelt das lokalisierte Wort für "heute". </p> * * @return String * @since 3.24/4.20 */ public String printToday() { return UnitPatterns.of(this.getLocale()).getTodayWord(); }
private String format( String pattern, long amount ) { for (int i = 0, n = pattern.length(); i < n; i++) { if ( (i < n - 2) && (pattern.charAt(i) == '{') && (pattern.charAt(i + 1) == '0') && (pattern.charAt(i + 2) == '}') ) { StringBuilder sb = new StringBuilder(pattern); sb.replace(i, i + 3, this.format(amount)); return sb.toString(); } } if (amount < 0) { return this.minusSign + pattern; } return pattern; }
Moment refTime = Moment.from(this.getReferenceClock().currentTime()); PlainDate refDate = refTime.toZonalTimestamp(tzid).toDate(); Duration<CalendarUnit> duration; return this.getEmptyRelativeString(TimeUnit.DAYS); ? this.getPastPattern(amount, unit) : this.getFuturePattern(amount, unit)); return this.format(pattern, amount);
/** * <p>Formats given time point relative to the current time of * {@link #getReferenceClock()} as duration in at most second * precision or less - using the system timezone. </p> * * @param moment relative time point * @return formatted output of relative time, either in past or in future * @see #printRelative(UnixTime, Timezone, TimeUnit) * @since 3.4/4.3 */ /*[deutsch] * <p>Formatiert den angegebenen Zeitpunkt relativ zur aktuellen Zeit * der Referenzuhr {@link #getReferenceClock()} als Dauer in maximal * Sekundengenauigkeit - bezüglich der Systemzeitzone. </p> * * @param moment relative time point * @return formatted output of relative time, either in past or in future * @see #printRelative(UnixTime, Timezone, TimeUnit) * @since 3.4/4.3 */ public String printRelativeInStdTimezone(UnixTime moment) { return this.printRelative(moment, Timezone.ofSystem(), TimeUnit.SECONDS); }
String pattern = p.getPattern(width, this.getCategory(amount), u); return this.format(pattern, amount);
private String getPastPattern( long amount, CalendarUnit unit ) { UnitPatterns patterns = UnitPatterns.of(this.locale); PluralCategory category = this.getCategory(amount); return patterns.getPatternInPast(category, this.shortStyle, unit); }
/** * <p>Determines the localized word for "tomorrow". </p> * * @return String * @since 3.43/4.38 */ /*[deutsch] * <p>Ermittelt das lokalisierte Wort für "morgen". </p> * * @return String * @since 3.43/4.38 */ public String printTomorrow() { return UnitPatterns.of(this.getLocale()).getTomorrowWord(); }
return this.print(duration, width, false, Integer.MAX_VALUE);
/** * <p>Formats given time point relative to the current time of * {@link #getReferenceClock()} as duration in at most second * precision or less. </p> * * @param moment relative time point * @param tzid time zone id for translating to a local duration * @return formatted output of relative time, either in past or in future * @see #printRelative(UnixTime, Timezone, TimeUnit) * @since 1.2 */ /*[deutsch] * <p>Formatiert den angegebenen Zeitpunkt relativ zur aktuellen Zeit * der Referenzuhr {@link #getReferenceClock()} als Dauer in maximal * Sekundengenauigkeit. </p> * * @param moment relative time point * @param tzid time zone id for translating to a local duration * @return formatted output of relative time, either in past or in future * @see #printRelative(UnixTime, Timezone, TimeUnit) * @since 1.2 */ public String printRelative( UnixTime moment, String tzid ) { return this.printRelative(moment, Timezone.of(tzid), TimeUnit.SECONDS); }
return new PrettyTime( this.locale, clock,