Example usage for org.joda.time DateTime get

List of usage examples for org.joda.time DateTime get

Introduction

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

Prototype

public int get(DateTimeFieldType type) 

Source Link

Document

Get the value of one of the fields of a datetime.

Usage

From source file:com.google.code.tickconverter.convert.ConvertAdapter.java

License:Open Source License

/**
 * This method is the main method of the convert process. While the {@link BlockingQueue} of {@link IDukascopyRO}
 * have for 10 seconds no objects in the {@link BlockingQueue} add this method this object into the
 * {@link MetatraderConverter}. If an {@link InvalidTimeException} will threw the converter put a new
 * {@link MetatraderBean} into the {@link BlockingQueue} of {@link IMetatraderRO} and get the information of the
 * values from the {@link MetatraderConverter} object.
 * //from   w w  w  .ja  v  a2  s  . co  m
 * @throws InterruptedException will threw if {@link Thread#interrupt()} is called in the poll phase
 * @throws InvalidTimeException will threw if {@link MetatraderConverter#incrementInterval()} have a low range for
 *             the new object after the creation of a new {@link MetatraderBean}
 */
public void convertProcess() throws InterruptedException {
    while (true) {
        IDukascopyRO object = dukaQueue.poll(2, TimeUnit.SECONDS);
        LoggerUtils.createDebugLog("poll object: " + object);
        if (null == object) {
            if (null != converter && converter.hasElements()) {
                putMetatraderObject();
            }

            break;
        }

        if (null == converter) {
            DateTime timestamp = object.getTimeStamp();
            DateTime start = new DateTime(timestamp.get(DateTimeFieldType.year()),
                    timestamp.get(DateTimeFieldType.monthOfYear()),
                    timestamp.get(DateTimeFieldType.dayOfMonth()), timestamp.get(DateTimeFieldType.hourOfDay()),
                    timestamp.get(DateTimeFieldType.minuteOfHour()));
            converter = new MetatraderConverter(start, Period.minutes(1));
        }
        try {
            converter.addDukascopy(object);
        } catch (InvalidTimeException e) {
            putMetatraderObject();
            incrementWhileAdd(object);
        }
    }
}

From source file:com.graphaware.module.timetree.SingleTimeTree.java

License:Open Source License

private Node getInstant(Node parent, DateTime dateTime, Resolution targetResolution,
        ChildNotFoundPolicy childNotFoundPolicy) {
    Resolution currentResolution = currentResolution(parent);

    if (targetResolution.equals(currentResolution)) {
        return parent;
    }//from   w  w  w.ja v a  2s.co m

    Resolution newCurrentResolution = childResolution(parent);

    Node child = findChild(parent, dateTime.get(newCurrentResolution.getDateTimeFieldType()), RETURN_NULL);

    if (child == null) {
        switch (childNotFoundPolicy) {
        case RETURN_NULL:
            return null;
        case RETURN_NEXT:
            return getInstantViaClosestChild(parent, dateTime, targetResolution, childNotFoundPolicy,
                    newCurrentResolution, FIRST);
        case RETURN_PREVIOUS:
            return getInstantViaClosestChild(parent, dateTime, targetResolution, childNotFoundPolicy,
                    newCurrentResolution, LAST);
        }
    }

    //recursion
    return getInstant(child, dateTime, targetResolution, childNotFoundPolicy);
}

From source file:com.graphaware.module.timetree.SingleTimeTree.java

License:Open Source License

private Node getInstantViaClosestChild(Node parent, DateTime dateTime, Resolution targetResolution,
        ChildNotFoundPolicy childNotFoundPolicy, Resolution newCurrentResolution,
        RelationshipType relationshipType) {
    Node closestChild = findChild(parent, dateTime.get(newCurrentResolution.getDateTimeFieldType()),
            childNotFoundPolicy);/*from  w ww  . j a v  a  2 s. c  o  m*/
    if (closestChild == null) {
        return null;
    }
    return findChild(closestChild, relationshipType, targetResolution);
}

From source file:com.graphaware.module.timetree.SingleTimeTree.java

License:Open Source License

/**
 * Get a node representing a specific time instant. If one doesn't exist, it will be created as well as any missing
 * nodes on the way down from parent (recursively).
 *
 * @param parent           parent node on path to desired instant node.
 * @param dateTime         time instant.
 * @param targetResolution target child resolution. Recursion stops when at this level.
 * @return node representing the time instant at the desired resolution level.
 *///from   ww  w  .j  a v a  2 s  . co  m
