类org.joda.time.MutableDateTime源码实例Demo

下面列出了怎么用org.joda.time.MutableDateTime的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: astor   文件: ZoneInfoCompiler.java
static int parseTime(String str) {
    DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction();
    MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology());
    int pos = 0;
    if (str.startsWith("-")) {
        pos = 1;
    }
    int newPos = p.parseInto(mdt, str, pos);
    if (newPos == ~pos) {
        throw new IllegalArgumentException(str);
    }
    int millis = (int)mdt.getMillis();
    if (pos == 1) {
        millis = -millis;
    }
    return millis;
}
 
源代码2 项目: sql-layer   文件: MYearWeek.java
private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);
    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int dayOfYear = cal.getDayOfYear();

    if (dayOfYear < firstD) return modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31);
    else return yr * 100 + (dayOfYear - firstD) / 7 +1;
}
 
@Override
public Object convertToAvro(XMLGregorianCalendar xts) {
    if (xts == null) {
        return null;
    }

    MutableDateTime dateTime = new MutableDateTime();
    try {
        dateTime.setYear(xts.getYear());
        dateTime.setMonthOfYear(xts.getMonth());
        dateTime.setDayOfMonth(xts.getDay());
        dateTime.setHourOfDay(xts.getHour());
        dateTime.setMinuteOfHour(xts.getMinute());
        dateTime.setSecondOfMinute(xts.getSecond());
        dateTime.setMillisOfSecond(xts.getMillisecond());

        DateTimeZone tz = DateTimeZone.forOffsetMillis(xts.getTimezone() * 60000);
        if (tz != null) {
            dateTime.setZoneRetainFields(tz);
        }

        return Long.valueOf(dateTime.getMillis());
    } catch (IllegalArgumentException e) {
        throw new ComponentException(e);
    }
}
 
源代码4 项目: coming   文件: Time_11_ZoneInfoCompiler_s.java
static int parseTime(String str) {
    DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction();
    MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology());
    int pos = 0;
    if (str.startsWith("-")) {
        pos = 1;
    }
    int newPos = p.parseInto(mdt, str, pos);
    if (newPos == ~pos) {
        throw new IllegalArgumentException(str);
    }
    int millis = (int)mdt.getMillis();
    if (pos == 1) {
        millis = -millis;
    }
    return millis;
}
 
源代码5 项目: sql-layer   文件: MDateAddSub.java
@Override
protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output)
{
    ValueSource arg0 = inputs.get(pos0);
    long ymd[] = firstArg.decode(arg0, context);
    if (ymd == null)
    {
        output.putNull();
        context.warnClient(new InvalidDateFormatException("DATE", arg0.toString()));
    }
    else
    {
        MutableDateTime dt = MDateAndTime.toJodaDateTime(ymd, "UTC");    // calculations should be done
        helper.compute(dt, secondArg.toMillis(inputs.get(pos1)));      // in UTC (to avoid daylight-saving side effects)
        firstArg.adjustFirstArg(inputs.get(pos1).getType()).putResult(output, dt, context);
    }
}
 
源代码6 项目: sql-layer   文件: MWeek.java
@Override
protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output)
{
    int date = inputs.get(0).getInt32();
    long ymd[] = MDateAndTime.decodeDate(date);
    int mode = getMode(context, inputs);
    if (!MDateAndTime.isValidDateTime(ymd, ZeroFlag.YEAR) || mode < 0)
    {
        context.warnClient(new InvalidDateFormatException("date", Integer.toString(date)));
        output.putNull();
    }
    else
    {
        output.putInt32(modes[(int) mode].getWeek(new MutableDateTime(DateTimeZone.forID(context.getCurrentTimezone())),
                                              (int)ymd[0], (int)ymd[1], (int)ymd[2]));
    }
}
 
