Search in sources :

Example 6 with PeriodFormatterBuilder

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);
}
Also used : PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) Period(org.joda.time.Period) Interval(org.joda.time.Interval)

Example 7 with PeriodFormatterBuilder

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();
}
Also used : PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) Period(org.joda.time.Period)

Example 8 with PeriodFormatterBuilder

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;
}
Also used : PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) Period(org.joda.time.Period) MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException)

Example 9 with PeriodFormatterBuilder

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);
}
Also used : PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) LoggerFactory(org.slf4j.LoggerFactory) RecompactionConditionFactory(org.apache.gobblin.compaction.conditions.RecompactionConditionFactory) Period(org.joda.time.Period) RecompactionCondition(org.apache.gobblin.compaction.conditions.RecompactionCondition) RecompactionConditionFactory(org.apache.gobblin.compaction.conditions.RecompactionConditionFactory) DatasetHelper(org.apache.gobblin.compaction.dataset.DatasetHelper) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 10 with PeriodFormatterBuilder

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);
}
Also used : PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) Duration(org.joda.time.Duration) DateTime(org.joda.time.DateTime)

Aggregations

PeriodFormatterBuilder (org.joda.time.format.PeriodFormatterBuilder)16 PeriodFormatter (org.joda.time.format.PeriodFormatter)15 Period (org.joda.time.Period)10 DateTime (org.joda.time.DateTime)6 Duration (org.joda.time.Duration)5 HashMap (java.util.HashMap)2 Map (java.util.Map)2 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)2 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)2 ExpressionProcessor (org.akaza.openclinica.domain.rule.expression.ExpressionProcessor)2 PeriodParser (org.joda.time.format.PeriodParser)2 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 MessageFormat (java.text.MessageFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 Matcher (java.util.regex.Matcher)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1