Example usage for org.joda.time Duration Duration

List of usage examples for org.joda.time Duration Duration

Introduction

In this page you can find the example usage for org.joda.time Duration Duration.

Prototype

public Duration(Object duration) 

Source Link

Document

Creates a duration from the specified object using the org.joda.time.convert.ConverterManager ConverterManager .

Usage

From source file:com.nesscomputing.cache.PrefixedCacheBuilder.java

License:Apache License

public PrefixedCacheBuilder<P, K, V> withExpirationAndJitter(final TimeSpan withExpiration,
        final TimeSpan withJitter) {
    this.expiration = new Duration(withExpiration.getMillis());
    this.jitter = new Duration(withJitter.getMillis());

    return this;
}

From source file:com.nesscomputing.quartz.NessQuartzModule.java

License:Apache License

private static Duration parseDuration(final Configuration config, final String key) {
    final TimeSpan timeSpan = new TimeSpan(config.getString(key));
    return new Duration(timeSpan.getMillis());
}

From source file:com.nullpointerengineering.android.pomodoro.model.event.EventImpl.java

License:Apache License

public EventImpl(long id, long timeCreatedInMillis, Event.Type type, long totalDurationInMillis,
        long actualDurationInMillis) {
    checkArgument(id >= 0, "Illegal id " + id);
    checkArgument(timeCreatedInMillis >= 0, BAD_TIME_ARGUMENT);
    checkArgument(totalDurationInMillis >= 0, BAD_TIME_ARGUMENT);
    checkArgument(actualDurationInMillis >= 0, BAD_TIME_ARGUMENT);

    this.id = id;
    timeCreated = new DateTime(timeCreatedInMillis * 1000);
    this.type = type;
    totalDuration = new Duration(totalDurationInMillis);
    actualDuration = new Duration(actualDurationInMillis);
}

From source file:com.phloc.datetime.config.PDTTypeConverterRegistrar.java

License:Apache License

public void registerTypeConverter(@Nonnull final ITypeConverterRegistry aRegistry) {
    // Register Joda native converters
    _registerJodaConverter();//from  w  ww.  j a va  2  s .c  o m

    // DateTime
    aRegistry.registerTypeConverter(
            new Class<?>[] { String.class, Calendar.class, GregorianCalendar.class, Date.class,
                    AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class,
                    Double.class, Float.class, Integer.class, Long.class, Short.class },
            DateTime.class, new ITypeConverter() {
                @Nonnull
                public DateTime convert(@Nonnull final Object aSource) {
                    return new DateTime(aSource, PDTConfig.getDefaultChronology());
                }
            });
    aRegistry.registerTypeConverter(LocalDate.class, DateTime.class, new ITypeConverter() {
        @Nonnull
        public DateTime convert(@Nonnull final Object aSource) {
            return PDTFactory.createDateTime((LocalDate) aSource);
        }
    });
    aRegistry.registerTypeConverter(LocalTime.class, DateTime.class, new ITypeConverter() {
        @Nonnull
        public DateTime convert(@Nonnull final Object aSource) {
            return PDTFactory.createDateTime((LocalTime) aSource);
        }
    });
    aRegistry.registerTypeConverter(LocalDateTime.class, DateTime.class, new ITypeConverter() {
        @Nonnull
        public DateTime convert(@Nonnull final Object aSource) {
            return PDTFactory.createDateTime((LocalDateTime) aSource);
        }
    });

    // LocalDateTime
    aRegistry.registerTypeConverter(
            new Class<?>[] { String.class, Calendar.class, GregorianCalendar.class, Date.class,
                    AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class,
                    Double.class, Float.class, Integer.class, Long.class, Short.class },
            LocalDateTime.class, new ITypeConverter() {
                @Nonnull
                public LocalDateTime convert(@Nonnull final Object aSource) {
                    return new LocalDateTime(aSource, PDTConfig.getDefaultChronology());
                }
            });
    aRegistry.registerTypeConverter(DateTime.class, LocalDateTime.class, new ITypeConverter() {
        @Nonnull
        public LocalDateTime convert(@Nonnull final Object aSource) {
            return PDTFactory.createLocalDateTime((DateTime) aSource);
        }
    });
    aRegistry.registerTypeConverter(LocalDate.class, LocalDateTime.class, new ITypeConverter() {
        @Nonnull
        public LocalDateTime convert(@Nonnull final Object aSource) {
            return PDTFactory.createLocalDateTime((LocalDate) aSource);
        }
    });
    aRegistry.registerTypeConverter(LocalTime.class, LocalDateTime.class, new ITypeConverter() {
        @Nonnull
        public LocalDateTime convert(@Nonnull final Object aSource) {
            return PDTFactory.createLocalDateTime((LocalTime) aSource);
        }
    });

    // LocalDate
    aRegistry.registerTypeConverter(
            new Class<?>[] { String.class, Calendar.class, GregorianCalendar.class, Date.class,
                    AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class,
                    Double.class, Float.class, Integer.class, Long.class, Short.class },
            LocalDate.class, new ITypeConverter() {
                @Nonnull
                public LocalDate convert(@Nonnull final Object aSource) {
                    return new LocalDate(aSource, PDTConfig.getDefaultChronology());
                }
            });
    aRegistry.registerTypeConverter(DateTime.class, LocalDate.class, new ITypeConverter() {
        @Nonnull
        public LocalDate convert(@Nonnull final Object aSource) {
            return PDTFactory.createLocalDate((DateTime) aSource);
        }
    });
    aRegistry.registerTypeConverter(LocalDateTime.class, LocalDate.class, new ITypeConverter() {
        @Nonnull
        public LocalDate convert(@Nonnull final Object aSource) {
            return PDTFactory.createLocalDate((LocalDateTime) aSource);
        }
    });

    // LocalTime
    aRegistry.registerTypeConverter(
            new Class<?>[] { String.class, Calendar.class, GregorianCalendar.class, Date.class,
                    AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class,
                    Double.class, Float.class, Integer.class, Long.class, Short.class },
            LocalTime.class, new ITypeConverter() {
                @Nonnull
                public LocalTime convert(@Nonnull final Object aSource) {
                    return new LocalTime(aSource, PDTConfig.getDefaultChronology());
                }
            });
    aRegistry.registerTypeConverter(DateTime.class, LocalTime.class, new ITypeConverter() {
        @Nonnull
        public LocalTime convert(@Nonnull final Object aSource) {
            return PDTFactory.createLocalTime((DateTime) aSource);
        }
    });
    aRegistry.registerTypeConverter(LocalDateTime.class, LocalTime.class, new ITypeConverter() {
        @Nonnull
        public LocalTime convert(@Nonnull final Object aSource) {
            return PDTFactory.createLocalTime((LocalDateTime) aSource);
        }
    });

    // Duration
    aRegistry.registerTypeConverter(new Class<?>[] { String.class, AtomicInteger.class, AtomicLong.class,
            BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class,
            Long.class, Short.class }, Duration.class, new ITypeConverter() {
                @Nonnull
                public Duration convert(@Nonnull final Object aSource) {
                    return new Duration(aSource);
                }
            });

    // Duration
    aRegistry.registerTypeConverter(new Class<?>[] { String.class, AtomicInteger.class, AtomicLong.class,
            BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class,
            Long.class, Short.class }, Period.class, new ITypeConverter() {
                @Nonnull
                public Period convert(@Nonnull final Object aSource) {
                    return new Period(aSource);
                }
            });
}