源代码7 项目: crate   文件: XContentElasticsearchExtension.java
@Override
public Map<Class<?>, Function<Object, Object>> getDateTransformers() {
    Map<Class<?>, Function<Object, Object>> transformers = new HashMap<>();
    transformers.put(Date.class, d -> DEFAULT_DATE_PRINTER.print(((Date) d).getTime()));
    transformers.put(DateTime.class, d -> DEFAULT_DATE_PRINTER.print((DateTime) d));
    transformers.put(MutableDateTime.class, d -> DEFAULT_DATE_PRINTER.print((MutableDateTime) d));
    transformers.put(ReadableInstant.class, d -> DEFAULT_DATE_PRINTER.print((ReadableInstant) d));
    transformers.put(Long.class, d -> DEFAULT_DATE_PRINTER.print((long) d));
    transformers.put(Calendar.class, d -> DEFAULT_DATE_PRINTER.print(((Calendar) d).getTimeInMillis()));
    transformers.put(GregorianCalendar.class, d -> DEFAULT_DATE_PRINTER.print(((Calendar) d).getTimeInMillis()));
    transformers.put(Instant.class, d -> DEFAULT_DATE_PRINTER.print((Instant) d));
    transformers.put(ZonedDateTime.class, d -> DEFAULT_FORMATTER.format((ZonedDateTime) d));
    transformers.put(OffsetDateTime.class, d -> DEFAULT_FORMATTER.format((OffsetDateTime) d));
    transformers.put(OffsetTime.class, d -> OFFSET_TIME_FORMATTER.format((OffsetTime) d));
    transformers.put(LocalDateTime.class, d -> DEFAULT_FORMATTER.format((LocalDateTime) d));
    transformers.put(java.time.Instant.class,
        d -> DEFAULT_FORMATTER.format(ZonedDateTime.ofInstant((java.time.Instant) d, ZoneOffset.UTC)));
    transformers.put(LocalDate.class, d -> ((LocalDate) d).toString());
    transformers.put(LocalTime.class, d -> LOCAL_TIME_FORMATTER.format((LocalTime) d));
    return transformers;
}
 
源代码8 项目: astor   文件: TestReadableInstantConverter.java
public void testGetChronology_Object_Zone() throws Exception {
    assertEquals(ISO_PARIS, ReadableInstantConverter.INSTANCE.getChronology(new Instant(123L), PARIS));
    assertEquals(ISO_PARIS, ReadableInstantConverter.INSTANCE.getChronology(new DateTime(123L), PARIS));
    assertEquals(ISO, ReadableInstantConverter.INSTANCE.getChronology(new Instant(123L), DateTimeZone.getDefault()));
    assertEquals(ISO, ReadableInstantConverter.INSTANCE.getChronology(new DateTime(123L), DateTimeZone.getDefault()));
    assertEquals(ISO, ReadableInstantConverter.INSTANCE.getChronology(new Instant(123L), (DateTimeZone) null));
    assertEquals(ISO, ReadableInstantConverter.INSTANCE.getChronology(new DateTime(123L), (DateTimeZone) null));
    
    assertEquals(ISO_PARIS, ReadableInstantConverter.INSTANCE.getChronology(new DateTime(123L, new MockBadChronology()), PARIS));
    
    MutableDateTime mdt = new MutableDateTime() {
        public Chronology getChronology() {
            return null; // bad
        }
    };
    assertEquals(ISO_PARIS, ReadableInstantConverter.INSTANCE.getChronology(mdt, PARIS));
}
 
源代码9 项目: philadelphia   文件: FIXValue.java
/**
 * Get the value as a timestamp.
 *
 * @param x a timestamp
 * @throws FIXValueFormatException if the value is not a timestamp
 */
public void asTimestamp(MutableDateTime x) {
    if (length != 17 && length != 21)
        notTimestamp();

    int year           = getDigits(4, offset + 0);
    int monthOfYear    = getDigits(2, offset + 4);
    int dayOfMonth     = getDigits(2, offset + 6);
    int hourOfDay      = getDigits(2, offset + 9);
    int minuteOfHour   = getDigits(2, offset + 12);
    int secondOfMinute = getDigits(2, offset + 15);
    int millisOfSecond = length == 21 ? getDigits(3, offset + 18) : 0;

    x.setDateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour,
            secondOfMinute, millisOfSecond);
}
 
