Example usage for org.joda.time Period Period

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

Introduction

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

Prototype

public Period(long startInstant, long endInstant, PeriodType type, Chronology chrono) 

Source Link

Document

Creates a period from the given interval endpoints.

Usage

From source file:com.enonic.cms.business.portal.datasource.expressionfunctions.ExpressionFunctions.java

License:Open Source License

public String periodHoursMinutes(int hours, int minutes) {
    Period period = new Period(hours, minutes, 0, 0);
    return period.toString();
}

From source file:com.enonic.cms.core.content.index.queryexpression.DateCompareEvaluator.java

License:Open Source License

private ReadableDateTime createUpperBoundDate(DateMidnight date) {
    DateTime dateMidnight = date.toDateTime();
    return dateMidnight.plus(new Period(23, 59, 59, 999));
}

From source file:com.thinkbiganalytics.policy.precondition.FeedExecutedSinceFeedsOrTime.java

License:Apache License

@Override
public Set<com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup> buildPreconditionObligations() {
    Set<com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup> preconditionGroups = new HashSet<>();
    preconditionGroups.addAll(super.buildPreconditionObligations());

    try {/*  w w w.j a  v  a  2s .  c  o m*/
        Period p = new Period(0, 0, 1, 0);
        String withinPeriod = p.toString();
        WithinSchedule metric = new WithinSchedule(cronExpression, withinPeriod);
        Obligation obligation = new Obligation();
        obligation.setMetrics(Lists.newArrayList(metric));
        com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup group = new com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup();
        group.addObligation(obligation);
        group.setCondition(ObligationGroup.Condition.SUFFICIENT.name());
        preconditionGroups.add(group);
    } catch (ParseException e) {

    }
    return preconditionGroups;
}

From source file:druid.examples.flights.FlightsConverter.java

License:Open Source License

public static void main(String[] args) throws IOException {
    DateTimeZone.setDefault(DateTimeZone.UTC);
    ObjectMapper mapper = new DefaultObjectMapper();

    File flightsDataDirectory = new File(args[0]);
    File flightsOutputDirectory = new File(args[1]);
    flightsOutputDirectory.mkdirs();/*  ww  w . java 2  s  .  c  om*/

    for (File flightsDataFile : flightsDataDirectory.listFiles()) {
        System.out.printf("Processing file[%s]%n", flightsDataFile);

        CSVParser parser = new CSVParser();
        BufferedReader in = null;
        BufferedWriter out = null;

        try {
            in = new BufferedReader(new FileReader(flightsDataFile));
            out = new BufferedWriter(new FileWriter(
                    new File(flightsOutputDirectory, flightsDataFile.getName().replace("csv", "json"))));

            int count = 0;
            long time = System.currentTimeMillis();
            parser.setFieldNames(in.readLine());
            String line = null;
            while ((line = in.readLine()) != null) {
                if (++count % 100000 == 0) {
                    System.out.printf("File[%s], processed %,d lines in %,d millis.%n",
                            flightsDataFile.getName(), count, System.currentTimeMillis() - time);
                    time = System.currentTimeMillis();
                }
                Map<String, Object> event = parser.parse(line);

                int year = Integer.parseInt(event.get("Year").toString());
                int month = Integer.parseInt(event.get("Month").toString());
                int dayOfMonth = Integer.parseInt(event.get("DayofMonth").toString());
                int departureTime = Integer.parseInt(event.get("CRSDepTime").toString());
                int hourOfDay = departureTime / 100;
                final int minuteOfHour = departureTime % 100;

                DateTime timestamp = new DateTime(String.format("%4d-%02d-%02d", year, month, dayOfMonth))
                        .plus(new Period(hourOfDay, minuteOfHour, 0, 0));

                event.put("timestamp", timestamp);

                for (String metricDimension : METRIC_DIMENSIONS) {
                    String value = event.get(metricDimension).toString();

                    if (value.equals("NA")) {
                        event.put(metricDimension, 0);
                    } else {
                        event.put(metricDimension, Integer.parseInt(value));
                    }
                }

                out.write(mapper.writeValueAsString(event));
                out.write("\n");
            }
        } finally {
            Closeables.closeQuietly(in);
            Closeables.closeQuietly(out);
        }
    }
}

