Example usage for org.joda.time DateTimeFieldType secondOfMinute

List of usage examples for org.joda.time DateTimeFieldType secondOfMinute

Introduction

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

Prototype

public static DateTimeFieldType secondOfMinute() 

Source Link

Document

Get the second of minute field type.

Usage

From source file:de.avanux.smartapplianceenabler.appliance.TimeOfDay.java

License:Open Source License

public TimeOfDay(LocalDateTime dateTime) {
    hour = dateTime.get(DateTimeFieldType.hourOfDay());
    minute = dateTime.get(DateTimeFieldType.minuteOfHour());
    second = dateTime.get(DateTimeFieldType.secondOfMinute());
}

From source file:de.openali.odysseus.chart.ext.base.axisrenderer.provider.DateTimeAxisFieldProvider.java

License:Open Source License

@Override
public IDateTimeAxisField getDateTimeAxisField(final IDataRange<Number> range) {

    final long dr = range.getMax().longValue() - range.getMin().longValue();
    final long sec = 1000;
    final long min = 60 * sec;
    final long hour = 60 * min;
    final long day = 24 * hour;

    if (dr < 3 * sec)
        return new DateTimeAxisField(DateTimeFieldType.millisOfSecond(), "YYYY.dd.MM\nHH:mm:ss:SSS", //$NON-NLS-1$
                new int[] { 1, 10, 100, 500 }, new int[] {});
    else if (dr < 3 * min)
        return new DateTimeAxisField(DateTimeFieldType.secondOfMinute(), "YY.dd.MM\nHH:mm:ss", //$NON-NLS-1$
                new int[] { 1, 15, 30 }, new int[] {});
    else if (dr < 3 * hour)
        return new DateTimeAxisField(DateTimeFieldType.minuteOfHour(), "YY.dd.MM\nHH:mm:ss", //$NON-NLS-1$
                new int[] { 1, 15, 30 }, new int[] {});
    else if (dr < 3 * day)
        return new DateTimeAxisField(DateTimeFieldType.minuteOfDay(), "dd.MM\nHH:mm", new int[] { 1, 15, 30 }, //$NON-NLS-1$
                new int[] {});
    else if (dr < 7 * day)
        return new DateTimeAxisField(DateTimeFieldType.hourOfDay(), "dd.MM\nHH:mm", //$NON-NLS-1$
                new int[] { 1, 2, 4, 6, 8, 12 }, new int[] { 12 });
    else if (dr < 30 * day)
        return new DateTimeAxisField(DateTimeFieldType.dayOfMonth(), "YYYY.dd.MM\ndddd", //$NON-NLS-1$
                new int[] { 1, 2, 7, 14 }, new int[] { 7, 14, 28 });
    else/* w ww .  j  a  va  2  s  . c  om*/
        return new DateTimeAxisField(DateTimeFieldType.monthOfYear(), "YYYY.dd.MM", new int[] { 1, 2, 3, 4, 6 }, //$NON-NLS-1$
                new int[] { 6 });
}

From source file:net.karlmartens.platform.datatable.DataTableCell.java

License:Apache License

private static JsonElement creasteJsonElement(Object o) {
    if (o == null)
        return JsonNull.INSTANCE;

    if (o instanceof String)
        return new JsonPrimitive((String) o);

    if (o instanceof Boolean)
        return new JsonPrimitive((Boolean) o);

    if (o instanceof Number)
        return new JsonPrimitive((Number) o);

    if (o instanceof BaseLocal) {
        final BaseLocal date = (BaseLocal) o;
        final JsonObject json = new JsonObject();
        json.add("year", createJsonElement(DateTimeFieldType.year(), date));
        json.add("month", createJsonElement(DateTimeFieldType.monthOfYear(), date));
        json.add("day", createJsonElement(DateTimeFieldType.dayOfMonth(), date));
        json.add("hour", createJsonElement(DateTimeFieldType.hourOfDay(), date));
        json.add("minute", createJsonElement(DateTimeFieldType.minuteOfHour(), date));
        json.add("second", createJsonElement(DateTimeFieldType.secondOfMinute(), date));
        json.add("millis", createJsonElement(DateTimeFieldType.millisOfSecond(), date));
        return json;
    }//ww  w  .  jav  a  2s .  co m

    throw new UnsupportedOperationException();
}