源代码10 项目: philadelphia   文件: FIXMessageTest.java
@Test
public void format() {
    MutableDateTime timestamp = new MutableDateTime(2015, 9, 24, 9, 30, 5, 250);

    message.addField(ClOrdID).setString("123");
    message.addField(HandlInst).setChar(HandlInstValues.AutomatedExecutionNoIntervention);
    message.addField(Symbol).setString("FOO");
    message.addField(Side).setChar(SideValues.Buy);
    message.addField(TransactTime).setTimestamp(timestamp, true);
    message.addField(OrderQty).setInt(100);
    message.addField(OrdType).setChar(OrdTypeValues.Limit);
    message.addField(Price).setFloat(150.25, 2);

    ByteBuffer buffer = ByteBuffer.allocateDirect(256);

    message.put(buffer);
    buffer.flip();

    assertEquals("11=123\u000121=1\u000155=FOO\u000154=1\u0001" +
            "60=20150924-09:30:05.250\u000138=100\u000140=2\u0001" +
            "44=150.25\u0001", ByteBuffers.getString(buffer));
}
 
源代码11 项目: philadelphia   文件: FIXMessageTest.java
@Test
public void print() {
    MutableDateTime timestamp = new MutableDateTime(2015, 9, 24, 9, 30, 5, 250);

    message.addField(ClOrdID).setString("123");
    message.addField(HandlInst).setChar(HandlInstValues.AutomatedExecutionNoIntervention);
    message.addField(Symbol).setString("FOO");
    message.addField(Side).setChar(SideValues.Buy);
    message.addField(TransactTime).setTimestamp(timestamp, true);
    message.addField(OrderQty).setInt(100);
    message.addField(OrdType).setChar(OrdTypeValues.Limit);
    message.addField(Price).setFloat(150.25, 2);

    assertEquals("11=123|21=1|55=FOO|54=1|60=20150924-09:30:05.250|" +
            "38=100|40=2|44=150.25|", message.toString());
}
 
源代码12 项目: Raigad   文件: DatePatternIndexNameFilter.java
@Override
public boolean filter(String name) {
    try {
        MutableDateTime instant = new MutableDateTime();
        int pos = formatter.parseInto(instant, name, 0);
        return pos > 0
            && pos == name.length()
            && checkYear(instant)
            && reproducible(name, instant);
    } catch (IllegalArgumentException e) {
        return false;
    }
}
 
源代码13 项目: astor   文件: DateTimePerformance.java
private void checkJISOSetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
源代码14 项目: SimFix   文件: 1_DateTimeFormatter.java
/**
 * Parses a date-time from the given text, returning a new MutableDateTime.
 * <p>
 * The parse will use the zone and chronology specified on this formatter.
 * <p>
 * If the text contains a time zone string then that will be taken into
 * account in adjusting the time of day as follows.
 * If the {@link #withOffsetParsed()} has been called, then the resulting
 * DateTime will have a fixed offset based on the parsed time zone.
 * Otherwise the resulting DateTime will have the zone of this formatter,
 * but the parsed zone may have caused the time to be adjusted.
 *
 * @param text  the text to parse, not null
 * @return the parsed date-time, never null
 * @throws UnsupportedOperationException if parsing is not supported
 * @throws IllegalArgumentException if the text to parse is invalid
 */
public MutableDateTime parseMutableDateTime(String text) {
    DateTimeParser parser = requireParser();
    
    Chronology chrono = selectChronology(null);
    DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, iLocale, iPivotYear, iDefaultYear);
    int newPos = parser.parseInto(bucket, text, 0);
    if (newPos >= 0) {
        if (newPos >= text.length()) {
            long millis = bucket.computeMillis(true, text);
            if (iOffsetParsed && bucket.getOffsetInteger() != null) {
                int parsedOffset = bucket.getOffsetInteger();
                DateTimeZone parsedZone = DateTimeZone.forOffsetMillis(parsedOffset);
                chrono = chrono.withZone(parsedZone);
            } else if (bucket.getZone() != null) {
                chrono = chrono.withZone(bucket.getZone());
            }
            MutableDateTime dt = new MutableDateTime(millis, chrono);
            if (iZone != null) {
                dt.setZone(iZone);
            }
            return dt;
        }
    } else {
        newPos = ~newPos;
    }
    throw new IllegalArgumentException(FormatUtils.createErrorMessage(text, newPos));
}
 