From source file:graphene.util.stats.TimeReporter.java

License:Apache License

public void logEstimation(long estimatedTotal, long numberProcessed) {
    if (estimatedTotal <= numberProcessed) {
        log.info("Should be Completed");
    } else if (numberProcessed == 0) {
        log.info("inf");
    } else {/* w  w w  .  j  a  v a 2  s  . co m*/
        double rate = getElapsed() / numberProcessed;
        double guess = ((estimatedTotal - numberProcessed) * rate) / 1000;
        int d = guess > 86400 ? (int) guess / 86400 : 0;
        guess %= 86400;
        int h = guess > 3600 ? (int) guess / 3600 : 0;
        guess %= 3600;
        int m = guess > 60 ? (int) guess / 60 : 0;
        guess %= 60;
        int s = (int) (guess > 0 ? guess : 0);
        Period period = new Period(d, h, m, s);

        log.info("Time remaining: " + daysHoursMinutes.print(period.normalizedStandard()));
    }
}

From source file:io.jawg.osmcontributor.ui.adapters.parser.OpeningHoursValueParser.java

License:Open Source License

public boolean isNonStopHours(OpeningHours openingHours) {
    if (openingHours.getFromTime().equals(openingHours.getToTime())) {
        return true;
    }/*from  ww  w  . j ava 2  s .c om*/

    LocalTime diff = openingHours.getToTime().minus(new Period(openingHours.getFromTime().getHourOfDay(),
            openingHours.getFromTime().getMinuteOfHour(), 0, 0));

    return diff.minus(new Period(23, 50, 0, 0)).getMinuteOfHour() < 10;
}

From source file:net.solarnetwork.central.dras.dao.ibatis.test.AbstractIbatisDaoTestSupport.java

License:Open Source License

protected Constraint createConstraint() {
    Constraint constraint = new Constraint();

    List<DateTimeWindow> blackoutDates = new ArrayList<DateTimeWindow>(2);
    blackoutDates.add(//  w ww.  j  a va2s.  co  m
            new DateTimeWindow(new DateTime(2011, 1, 1, 0, 0, 0, 0), new DateTime(2011, 1, 2, 0, 0, 0, 0)));
    blackoutDates.add(
            new DateTimeWindow(new DateTime(2011, 2, 1, 0, 0, 0, 0), new DateTime(2011, 2, 2, 0, 0, 0, 0)));
    constraint.setBlackoutDates(blackoutDates);
    constraint.setBlackoutDatesFilter(FilterKind.RESTRICT);

    constraint.setEventWindowStart(new LocalTime(12, 0));
    constraint.setEventWindowEnd(new LocalTime(14, 0));
    constraint.setEventWindowFilter(FilterKind.ACCEPT);

    constraint.setMaxConsecutiveDays(23);
    constraint.setMaxConsecutiveDaysFilter(FilterKind.REJECT);

    constraint.setMaxEventDuration(new Period(4, 0, 0, 0).toStandardDuration());
    constraint.setMaxEventDurationFilter(FilterKind.ACCEPT);

    constraint.setNotificationWindowMax(new Period(4, 0, 0, 0).toStandardDuration());
    constraint.setNotificationWindowMin(new Period(2, 0, 0, 0).toStandardDuration());
    constraint.setNotificationWindowFilter(FilterKind.RESTRICT);

    List<DateTimeWindow> validDates = new ArrayList<DateTimeWindow>(2);
    validDates.add(
            new DateTimeWindow(new DateTime(2011, 1, 1, 0, 0, 0, 0), new DateTime(2011, 1, 2, 0, 0, 0, 0)));
    validDates.add(
            new DateTimeWindow(new DateTime(2011, 2, 1, 0, 0, 0, 0), new DateTime(2011, 2, 2, 0, 0, 0, 0)));
    constraint.setValidDates(validDates);
    constraint.setValidDatesFilter(FilterKind.FORCE);

    return constraint;
}

From source file:net.solarnetwork.central.dras.dao.ibatis.test.AbstractIbatisDaoTestSupport.java

License:Open Source License