From source file:org.apache.tajo.util.TimeStampUtil.java

License:Apache License

public static long getSecond(DateTime dateTime) {
    return convertToMicroSeconds(dateTime.withTime(dateTime.get(DateTimeFieldType.clockhourOfDay()),
            dateTime.get(DateTimeFieldType.minuteOfHour()), dateTime.get(DateTimeFieldType.secondOfMinute()),
            0));/*www  . j a v a2s  .  c  om*/
}

From source file:org.codelibs.elasticsearch.common.joda.Joda.java

License:Apache License

public static FormatDateTimeFormatter getStrictStandardDateFormatter() {
    // 2014/10/10
    DateTimeFormatter shortFormatter = new DateTimeFormatterBuilder()
            .appendFixedDecimal(DateTimeFieldType.year(), 4).appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2).appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2).toFormatter().withZoneUTC();

    // 2014/10/10 12:12:12
    DateTimeFormatter longFormatter = new DateTimeFormatterBuilder()
            .appendFixedDecimal(DateTimeFieldType.year(), 4).appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2).appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2).appendLiteral(' ')
            .appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2).appendLiteral(':')
            .appendFixedSignedDecimal(DateTimeFieldType.minuteOfHour(), 2).appendLiteral(':')
            .appendFixedSignedDecimal(DateTimeFieldType.secondOfMinute(), 2).toFormatter().withZoneUTC();

    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder()
            .append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[] {
                    longFormatter.getParser(), shortFormatter.getParser(), new EpochTimeParser(true) });

    return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis",
            builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT);
}

From source file:org.codelibs.elasticsearch.common.joda.StrictISODateTimeFormat.java

License:Apache License

/**
 * Adds the time fields to the builder.//  w w  w .j av  a 2s .  c om
 * Specification reference: 5.3.1.
 *
 * @param bld  the builder
 * @param fields  the fields
 * @param extended  whether to use the extended format
 * @param strictISO  whether to be strict
 * @param reducedPrec  whether the date was reduced precision
 * @param datePresent  whether there was a date
 * @since 1.1
 */
private static void time(DateTimeFormatterBuilder bld, Collection<DateTimeFieldType> fields, boolean extended,
        boolean strictISO, boolean reducedPrec, boolean datePresent) {

    boolean hour = fields.remove(DateTimeFieldType.hourOfDay());
    boolean minute = fields.remove(DateTimeFieldType.minuteOfHour());
    boolean second = fields.remove(DateTimeFieldType.secondOfMinute());
    boolean milli = fields.remove(DateTimeFieldType.millisOfSecond());
    if (!hour && !minute && !second && !milli) {
        return;
    }
    if (hour || minute || second || milli) {
        if (strictISO && reducedPrec) {
            throw new IllegalArgumentException(
                    "No valid ISO8601 format for fields because Date was reduced precision: " + fields);
        }
        if (datePresent) {
            bld.appendLiteral('T');
        }
    }
    if (hour && minute && second || (hour && !second && !milli)) {
        // OK - HMSm/HMS/HM/H - valid in combination with date
    } else {
        if (strictISO && datePresent) {
            throw new IllegalArgumentException(
                    "No valid ISO8601 format for fields because Time was truncated: " + fields);
        }
        if (!hour && (minute && second || (minute && !milli) || second)) {
            // OK - MSm/MS/M/Sm/S - valid ISO formats
        } else {
            if (strictISO) {
                throw new IllegalArgumentException("No valid ISO8601 format for fields: " + fields);
            }
        }
    }
    if (hour) {
        bld.appendHourOfDay(2);
    } else if (minute || second || milli) {
        bld.appendLiteral('-');
    }
    if (extended && hour && minute) {
        bld.appendLiteral(':');
    }
    if (minute) {
        bld.appendMinuteOfHour(2);
    } else if (second || milli) {
        bld.appendLiteral('-');
    }
    if (extended && minute && second) {
        bld.appendLiteral(':');
    }
    if (second) {
        bld.appendSecondOfMinute(2);
    } else if (milli) {
        bld.appendLiteral('-');
    }
    if (milli) {
        bld.appendLiteral('.');
        bld.appendMillisOfSecond(3);
    }
}