源代码15 项目: astor   文件: DateTimePerformance.java
private void checkJodaSetGetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "setGetHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            int val = dt.getHourOfDay();
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
源代码16 项目: astor   文件: TestTextFields.java
public void testWeekdayNames() {
    DateTimeFormatter printer = DateTimeFormat.forPattern("EEEE");
    for (int i=0; i<ZONES.length; i++) {
        MutableDateTime mdt = new MutableDateTime(2004, 1, 1, 1, 20, 30, 40, ZONES[i]);
        for (int day=1; day<=366; day++) {
            mdt.setDayOfYear(day);
            int weekday = mdt.getDayOfWeek();
            String weekdayText = printer.print(mdt);
            assertEquals(WEEKDAYS[weekday], weekdayText);
        }
    }
}
 
源代码17 项目: astor   文件: DateTimePerformance.java
private void checkJodaSetGetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "setGetHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            int val = dt.getHourOfDay();
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
源代码18 项目: sql-layer   文件: MDateAndTime.java
public static MutableDateTime toJodaDateTime(long[] dt, DateTimeZone dtz) {
    return new MutableDateTime((int)dt[YEAR_INDEX],
                               (int)dt[MONTH_INDEX],
                               (int)dt[DAY_INDEX],
                               (int)dt[HOUR_INDEX],
                               (int)dt[MIN_INDEX],
                               (int)dt[SEC_INDEX],
                               0,
                               dtz);
}
 
源代码19 项目: sql-layer   文件: MYearWeek.java
private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);

    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int week = cal.getDayOfYear() - (firstD +1 ); // Sun/Mon
    if (firstD < 4)
    {
        if (week < 0) return  modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31);
        else return yr * 100 + week / 7 + 1;
    }
    else
    {
        if (week < 0) return yr * 100 + 1;
        else return yr * 100 + week / 7 + 2;
    }
}
 