private Node getOrCreateInstant(Node parent, DateTime dateTime, Resolution targetResolution) {
    Resolution currentResolution = currentResolution(parent);

    if (targetResolution.equals(currentResolution)) {
        return parent;
    }

    Resolution newCurrentResolution = childResolution(parent);

    Node child = findOrCreateChild(parent, dateTime.get(newCurrentResolution.getDateTimeFieldType()));

    //recursion
    return getOrCreateInstant(child, dateTime, targetResolution);
}

From source file:com.linagora.obm.ui.page.CreateCalendarPage.java

License:Open Source License

private void selectDay(UIEvent eventToCreate) {
    DateTime dateTime = new DateTime(eventToCreate.getDateBegin());
    switch (dateTime.get(DateTimeFieldType.dayOfWeek())) {
    case 1://from  ww w.jav  a2 s . c om
        cba_repeatday_1.click();
        break;
    case 2:
        cba_repeatday_2.click();
        break;
    case 3:
        cba_repeatday_3.click();
        break;
    case 4:
        cba_repeatday_4.click();
        break;
    case 5:
        cba_repeatday_5.click();
        break;
    case 6:
        cba_repeatday_6.click();
        break;
    case 7:
        cba_repeatday_7.click();
        break;
    }
}

From source file:com.splicemachine.derby.utils.SpliceDateFunctions.java

License:Apache License

/**
 * Implements the trunc_date function/*from  ww w .  ja  va 2 s. c om*/
 */
