Example usage for org.joda.time LocalDateTime getValues

List of usage examples for org.joda.time LocalDateTime getValues

Introduction

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

Prototype

public int[] getValues() 

Source Link

Document

Gets an array of the value of each of the fields that this partial supports.

Usage

From source file:de.jpaw.bonaparte.core.AppendableComposer.java

License:Apache License

@Override
public void addField(TemporalElementaryDataItem di, LocalDateTime t) throws IOException {
    if (t != null) {
        int[] values = t.getValues(); // 4 values: year, month, day, millis of day
        //int tmpValue = 10000 * t.getYear() + 100 * t.getMonthOfYear() + t.getDayOfMonth();
        work.append(Integer.toString((10000 * values[0]) + (100 * values[1]) + values[2]));
        int length = di.getFractionalSeconds();
        if (length >= 0) {
            // not only day, but also time
            //tmpValue = 10000 * t.getHourOfDay() + 100 * t.getMinuteOfHour() + t.getSecondOfMinute();
            if (length > 0 ? (values[3] != 0) : ((values[3] / 1000) != 0)) {
                work.append('.');
                if (di.getHhmmss()) {
                    int tmpValue = values[3] / 60000; // minutes and hours
                    tmpValue = (100 * (tmpValue / 60)) + (tmpValue % 60);
                    lpad(Integer.toString((tmpValue * 100) + ((values[3] % 60000) / 1000)), 6, '0');
                } else {
                    lpad(Integer.toString(values[3] / 1000), 6, '0');
                }//  w w  w . jav a  2 s.c om
                if (length > 0) {
                    // add milliseconds
                    int milliSeconds = values[3] % 1000;
                    if (milliSeconds != 0) {
                        lpad(Integer.toString(milliSeconds), 3, '0');
                    }
                }
            }
        }
        terminateField();
    } else {
        writeNull();
    }
}

From source file:de.jpaw.bonaparte.core.ByteArrayComposer.java

License:Apache License

@Override
public void addField(TemporalElementaryDataItem di, LocalDateTime t) {
    if (t != null) {
        int[] values = t.getValues(); // 4 values: year, month, day, millis of day
        //int tmpValue = 10000 * t.getYear() + 100 * t.getMonthOfYear() + t.getDayOfMonth();
        work.appendAscii(Integer.toString((10000 * values[0]) + (100 * values[1]) + values[2]));
        int length = di.getFractionalSeconds();
        if (length >= 0) {
            // not only day, but also time
            //tmpValue = 10000 * t.getHourOfDay() + 100 * t.getMinuteOfHour() + t.getSecondOfMinute();
            if (length > 0 ? (values[3] != 0) : ((values[3] / 1000) != 0)) {
                work.append((byte) '.');
                if (di.getHhmmss()) {
                    int tmpValue = values[3] / 60000; // minutes and hours
                    tmpValue = (100 * (tmpValue / 60)) + (tmpValue % 60);
                    lpad(Integer.toString((tmpValue * 100) + ((values[3] % 60000) / 1000)), 6, (byte) '0');
                } else {
                    lpad(Integer.toString(values[3] / 1000), 6, (byte) '0');
                }/*from w ww  . ja v  a2s  .  c o m*/
                if (length > 0) {
                    // add milliseconds
                    int milliSeconds = values[3] % 1000;
                    if (milliSeconds != 0) {
                        lpad(Integer.toString(milliSeconds), 3, (byte) '0');
                    }
                }
            }
        }
        terminateField();
    } else {
        writeNull();
    }
}

From source file:de.jpaw.bonaparte.core.ExternalizableComposer.java

License:Apache License

@Override
public void addField(TemporalElementaryDataItem di, LocalDateTime t) throws IOException {
    if (t == null) {
        out.writeByte(NULL_FIELD);// w  w  w. j a va2s .  co  m
    } else {
        int[] values = t.getValues(); // 4 values: year, month, day, milliseconds
        if (values[3] != 0) {
            // fractional part first...
            out.writeByte(FRAC_SCALE_0 + 9);
            if (di.getHhmmss()) {
                // convert milliseconds to hhmmssfff format
                int tmp = values[3] / 60000; // number of minutes
                tmp = ((tmp / 60) * 100) + (tmp % 60);
                writeVarInt((tmp * 100000) + (values[3] % 60000));
            } else {
                writeVarInt(values[3]);
            }
        }
        // then integral part
        writeVarInt((10000 * values[0]) + (100 * values[1]) + values[2]);
    }
}