源代码20 项目: astor   文件: DateTimePerformance.java
private void checkJISOSetYear() {
    int COUNT = COUNT_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setYear");
        for (int j = 0; j < COUNT; j++) {
            dt.setYear(1972);
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
源代码21 项目: components   文件: ValueConverterTest.java
@Test
public void testXMLGregorianCalendarConverter() throws Exception {
    DateTimeZone tz1 = DateTimeZone.getDefault();

    MutableDateTime dateTime1 = new MutableDateTime(tz1);
    dateTime1.setDate(System.currentTimeMillis());
    Long controlValue1 = dateTime1.getMillis();

    XMLGregorianCalendar xmlCalendar1 = datatypeFactory.newXMLGregorianCalendar();
    xmlCalendar1.setYear(dateTime1.getYear());
    xmlCalendar1.setMonth(dateTime1.getMonthOfYear());
    xmlCalendar1.setDay(dateTime1.getDayOfMonth());
    xmlCalendar1.setHour(dateTime1.getHourOfDay());
    xmlCalendar1.setMinute(dateTime1.getMinuteOfHour());
    xmlCalendar1.setSecond(dateTime1.getSecondOfMinute());
    xmlCalendar1.setMillisecond(dateTime1.getMillisOfSecond());
    xmlCalendar1.setTimezone(tz1.toTimeZone().getOffset(dateTime1.getMillis()) / 60000);

    FieldDesc fieldInfo = typeDesc.getField("tranDate");

    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());

    AvroConverter<XMLGregorianCalendar, Long> converter1 =
            (AvroConverter<XMLGregorianCalendar, Long>) transducer.getValueConverter(fieldInfo);
    assertEquals(AvroUtils._logicalTimestamp(), converter1.getSchema());
    assertEquals(XMLGregorianCalendar.class, converter1.getDatumClass());
    assertEquals(controlValue1,
            converter1.convertToAvro(xmlCalendar1));
    assertEquals(xmlCalendar1,
            converter1.convertToDatum(controlValue1));

    AvroConverter<XMLGregorianCalendar, Object> converter2 =
            (AvroConverter<XMLGregorianCalendar, Object>) transducer.getValueConverter(fieldInfo);
    assertEquals(xmlCalendar1,
            converter2.convertToDatum(new Date(controlValue1.longValue())));

    assertNull(converter1.convertToAvro(null));
}
 
@Override
public XMLGregorianCalendar convertToDatum(Object timestamp) {
    if (timestamp == null) {
        return null;
    }

    long timestampMillis;
    if (timestamp instanceof Long) {
        timestampMillis = ((Long) timestamp).longValue();
    } else if (timestamp instanceof Date) {
        timestampMillis = ((Date) timestamp).getTime();
    } else {
        throw new IllegalArgumentException("Unsupported Avro timestamp value: " + timestamp);
    }

    MutableDateTime dateTime = new MutableDateTime();
    dateTime.setMillis(timestampMillis);

    XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar();
    xts.setYear(dateTime.getYear());
    xts.setMonth(dateTime.getMonthOfYear());
    xts.setDay(dateTime.getDayOfMonth());
    xts.setHour(dateTime.getHourOfDay());
    xts.setMinute(dateTime.getMinuteOfHour());
    xts.setSecond(dateTime.getSecondOfMinute());
    xts.setMillisecond(dateTime.getMillisOfSecond());
    xts.setTimezone(dateTime.getZone().toTimeZone().getOffset(dateTime.getMillis()) / 60000);

    return xts;
}
 
源代码23 项目: astor   文件: DateTimePerformance.java
private void checkJISOSetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
源代码24 项目: astor   文件: DateTimePerformance.java
private void checkJodaSetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "setHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
源代码25 项目: astor   文件: DateTimeFormatter.java
/**
 * Parses a date-time from the given text, returning a new MutableDateTime.
 * <p>
 * The parse will use the zone and chronology specified on this formatter.
 * <p>
 * If the text contains a time zone string then that will be taken into
 * account in adjusting the time of day as follows.
 * If the {@link #withOffsetParsed()} has been called, then the resulting
 * DateTime will have a fixed offset based on the parsed time zone.
 * Otherwise the resulting DateTime will have the zone of this formatter,
 * but the parsed zone may have caused the time to be adjusted.
 *
 * @param text  the text to parse, not null
 * @return the parsed date-time, never null
 * @throws UnsupportedOperationException if parsing is not supported
 * @throws IllegalArgumentException if the text to parse is invalid
 */
public MutableDateTime parseMutableDateTime(String text) {
    DateTimeParser parser = requireParser();
    
    Chronology chrono = selectChronology(null);
    DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, iLocale, iPivotYear, iDefaultYear);
    int newPos = parser.parseInto(bucket, text, 0);
    if (newPos >= 0) {
        if (newPos >= text.length()) {
            long millis = bucket.computeMillis(true, text);
            if (iOffsetParsed && bucket.getOffsetInteger() != null) {
                int parsedOffset = bucket.getOffsetInteger();
                DateTimeZone parsedZone = DateTimeZone.forOffsetMillis(parsedOffset);
                chrono = chrono.withZone(parsedZone);
            } else if (bucket.getZone() != null) {
                chrono = chrono.withZone(bucket.getZone());
            }
            MutableDateTime dt = new MutableDateTime(millis, chrono);
            if (iZone != null) {
                dt.setZone(iZone);
            }
            return dt;
        }
    } else {
        newPos = ~newPos;
    }
    throw new IllegalArgumentException(FormatUtils.createErrorMessage(text, newPos));
}
 