From source file:org.datavec.api.util.jackson.DateTimeFieldTypeDeserializer.java

License:Apache License

private static Map<String, DateTimeFieldType> getMap() {
    Map<String, DateTimeFieldType> ret = new HashMap<>();
    ret.put(DateTimeFieldType.centuryOfEra().getName(), DateTimeFieldType.centuryOfEra());
    ret.put(DateTimeFieldType.clockhourOfDay().getName(), DateTimeFieldType.clockhourOfDay());
    ret.put(DateTimeFieldType.clockhourOfHalfday().getName(), DateTimeFieldType.clockhourOfHalfday());
    ret.put(DateTimeFieldType.dayOfMonth().getName(), DateTimeFieldType.dayOfMonth());
    ret.put(DateTimeFieldType.dayOfWeek().getName(), DateTimeFieldType.dayOfWeek());
    ret.put(DateTimeFieldType.dayOfYear().getName(), DateTimeFieldType.dayOfYear());
    ret.put(DateTimeFieldType.era().getName(), DateTimeFieldType.era());
    ret.put(DateTimeFieldType.halfdayOfDay().getName(), DateTimeFieldType.halfdayOfDay());
    ret.put(DateTimeFieldType.hourOfDay().getName(), DateTimeFieldType.hourOfDay());
    ret.put(DateTimeFieldType.hourOfHalfday().getName(), DateTimeFieldType.hourOfHalfday());
    ret.put(DateTimeFieldType.millisOfDay().getName(), DateTimeFieldType.millisOfDay());
    ret.put(DateTimeFieldType.millisOfSecond().getName(), DateTimeFieldType.millisOfSecond());
    ret.put(DateTimeFieldType.minuteOfDay().getName(), DateTimeFieldType.minuteOfDay());
    ret.put(DateTimeFieldType.minuteOfHour().getName(), DateTimeFieldType.minuteOfHour());
    ret.put(DateTimeFieldType.secondOfDay().getName(), DateTimeFieldType.secondOfDay());
    ret.put(DateTimeFieldType.secondOfMinute().getName(), DateTimeFieldType.secondOfMinute());
    ret.put(DateTimeFieldType.weekOfWeekyear().getName(), DateTimeFieldType.weekOfWeekyear());
    ret.put(DateTimeFieldType.weekyear().getName(), DateTimeFieldType.weekyear());
    ret.put(DateTimeFieldType.weekyearOfCentury().getName(), DateTimeFieldType.weekyearOfCentury());
    ret.put(DateTimeFieldType.year().getName(), DateTimeFieldType.year());
    ret.put(DateTimeFieldType.yearOfCentury().getName(), DateTimeFieldType.yearOfCentury());
    ret.put(DateTimeFieldType.yearOfEra().getName(), DateTimeFieldType.yearOfEra());

    return ret;//from   w ww.  jav a  2 s. c  o  m
}

From source file:org.filteredpush.qc.date.DateUtils.java

License:Apache License

/**
 * Given an instant, return the time within one day that it represents as a string.
 * /*from  w w w  .j  a va 2s  . c  o m*/
 * @param instant to obtain time from.
 * @return string in the form hh:mm:ss.sssZ or an empty string if instant is null.  
 */
