use of org.joda.time.format.PeriodFormatterBuilder in project opennms by OpenNMS.
the class NewtsConverter method main.
/**
* The main method.
*
* @param args the arguments
*/
public static void main(final String... args) {
final long start;
try (final NewtsConverter converter = new NewtsConverter(args)) {
start = System.currentTimeMillis();
converter.execute();
} catch (final NewtsConverterError e) {
LOG.error(e.getMessage(), e);
System.exit(1);
throw null;
}
final Period period = new Interval(start, System.currentTimeMillis()).toPeriod();
final PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix(" days ").appendHours().appendSuffix(" hours ").appendMinutes().appendSuffix(" min ").appendSeconds().appendSuffix(" sec ").printZeroNever().toFormatter();
LOG.info("Conversion Finished: metrics: {}, samples: {}, time: {}", processedMetrics, processedSamples, formatter.print(period));
System.exit(0);
}
use of org.joda.time.format.PeriodFormatterBuilder in project knox by apache.
the class DefaultHttpClientFactory method parseTimeout.
private static long parseTimeout(String s) {
PeriodFormatter f = new PeriodFormatterBuilder().appendMinutes().appendSuffix("m", " min").appendSeconds().appendSuffix("s", " sec").appendMillis().toFormatter();
Period p = Period.parse(s, f);
return p.toStandardDuration().getMillis();
}
use of org.joda.time.format.PeriodFormatterBuilder in project knox by apache.
the class GatewayConfigImpl method getGatewayDeploymentsBackupAgeLimit.
@Override
public long getGatewayDeploymentsBackupAgeLimit() {
PeriodFormatter f = new PeriodFormatterBuilder().appendDays().toFormatter();
String s = get(DEPLOYMENTS_BACKUP_AGE_LIMIT, "-1");
long d;
try {
Period p = Period.parse(s, f);
d = p.toStandardDuration().getMillis();
if (d < 0) {
d = -1;
}
} catch (Exception e) {
d = -1;
}
return d;
}
use of org.joda.time.format.PeriodFormatterBuilder in project incubator-gobblin by apache.
the class RecompactionConditionTest method testRecompactionConditionBasedOnDuration.
@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);
}
use of org.joda.time.format.PeriodFormatterBuilder in project TeamCityApp by vase4kin.
the class DateUtils method formatDateToOverview.
/**
* Format date to Overview screen to format "20 Apr 15 16:14:28 - 16:14:46 (18s)"
*/
public String formatDateToOverview() {
String formattedStartDate = formatStartDateToBuildTitle();
String formattedFinishedDate = formatFinishedDate();
Duration duration = new Duration(new DateTime(finishedDate).minus(startDate.getTime()).getMillis());
PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix("d:").appendHours().appendSuffix("h:").appendMinutes().appendSuffix("m:").appendSeconds().appendSuffix("s").toFormatter();
String formatted = formatter.print(duration.toPeriod());
return String.format("%s - %s (%s)", formattedStartDate, formattedFinishedDate, formatted);
}
Aggregations