源代码26 项目: astor   文件: DateTimePerformance.java
private void checkJISOSetGetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setGetHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            int val = dt.getHourOfDay();
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
源代码27 项目: jfixture   文件: ReadableInstantRelay.java
@Override
public Object create(Object request, SpecimenContext context) {
    if (!(request.equals(ReadableInstant.class) ||
            request.equals(ReadWritableInstant.class) ||
            request.equals(ReadableDateTime.class) ||
            request.equals(ReadWritableDateTime.class))) {
        return new NoSpecimen();
    }

    DateTime date = (DateTime) context.resolve(DateTime.class);
    return new MutableDateTime(date);
}
 
源代码28 项目: philadelphia   文件: FIXValue.java
/**
 * Get the value as a date.
 *
 * <p><strong>Note.</strong> This method sets both date and time fields.
 * When combining this method and {@link #asTimeOnly(MutableDateTime)},
 * this method should be invoked first.</p>
 *
 * @param x a date
 * @throws FIXValueFormatException if the value is not a date
 * @see #asTimeOnly(MutableDateTime)
 */
public void asDate(MutableDateTime x) {
    if (length != 8)
        notDate();

    int year        = getDigits(4, offset + 0);
    int monthOfYear = getDigits(2, offset + 4);
    int dayOfMonth  = getDigits(2, offset + 6);

    // Note: 'setDateTime()' takes roughly 55% of the time 'setDate()'
    // takes. Using individual methods, such as 'setYear()', is faster
    // than using 'setDate()' but still slower than 'setDateTime()'.
    x.setDateTime(year, monthOfYear, dayOfMonth, 0, 0, 0, 0);
}
 
源代码29 项目: philadelphia   文件: FIXValue.java
/**
 * Get the value as a time only.
 *
 * @param x a time only
 * @throws FIXValueFormatException if the value is not a time only
 * @see #asDate(MutableDateTime)
 */
public void asTimeOnly(MutableDateTime x) {
    if (length != 8 && length != 12)
        notTimeOnly();

    int hourOfDay      = getDigits(2, offset + 0);
    int minuteOfHour   = getDigits(2, offset + 3);
    int secondOfMinute = getDigits(2, offset + 6);
    int millisOfSecond = length == 12 ? getDigits(3, offset + 9) : 0;

    x.setTime(hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}
 
源代码30 项目: coming   文件: Cardumen_0073_t.java
/**
 * Parses a date-time from the given text, returning a new MutableDateTime.
 * <p>
 * The parse will use the zone and chronology specified on this formatter.
 * <p>
 * If the text contains a time zone string then that will be taken into
 * account in adjusting the time of day as follows.
 * If the {@link #withOffsetParsed()} has been called, then the resulting
 * DateTime will have a fixed offset based on the parsed time zone.
 * Otherwise the resulting DateTime will have the zone of this formatter,
 * but the parsed zone may have caused the time to be adjusted.
 *
 * @param text  the text to parse, not null
 * @return the parsed date-time, never null
 * @throws UnsupportedOperationException if parsing is not supported
 * @throws IllegalArgumentException if the text to parse is invalid
 */
public MutableDateTime parseMutableDateTime(String text) {
    DateTimeParser parser = requireParser();
    
    Chronology chrono = selectChronology(null);
    DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, iLocale, iPivotYear, iDefaultYear);
    int newPos = parser.parseInto(bucket, text, 0);
    if (newPos >= 0) {
        if (newPos >= text.length()) {
            long millis = bucket.computeMillis(true, text);
            if (iOffsetParsed && bucket.getOffsetInteger() != null) {
                int parsedOffset = bucket.getOffsetInteger();
                DateTimeZone parsedZone = DateTimeZone.forOffsetMillis(parsedOffset);
                chrono = chrono.withZone(parsedZone);
            } else if (bucket.getZone() != null) {
                chrono = chrono.withZone(bucket.getZone());
            }
            MutableDateTime dt = new MutableDateTime(millis, chrono);
            if (iZone != null) {
                dt.setZone(iZone);
            }
            return dt;
        }
    } else {
        newPos = ~newPos;
    }
    throw new IllegalArgumentException(FormatUtils.createErrorMessage(text, newPos));
}
 
 类所在包
 同包方法