protected Fee createFee() {
    Fee f = new Fee();
    f.setAvailableFee(1L);/*from  w  ww .j  a  v  a2s .  c  o  m*/
    f.setAvailablePeriod(new Period(24, 0, 0, 0));
    f.setCancelFee(2L);
    f.setCurrency("NZD");
    f.setDeliveryFee(4L);
    f.setEstablishFee(5L);
    f.setEventFee(6L);
    return f;
}

From source file:op.tools.SYSCalendar.java

License:Open Source License

/**
 * determines to which timeofday code a given date object belongs. The settings in SYSProps are taken into account.
 * or in short: it answers a question like "is 0800h early, noon or early in the morning ?"
 *
 * @param date//from   ww  w.  java2s .  c o  m
 * @return timecode
 */
public static byte whatTimeIDIs(Date date) {
    byte timeid;

    DateTimeFormatter parser = DateTimeFormat.forPattern("HH:mm");

    DateTime early_in_the_morning = parser
            .parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_EARLY_IN_THE_MORNING));
    DateTime morning = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_MORNING));
    DateTime noon = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_NOON));
    DateTime afternoon = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_AFTERNOON));
    DateTime evening = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_EVENING));
    DateTime late_at_night = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_LATE_AT_NIGHT));

    Period period_early_in_the_morning = new Period(early_in_the_morning.getHourOfDay(),
            early_in_the_morning.getMinuteOfHour(), early_in_the_morning.getSecondOfMinute(),
            early_in_the_morning.getMillisOfSecond());
    Period period_morning = new Period(morning.getHourOfDay(), morning.getMinuteOfHour(),
            morning.getSecondOfMinute(), morning.getMillisOfSecond());
    Period period_noon = new Period(noon.getHourOfDay(), noon.getMinuteOfHour(), noon.getSecondOfMinute(),
            noon.getMillisOfSecond());
    Period period_afternoon = new Period(afternoon.getHourOfDay(), afternoon.getMinuteOfHour(),
            afternoon.getSecondOfMinute(), afternoon.getMillisOfSecond());
    Period period_evening = new Period(evening.getHourOfDay(), evening.getMinuteOfHour(),
            evening.getSecondOfMinute(), evening.getMillisOfSecond());
    Period period_late_at_night = new Period(late_at_night.getHourOfDay(), late_at_night.getMinuteOfHour(),
            late_at_night.getSecondOfMinute(), late_at_night.getMillisOfSecond());

    DateTime ref = new DateTime(date);
    DateTime eitm = new DateMidnight(date).toDateTime().plus(period_early_in_the_morning);
    DateTime m = new DateMidnight(date).toDateTime().plus(period_morning);
    DateTime n = new DateMidnight(date).toDateTime().plus(period_noon);
    DateTime a = new DateMidnight(date).toDateTime().plus(period_afternoon);
    DateTime e = new DateMidnight(date).toDateTime().plus(period_evening);
    DateTime lan = new DateMidnight(date).toDateTime().plus(period_late_at_night);

    if (eitm.compareTo(ref) <= 0 && ref.compareTo(m) < 0) {
        timeid = DFNTools.BYTE_EARLY_IN_THE_MORNING;
    } else if (m.compareTo(ref) <= 0 && ref.compareTo(n) < 0) {
        timeid = DFNTools.BYTE_MORNING;
    } else if (n.compareTo(ref) <= 0 && ref.compareTo(a) < 0) {
        timeid = DFNTools.BYTE_NOON;
    } else if (a.compareTo(ref) <= 0 && ref.compareTo(e) < 0) {
        timeid = DFNTools.BYTE_AFTERNOON;
    } else if (e.compareTo(ref) <= 0 && ref.compareTo(lan) < 0) {
        timeid = DFNTools.BYTE_EVENING;
    } else {
        timeid = DFNTools.BYTE_LATE_AT_NIGHT;
    }
    return timeid;
}

From source file:org.apache.isis.applib.value.Time.java

License:Apache License

/**
 * Add the specified hours and minutes to this time value, returned as a new
 * Time object./*from   ww w .j  a  v  a  2 s .c o  m*/
 */
public Time add(final int hours, final int minutes) {
    final Period period = new Period(hours, minutes, 0, 0);
    return new Time(time.plus(period));
}