本文整理汇总了Java中org.joda.time.format.PeriodFormatter类的典型用法代码示例。如果您正苦于以下问题:Java PeriodFormatter类的具体用法?Java PeriodFormatter怎么用?Java PeriodFormatter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PeriodFormatter类属于org.joda.time.format包,在下文中一共展示了PeriodFormatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatDuration
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
public static String formatDuration(long duration)
{
// Using Joda Time
DateTime now = new DateTime(); // Now
DateTime plus = now.plus(new Duration(duration * 1000));
// Define and calculate the interval of time
Interval interval = new Interval(now.getMillis(), plus.getMillis());
Period period = interval.toPeriod(PeriodType.time());
// Define the period formatter for pretty printing
String ampersand = " & ";
PeriodFormatter pf = new PeriodFormatterBuilder().appendHours().appendSuffix(ds("hour"), ds("hours"))
.appendSeparator(" ", ampersand).appendMinutes().appendSuffix(ds("minute"), ds("minutes"))
.appendSeparator(ampersand).appendSeconds().appendSuffix(ds("second"), ds("seconds")).toFormatter();
return pf.print(period).trim();
}
示例2: prettifyDuration
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
private String prettifyDuration(String duration) {
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendDays().appendSuffix("d")
.appendHours().appendSuffix(":")
.appendMinutes().appendSuffix(":")
.appendSeconds().toFormatter();
Period p = formatter.parsePeriod(duration);
String day = context.getResources().getString(R.string.day_short);
if(p.getDays() > 0) {
return String.format("%d"+ day + " %dh %dm", p.getDays(), p.getHours(), p.getMinutes());
} else if (p.getHours() > 0) {
return String.format(Locale.getDefault(), "%dh %dm", p.getHours(), p.getMinutes());
} else {
return String.format(Locale.getDefault(), "%dm", p.getMinutes());
}
}
示例3: calculateAge
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
private static String calculateAge(DateTime epDate) {
Period period;
if (epDate.isBefore(new DateTime())) {
period = new Period(epDate, new DateTime());
} else {
period = new Period(new DateTime(), epDate);
}
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendYears().appendSuffix("y")
.appendMonths().appendSuffix("m")
.appendWeeks().appendSuffix("w")
.appendDays().appendSuffix("d ")
.appendHours().appendSuffix("h")
.appendMinutes().appendSuffix("m")
.printZeroNever().toFormatter();
return formatter.print(period);
}
示例4: dateHelper
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
private Helper<Long> dateHelper() {
return new Helper<Long>() {
public CharSequence apply(Long arg0, Options arg1) throws IOException {
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendDays()
.appendSuffix(" d : ")
.appendHours()
.appendSuffix(" h : ")
.appendMinutes()
.appendSuffix(" m : ")
.appendSeconds()
.appendSuffix(" s : ")
.appendMillis()
.appendSuffix(" ms")
.toFormatter();
return formatter.print(new Period((arg0 * 1) / 1000000));
}
};
}
示例5: folderWithinAllowedPeriod
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
/**
* Return true iff input folder time is between compaction.timebased.min.time.ago and
* compaction.timebased.max.time.ago.
*/
private boolean folderWithinAllowedPeriod(Path inputFolder, DateTime folderTime) {
DateTime currentTime = new DateTime(this.timeZone);
PeriodFormatter periodFormatter = getPeriodFormatter();
DateTime earliestAllowedFolderTime = getEarliestAllowedFolderTime(currentTime, periodFormatter);
DateTime latestAllowedFolderTime = getLatestAllowedFolderTime(currentTime, periodFormatter);
if (folderTime.isBefore(earliestAllowedFolderTime)) {
LOG.info(String.format("Folder time for %s is %s, earlier than the earliest allowed folder time, %s. Skipping",
inputFolder, folderTime, earliestAllowedFolderTime));
return false;
} else if (folderTime.isAfter(latestAllowedFolderTime)) {
LOG.info(String.format("Folder time for %s is %s, later than the latest allowed folder time, %s. Skipping",
inputFolder, folderTime, latestAllowedFolderTime));
return false;
} else {
return true;
}
}
示例6: parseYearMonthInterval
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
public static long parseYearMonthInterval(String value, IntervalField startField, Optional<IntervalField> endField)
{
IntervalField end = endField.orElse(startField);
if (startField == IntervalField.YEAR && end == IntervalField.MONTH) {
PeriodFormatter periodFormatter = INTERVAL_YEAR_MONTH_FORMATTER;
return parsePeriodMonths(value, periodFormatter, startField, end);
}
if (startField == IntervalField.YEAR && end == IntervalField.YEAR) {
return parsePeriodMonths(value, INTERVAL_YEAR_FORMATTER, startField, end);
}
if (startField == IntervalField.MONTH && end == IntervalField.MONTH) {
return parsePeriodMonths(value, INTERVAL_MONTH_FORMATTER, startField, end);
}
throw new IllegalArgumentException("Invalid year month interval qualifier: " + startField + " to " + end);
}
示例7: formattedDuration
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
public static String formattedDuration(long duration) {
PeriodFormatter hoursMinutes = new PeriodFormatterBuilder()
.appendHours()
.appendSuffix(" hr", " hrs")
.appendSeparator(" ")
.appendMinutes()
.appendSuffix(" min", " mins")
.appendSeparator(" ")
.appendSeconds()
.appendSuffix(" sec", " secs")
.toFormatter();
Period p = new Period(duration);
return hoursMinutes.print(p);
}
示例8: getGatewayDeploymentsBackupAgeLimit
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
public long getGatewayDeploymentsBackupAgeLimit() {
PeriodFormatter f = (new PeriodFormatterBuilder()).appendDays().toFormatter();
String s = this.get("gateway.deployment.backup.ageLimit", "-1");
long d;
try {
Period e = Period.parse(s, f);
d = e.toStandardDuration().getMillis();
if (d < 0L) {
d = -1L;
}
} catch (Exception var6) {
d = -1L;
}
return d;
}
示例9: periodHourMinBased
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
public static String periodHourMinBased(long secDuration) {
PeriodFormatterBuilder builder = new PeriodFormatterBuilder();
PeriodFormatter formatter = null;
String minutesAbbr = ToggApp.getApplication().getString(
R.string.minutes_abbr);
;
String hoursAbbr = ToggApp.getApplication().getString(
R.string.hours_abbr);
;
formatter = builder.printZeroAlways().minimumPrintedDigits(1)
.appendHours().appendLiteral(" " + hoursAbbr + " ")
.minimumPrintedDigits(2).appendMinutes()
.appendLiteral(" " + minutesAbbr).toFormatter();
Period period = new Period(secDuration * 1000);
return formatter.print(period.normalizedStandard());
}
示例10: providePeriodFormatter
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
@Singleton
@Provides
public PeriodFormatter providePeriodFormatter(Dictionary<String> dictionary) {
return new PeriodFormatterBuilder()
.appendYears()
.appendSuffix(" " + dictionary.getTranslation("year"), " " + dictionary.getTranslation("years"))
.appendSeparator(" ")
.appendMonths()
.appendSuffix(" " + dictionary.getTranslation("month"), " " + dictionary.getTranslation("months"))
.appendSeparator(" ")
.appendDays()
.appendSuffix(" " + dictionary.getTranslation("day"), " " + dictionary.getTranslation("days"))
.appendSeparator(" ")
.appendMinutes()
.appendSuffix(" " + dictionary.getTranslation("minute"), " " + dictionary.getTranslation("minutes"))
.appendSeparator(" ")
.appendSeconds()
.appendSuffix(" " + dictionary.getTranslation("second"), " " + dictionary.getTranslation("seconds"))
.toFormatter();
}
示例11: postFailureBuild
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
private void postFailureBuild(SRunningBuild build )
{
String message = "";
PeriodFormatter durationFormatter = new PeriodFormatterBuilder()
.printZeroRarelyFirst()
.appendHours()
.appendSuffix(" hour", " hours")
.appendSeparator(" ")
.printZeroRarelyLast()
.appendMinutes()
.appendSuffix(" minute", " minutes")
.appendSeparator(" and ")
.appendSeconds()
.appendSuffix(" second", " seconds")
.toFormatter();
Duration buildDuration = new Duration(1000*build.getDuration());
message = String.format("Project '%s' build failed! ( %s )" , build.getFullName() , durationFormatter.print(buildDuration.toPeriod()));
postToSlack(build, message, false);
}
示例12: processSuccessfulBuild
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
private void processSuccessfulBuild(SRunningBuild build) {
String message = "";
PeriodFormatter durationFormatter = new PeriodFormatterBuilder()
.printZeroRarelyFirst()
.appendHours()
.appendSuffix(" hour", " hours")
.appendSeparator(" ")
.printZeroRarelyLast()
.appendMinutes()
.appendSuffix(" minute", " minutes")
.appendSeparator(" and ")
.appendSeconds()
.appendSuffix(" second", " seconds")
.toFormatter();
Duration buildDuration = new Duration(1000*build.getDuration());
message = String.format("Project '%s' built successfully in %s." , build.getFullName() , durationFormatter.print(buildDuration.toPeriod()));
postToSlack(build, message, true);
}
示例13: folderWithinAllowedPeriod
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
/**
* Return true iff input folder time is between compaction.timebased.min.time.ago and
* compaction.timebased.max.time.ago.
*/
protected boolean folderWithinAllowedPeriod(Path inputFolder, DateTime folderTime) {
DateTime currentTime = new DateTime(this.timeZone);
PeriodFormatter periodFormatter = getPeriodFormatter();
DateTime earliestAllowedFolderTime = getEarliestAllowedFolderTime(currentTime, periodFormatter);
DateTime latestAllowedFolderTime = getLatestAllowedFolderTime(currentTime, periodFormatter);
if (folderTime.isBefore(earliestAllowedFolderTime)) {
log.info(String.format("Folder time for %s is %s, earlier than the earliest allowed folder time, %s. Skipping",
inputFolder, folderTime, earliestAllowedFolderTime));
return false;
} else if (folderTime.isAfter(latestAllowedFolderTime)) {
log.info(String.format("Folder time for %s is %s, later than the latest allowed folder time, %s. Skipping",
inputFolder, folderTime, latestAllowedFolderTime));
return false;
} else {
return true;
}
}
示例14: testRecompactionConditionBasedOnDuration
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
@Test
public void testRecompactionConditionBasedOnDuration() {
RecompactionConditionFactory factory = new RecompactionConditionBasedOnDuration.Factory();
RecompactionCondition conditionBasedOnDuration = factory.createRecompactionCondition(dataset);
DatasetHelper helper = mock (DatasetHelper.class);
when(helper.getDataset()).thenReturn(dataset);
PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendMonths().appendSuffix("m").appendDays().appendSuffix("d").appendHours()
.appendSuffix("h").appendMinutes().appendSuffix("min").toFormatter();
DateTime currentTime = getCurrentTime();
Period period_A = periodFormatter.parsePeriod("11h59min");
DateTime earliest_A = currentTime.minus(period_A);
when(helper.getEarliestLateFileModificationTime()).thenReturn(Optional.of(earliest_A));
when(helper.getCurrentTime()).thenReturn(currentTime);
Assert.assertEquals(conditionBasedOnDuration.isRecompactionNeeded(helper), false);
Period period_B = periodFormatter.parsePeriod("12h01min");
DateTime earliest_B = currentTime.minus(period_B);
when(helper.getEarliestLateFileModificationTime()).thenReturn(Optional.of(earliest_B));
when(helper.getCurrentTime()).thenReturn(currentTime);
Assert.assertEquals(conditionBasedOnDuration.isRecompactionNeeded(helper), true);
}
示例15: toAge
import org.joda.time.format.PeriodFormatter; //导入依赖的package包/类
public static String toAge(Date from, Date to) {
if (from == null || to == null) return "N/A";
final Period period = new Period(from.getTime(), to.getTime());
DurationFieldType[] dtf = new ArrayList<DurationFieldType>() {{
add(DurationFieldType.years()); add(DurationFieldType.months());
add(DurationFieldType.days());
if (period.getYears() == 0 && period.getMonths() == 0 && period.getDays() == 0) {
add(DurationFieldType.hours());
add(DurationFieldType.minutes());
}
}}.toArray(new DurationFieldType[0]);
PeriodFormatter pf = PeriodFormat.getDefault();
return pf.print(period.normalizedStandard(PeriodType.forFields(dtf)));
}