public static Timestamp TRUNC_DATE(Timestamp source, String field) throws SQLException {
    if (source == null || field == null)
        return null;
    DateTime dt = new DateTime(source);
    field = field.toLowerCase();
    String lowerCaseField = field.toLowerCase();
    if ("microseconds".equals(lowerCaseField)) {
        int nanos = source.getNanos();
        nanos = nanos - nanos % 1000;
        source.setNanos(nanos);
        return source;
    } else if ("milliseconds".equals(lowerCaseField)) {
        int nanos = source.getNanos();
        nanos = nanos - nanos % 1000000;
        source.setNanos(nanos);
        return source;
    } else if ("second".equals(lowerCaseField)) {
        source.setNanos(0);
        return source;

    } else if ("minute".equals(lowerCaseField)) {
        DateTime modified = dt.minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("hour".equals(lowerCaseField)) {
        DateTime modified = dt.minusMinutes(dt.getMinuteOfHour()).minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("day".equals(lowerCaseField)) {
        DateTime modified = dt.minusHours(dt.getHourOfDay()).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("week".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.getDayOfWeek()).minusHours(dt.getHourOfDay())
                .minusMinutes(dt.getMinuteOfHour()).minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("month".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusHours(dt.getHourOfDay()).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("quarter".equals(lowerCaseField)) {
        int month = dt.getMonthOfYear();
        DateTime modified = dt;
        if ((month + 1) % 3 == 1) {
            modified = dt.minusMonths(2);
        } else if ((month + 1) % 3 == 0) {
            modified = dt.minusMonths(1);
        }
        DateTime fin = modified.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusHours(dt.getHourOfDay()).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(fin.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("year".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusHours(dt.getHourOfDay()).minusMonths(dt.getMonthOfYear() - 1)
                .minusMinutes(dt.getMinuteOfHour()).minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("decade".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusYears(dt.getYear() % 10).minusHours(dt.getHourOfDay())
                .minusMonths(dt.getMonthOfYear() - 1).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("century".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusHours(dt.getHourOfDay()).minusYears(dt.getYear() % 100)
                .minusMonths(dt.getMonthOfYear() - 1).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("millennium".equals(lowerCaseField)) {
        int newYear = dt.getYear() - dt.getYear() % 1000;
        //noinspection deprecation (converstion from joda to java.sql.Timestamp did not work for millennium < 2000)
        return new Timestamp(newYear - 1900, Calendar.JANUARY, 1, 0, 0, 0, 0);
    } else {
        throw new SQLException(String.format("invalid time unit '%s'", field));
    }
}

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

License:Apache License

/**
 * Takes a strftime()-compatible format string and outputs the properly formatted date.
 */// w w  w  .java 2 s.  co  m
public static void formatDate(Locale locale, String fmt, long instant, String tzName, StringBuilder buf) {
    DateTimeZone zone = null;
    try {
        zone = DateTimeZone.forID(tzName);
    } catch (IllegalArgumentException e) {
        zone = DateTimeZone.getDefault();
    }
    DateTime date = new DateTime(instant, zone);
    int index = 0;
    int len = fmt.length();
    while (index < len) {
        char c1 = fmt.charAt(index);
        index++;
        if (c1 != '%' || index == len) {
            buf.append(c1);
            continue;
        }
        char c2 = fmt.charAt(index);
        switch (c2) {
        case 'A':
            buf.append(date.dayOfWeek().getAsText(locale));
            break;
        case 'a':
            buf.append(date.dayOfWeek().getAsShortText(locale));
            break;
        case 'B':
            buf.append(date.monthOfYear().getAsText(locale));
            break;
        case 'b':
            buf.append(date.monthOfYear().getAsShortText(locale));
            break;
        case 'C':
            leftPad(date.centuryOfEra().get(), '0', 2, buf);
            break;
        case 'c':
            formatAggregate(DateTimeAggregate.FULL, locale, date, buf);
            break;
        case 'D':
            formatAggregate(DateTimeAggregate.MMDDYY, locale, date, buf);
            break;
        case 'd':
            leftPad(date.dayOfMonth().get(), '0', 2, buf);
            break;
        case 'e':
            leftPad(date.dayOfMonth().get(), ' ', 2, buf);
            break;
        case 'F':
            formatAggregate(DateTimeAggregate.YYYYMMDD, locale, date, buf);
            break;
        case 'G':
            buf.append(date.year().get());
            break;
        case 'g':
            leftPad(date.yearOfCentury().get(), '0', 2, buf);
            break;
        case 'H':
            leftPad(date.hourOfDay().get(), '0', 2, buf);
            break;
        case 'h':
            buf.append(date.monthOfYear().getAsShortText(locale));
            break;
        case 'I':
            leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), '0', 2, buf);
            break;
        case 'j':
            leftPad(date.dayOfYear().get(), '0', 3, buf);
            break;
        case 'k':
            leftPad(date.get(DateTimeFieldType.clockhourOfDay()), ' ', 2, buf);
            break;
        case 'l':
            leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), ' ', 2, buf);
            break;
        case 'M':
            leftPad(date.minuteOfHour().get(), '0', 2, buf);
            break;
        case 'm':
            leftPad(date.monthOfYear().get(), '0', 2, buf);
            break;
        case 'n':
            buf.append('\n');
            break;
        case 'P':
            buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "am" : "pm");
            break;
        case 'p':
            buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "AM" : "PM");
            break;
        case 'R':
            formatAggregate(DateTimeAggregate.H240_M0, locale, date, buf);
            break;
        case 'S':
            leftPad(date.secondOfMinute().get(), '0', 2, buf);
            break;
        case 's':
            buf.append(instant / 1000);
            break;
        case 't':
            buf.append('\t');
            break;
        case 'T':
            // Equivalent of %H:%M:%S
            formatAggregate(DateTimeAggregate.H240_M0, locale, date, buf);
            buf.append(':');
            leftPad(date.secondOfMinute().get(), '0', 2, buf);
            break;

        case 'U':
            // TODO: fix week-of-year number
            leftPad(date.weekOfWeekyear().get(), '0', 2, buf);
            break;

        case 'u':
            buf.append(date.dayOfWeek().get());
            break;

        case 'V':
            // TODO: fix week-of-year number
            leftPad(date.weekOfWeekyear().get(), '0', 2, buf);
            break;

        case 'v':
            // Equivalent of %e-%b-%Y
            leftPad(date.dayOfMonth().get(), ' ', 2, buf);
            buf.append('-');
            buf.append(date.monthOfYear().getAsShortText());
            buf.append('-');
            buf.append(date.getYear());
            break;

        case 'W':
            // TODO: fix week-of-year number
            break;

        case 'w':
            buf.append(date.dayOfWeek().get());
            break;
        case 'X':
            formatAggregate(DateTimeAggregate.HHMMSSP, locale, date, buf);
            break;
        case 'x':
            formatAggregate(DateTimeAggregate.MMDDYYYY, locale, date, buf);
            break;
        case 'Y':
            buf.append(date.getYear());
            break;
        case 'y':
            leftPad(date.getYearOfCentury(), '0', 2, buf);
            break;

        case 'Z':
            // Note: Joda's nameKey happens to be the same as the shortName. Making
            // this change to workaround Joda https://github.com/JodaOrg/joda-time/issues/288
            buf.append(zone.getNameKey(date.getMillis()));
            break;

        case 'z':
            int offset = date.getZone().getOffset(instant) / 60000;
            int hours = (int) Math.floor(offset / 60);
            int minutes = (hours * 60) - offset;
            if (offset < 0) {
                buf.append('-');
            }
            leftPad(Math.abs(hours), '0', 2, buf);
            leftPad(Math.abs(minutes), '0', 2, buf);
            break;

        default:
            // no match, emit literals.
            buf.append(c1).append(c2);
        }
        index++;
    }
}

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

License:Apache License

private static void formatAggregate(DateTimeAggregate type, Locale locale, DateTime date, StringBuilder buf) {
    switch (type) {
    case FULL://from w  ww .  j  av a2 s  . c  om
        buf.append(date.dayOfWeek().getAsShortText(locale));
        buf.append(' ');
        leftPad(date.dayOfMonth().get(), '0', 2, buf);
        buf.append(' ');
        buf.append(date.monthOfYear().getAsShortText(locale));
        buf.append(' ');
        buf.append(date.year().get());
        buf.append(' ');
        leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), '0', 2, buf);
        buf.append(':');
        leftPad(date.minuteOfHour().get(), '0', 2, buf);
        buf.append(':');
        leftPad(date.secondOfMinute().get(), '0', 2, buf);
        buf.append(' ');
        buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "AM" : "PM");
        buf.append(' ');
        buf.append(date.getZone().getNameKey(date.getMillis()));
        break;

    case H240_M0:
        leftPad(date.get(DateTimeFieldType.clockhourOfDay()), '0', 2, buf);
        buf.append(':');
        leftPad(date.minuteOfHour().get(), '0', 2, buf);
        break;

    case HHMMSSP:
        leftPad(date.get(DateTimeFieldType.hourOfHalfday()), '0', 2, buf);
        buf.append(':');
        leftPad(date.getMinuteOfHour(), '0', 2, buf);
        buf.append(':');
        leftPad(date.getSecondOfMinute(), '0', 2, buf);
        buf.append(' ');
        buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "AM" : "PM");
        break;

    case MMDDYY:
        leftPad(date.getMonthOfYear(), '0', 2, buf);
        buf.append('/');
        leftPad(date.dayOfMonth().get(), '0', 2, buf);
        buf.append('/');
        leftPad(date.yearOfCentury().get(), '0', 2, buf);
        break;

    case MMDDYYYY:
        leftPad(date.getMonthOfYear(), '0', 2, buf);
        buf.append('/');
        leftPad(date.dayOfMonth().get(), '0', 2, buf);
        buf.append('/');
        buf.append(date.getYear());
        break;

    case YYYYMMDD:
        buf.append(date.year().get());
        buf.append('-');
        leftPad(date.monthOfYear().get(), '0', 2, buf);
        buf.append('-');
        leftPad(date.dayOfMonth().get(), '0', 2, buf);
        break;

    default:
        break;
    }
}