protected static String instantToStringTime(Instant instant) {
    String result = "";
    if (instant != null) {
        StringBuffer time = new StringBuffer();
        time.append(String.format("%02d", instant.get(DateTimeFieldType.hourOfDay())));
        time.append(":").append(String.format("%02d", instant.get(DateTimeFieldType.minuteOfHour())));
        time.append(":").append(String.format("%02d", instant.get(DateTimeFieldType.secondOfMinute())));
        time.append(".").append(String.format("%03d", instant.get(DateTimeFieldType.millisOfSecond())));
        String timeZone = instant.getZone().getID();
        if (timeZone.equals("UTC")) {
            time.append("Z");
        } else {
            time.append(timeZone);
        }
        result = time.toString();
    }
    return result;
}

From source file:org.gephi.desktop.timeline.DateTick.java

License:Open Source License

public static DateTick create(double min, double max, int width) {

    DateTime minDate = new DateTime((long) min);
    DateTime maxDate = new DateTime((long) max);

    Period period = new Period(minDate, maxDate, PeriodType.yearMonthDayTime());
    ;/*w  w w  . j a  v a  2 s.  com*/
    int years = period.getYears();
    int months = period.getMonths();
    int days = period.getDays();
    int hours = period.getHours();
    int minutes = period.getMinutes();
    int seconds = period.getSeconds();

    //Top type
    DateTimeFieldType topType;
    if (years > 0) {
        topType = DateTimeFieldType.year();
    } else if (months > 0) {
        topType = DateTimeFieldType.monthOfYear();
    } else if (days > 0) {
        topType = DateTimeFieldType.dayOfMonth();
    } else if (hours > 0) {
        topType = DateTimeFieldType.hourOfDay();
    } else if (minutes > 0) {
        topType = DateTimeFieldType.minuteOfHour();
    } else if (seconds > 0) {
        topType = DateTimeFieldType.secondOfMinute();
    } else {
        topType = DateTimeFieldType.millisOfSecond();
    }

    //Bottom type
    if (topType != DateTimeFieldType.millisOfSecond()) {
        DateTimeFieldType bottomType;
        if (topType.equals(DateTimeFieldType.year())) {
            bottomType = DateTimeFieldType.monthOfYear();
        } else if (topType.equals(DateTimeFieldType.monthOfYear())) {
            bottomType = DateTimeFieldType.dayOfMonth();
        } else if (topType.equals(DateTimeFieldType.dayOfMonth())) {
            bottomType = DateTimeFieldType.hourOfDay();
        } else if (topType.equals(DateTimeFieldType.hourOfDay())) {
            bottomType = DateTimeFieldType.minuteOfHour();
        } else if (topType.equals(DateTimeFieldType.minuteOfHour())) {
            bottomType = DateTimeFieldType.secondOfMinute();
        } else {
            bottomType = DateTimeFieldType.millisOfSecond();
        }

        //Number of ticks
        Period p = new Period(minDate, maxDate,
                PeriodType.forFields(new DurationFieldType[] { bottomType.getDurationType() }));
        int intervals = p.get(bottomType.getDurationType());
        if (intervals > 0) {
            int intervalSize = width / intervals;
            if (intervalSize >= MIN_PIXELS) {
                return new DateTick(minDate, maxDate, new DateTimeFieldType[] { topType, bottomType });
            }
        }
    }

    return new DateTick(minDate, maxDate, new DateTimeFieldType[] { topType });
}

From source file:org.jpmml.evaluator.SecondsSinceMidnight.java

License:Open Source License

static private DateTimeFormatter createFormat() {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    builder = builder.appendSignedDecimal(HoursOfEpochFieldType.getInstance(), 1, 4).appendLiteral(':')
            .appendFixedDecimal(DateTimeFieldType.minuteOfHour(), 2).appendLiteral(':')
            .appendFixedDecimal(DateTimeFieldType.secondOfMinute(), 2);

    return builder.toFormatter();
}