From source file:com.sector91.wit.http.Session.java

License:Apache License

public final void expireAfter(long quantity, TimeUnit unit) {
    expireAfter(new Duration(unit.toMillis(quantity)));
    try {/*from w  ww.j a va 2  s .c o  m*/
        store.update(id, this);
    } catch (DataException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.squarespace.template.plugins.PluginDateUtils.java

License:Apache License

public static void humanizeDate(long instantMs, long baseMs, String tzId, boolean showSeconds,
        StringBuilder buf) {//from   www  .j a  v a 2  s.c o  m
    DateTimeZone timeZone = DateTimeZone.forID(tzId);
    int offset = timeZone.getOffset(instantMs);
    Duration delta = new Duration(baseMs - instantMs + offset);

    int days = (int) delta.getStandardDays();
    int years = (int) Math.floor(days / 365.0);
    if (years > 0) {
        humanizeDatePlural(years, DatePartType.YEAR, buf);
        return;
    }
    int months = (int) Math.floor(days / 30.0);
    if (months > 0) {
        humanizeDatePlural(months, DatePartType.MONTH, buf);
        return;
    }
    int weeks = (int) Math.floor(days / 7.0);
    if (weeks > 0) {
        humanizeDatePlural(weeks, DatePartType.WEEK, buf);
        return;
    }
    if (days > 0) {
        humanizeDatePlural(days, DatePartType.DAY, buf);
        return;
    }
    int hours = (int) delta.getStandardHours();
    if (hours > 0) {
        humanizeDatePlural(hours, DatePartType.HOUR, buf);
        return;
    }
    int mins = (int) delta.getStandardMinutes();
    if (mins > 0) {
        humanizeDatePlural(mins, DatePartType.MINUTE, buf);
        return;
    }
    int secs = (int) delta.getStandardSeconds();
    if (showSeconds) {
        humanizeDatePlural(secs, DatePartType.SECOND, buf);
        return;
    }
    buf.append("less than a minute ago");
}

From source file:com.studium.joda.converters.JodaDurationConverter.java

License:Apache License

public Duration convertToEntityAttribute(Long mills) {
    return mills == null ? null : new Duration(mills);
}

From source file:com.technophobia.substeps.report.DetailedJsonBuilder.java

License:Open Source License

private String convert(long runningDurationMillis) {
    Duration duration = new Duration(runningDurationMillis);
    PeriodFormatter formatter = PeriodFormat.getDefault();
    return formatter.print(duration.toPeriod());
}

From source file:com.thoughtworks.go.domain.JobInstance.java

License:Apache License

public Duration getElapsedTime() {
    return new Duration(elapsedSeconds() * 1000);
}

From source file:com.thoughtworks.go.domain.JobInstance.java

License:Apache License

public RunDuration getDuration() {
    if (!isCompleted()) {
        return RunDuration.IN_PROGRESS_DURATION;
    }//from  ww w .  java  2 s .com
    Date scheduleStartTime = getStartedDateFor(JobState.Scheduled);
    Date completedTime = getCompletedDate();
    return new RunDuration.ActualDuration(new Duration(completedTime.getTime() - scheduleStartTime.getTime()));
}