From source file:com.tripadvisor.seekbar.ClockView.java

License:Apache License

public void setBounds(DateTime minTime, DateTime maxTime, boolean isMaxClock) {
    // NOTE: To show correct end time on clock, since the Interval.contains() checks for
    // millisInstant >= thisStart && millisInstant < thisEnd
    // however we want
    // millisInstant >= thisStart && millisInstant <= thisEnd
    maxTime = maxTime.plusMillis(1);/*from  w  ww .j ava  2  s.  c  om*/
    mValidTimeInterval = new Interval(minTime, maxTime);
    maxTime = maxTime.minusMillis(1);
    mCircularClockSeekBar.reset();
    if (isMaxClock) {
        mOriginalTime = maxTime;
        mCurrentValidTime = maxTime;
        int hourOfDay = maxTime.get(DateTimeFieldType.clockhourOfDay()) % 12;
        mCircularClockSeekBar.setProgress(hourOfDay * 10);
        setClockText(mOriginalTime);
    } else {
        mOriginalTime = minTime;
        mCurrentValidTime = minTime;
        int hourOfDay = minTime.get(DateTimeFieldType.clockhourOfDay()) % 12;
        mCircularClockSeekBar.setProgress(hourOfDay * 10);
        setClockText(mOriginalTime);
    }
}

From source file:com.veeduria.dosfases.jsf.InconsPrespJSFBean.java

private void cargarPlanCGXInc() {
    lstTablaPlanCG.clear();/*  w w w .j  ava2s  .  c o m*/
    PreCmgastoinicial pc = tablaLogInconsSel.getAl().getGerId().getGinId();
    SysRegistrocarga src = tablaLogInconsSel.getAl().getGerId().getGinId().getLgregId();
    DateTime dtPeriodo = new DateTime(src.getLgregPeriodo());
    cdfsfb.getLstPCGXCuentaXVig(pc.getGinCodcuenta(), dtPeriodo.get(DateTimeFieldType.year())).stream()
            .map((e -> {
                return new TablaPlanCG(e);
            })).forEach(lstTablaPlanCG::add);

}