Example usage for org.joda.time Chronology withZone

List of usage examples for org.joda.time Chronology withZone

Introduction

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

Prototype

public abstract Chronology withZone(DateTimeZone zone);

Source Link

Document

Returns an instance of this Chronology that operates in any time zone.

Usage

From source file:com.github.jasonruckman.sidney.ext.common.JodaDateTimeSerializer.java

License:Apache License

@Override
public DateTime readValue(Contexts.ReadContext context) {
    long m = millis.readLong(context);
    Chronology chronology = chrono.readValue(context);
    String zone = tz.readValue(context);
    return new DateTime(m, chronology.withZone(DateTimeZone.forID(zone)));
}

From source file:de.javakaffee.kryoserializers.jodatime.JodaDateTimeSerializer.java

License:Apache License

@Override
public DateTime read(final Kryo kryo, final Input input, final Class<DateTime> type) {
    final long millis = input.readLong(true);
    final Chronology chronology = readChronology(input);
    final DateTimeZone tz = readTimeZone(input);
    return new DateTime(millis, chronology.withZone(tz));
}

From source file:de.javakaffee.web.msm.serializer.javolution.JodaDateTimeFormat.java

License:Apache License

/**
 * {@inheritDoc}//from  ww  w. j a v a  2s.  c o m
 */
@Override
public DateTime newInstance(final Class<DateTime> cls, final javolution.xml.XMLFormat.InputElement input)
        throws XMLStreamException {
    final long millis = input.getAttribute(MILLIS).toLong();
    final Chronology chronology = readChronology(input);
    final DateTimeZone tz = readTimeZone(input);
    return new DateTime(millis, chronology.withZone(tz));
}

From source file:org.renjin.primitives.time.Time.java

License:Open Source License

private static DateTime parseIgnoreTrailingCharacters(DateTimeFormatter formatter, String text) {
    // this is a modified version of DateTimeFormatter.parseDateTime() that does not
    // throw an exception on trailing characters

    Chronology chronology = DateTimeUtils.getChronology(null);
    DateTimeParser parser = formatter.getParser();

    Locale locale = null;/*from   w  w  w  .j a v  a 2  s.  co  m*/
    Integer pivotYear = null;
    int defaultYear = 2000;
    DateTimeZone timeZone = null;

    DateTimeParserBucket bucket = new DateTimeParserBucket(0, chronology, locale, pivotYear, defaultYear);
    int newPos = parser.parseInto(bucket, text, 0);
    if (newPos >= 0) {
        long millis = bucket.computeMillis(true, text);
        if (formatter.isOffsetParsed() && bucket.getOffsetInteger() != null) {
            int parsedOffset = bucket.getOffsetInteger();
            DateTimeZone parsedZone = DateTimeZone.forOffsetMillis(parsedOffset);
            chronology = chronology.withZone(parsedZone);
        } else if (bucket.getZone() != null) {
            chronology = chronology.withZone(bucket.getZone());
        }
        DateTime dt = new DateTime(millis, chronology);
        if (timeZone != null) {
            dt = dt.withZone(timeZone);
        }
        return dt;
    }
    throw new IllegalArgumentException();
}