Example usage for org.joda.time DateTimeZone forOffsetMillis

List of usage examples for org.joda.time DateTimeZone forOffsetMillis

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone forOffsetMillis.

Prototype

public static DateTimeZone forOffsetMillis(int millisOffset) 

Source Link

Document

Gets a time zone instance for the specified offset to UTC in milliseconds.

Usage

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

public static IDataTypeParser dateTime() {
    if (dateTimeDataTypeParser == null) {
        dateTimeDataTypeParser = new AbstractISO8601DataTypeParser(dateTimeFormatter()) {
            protected Object parseWithTimeZone(DateTimeParserBucket bucket) {
                DateTimeZone zone = DateTimeZone.forOffsetMillis(bucket.getOffset());
                return new DateTime(bucket.computeMillis(), validate(zone));
            }// w w  w .j  a va  2  s.c om

            protected Object parseWithoutTimeZone(DateTimeParserBucket bucket) {
                return new LocalDateTime(bucket.computeMillis());
            }
        };
    }
    return dateTimeDataTypeParser;
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

public static IDataTypeParser date() {
    if (dateDataTypeParser == null) {
        dateDataTypeParser = new AbstractISO8601DataTypeParser(dateFormatter()) {
            protected Object parseWithTimeZone(DateTimeParserBucket bucket) {
                DateTimeZone zone = DateTimeZone.forOffsetMillis(bucket.getOffset());
                return new Interval(new DateTime(bucket.computeMillis(), validate(zone)), Days.ONE);
            }/*  ww  w.  j  a v  a  2s.  com*/

            protected Object parseWithoutTimeZone(DateTimeParserBucket bucket) {
                return new LocalDate(bucket.computeMillis());
            }

            @Override
            public String unparseObject(EntityDescriptor<?> ed, Object value) {
                if (value instanceof ReadableInterval) {
                    // make use of recoverable time zones
                    DateTime start = ((ReadableInterval) value).getStart();
                    int millisOffset = start.getZone().getOffset(0L);
                    DateTimeZone zone = DateTimeZone.forOffsetMillis(millisOffset > TZ_REC_UPPER_MILLIS
                            ? millisOffset - H24
                            : (millisOffset <= TZ_REC_LOWER_MILLIS ? millisOffset + H24 : millisOffset));
                    return getFormatter().withZone(zone).print(start);
                } else
                    return super.unparseObject(ed, value);
            }
        };
    }
    return dateDataTypeParser;
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

public static IDataTypeParser yearMonth() {
    if (yearMonthDataTypeParser == null) {
        yearMonthDataTypeParser = new AbstractISO8601DataTypeParser(yearMonthFormatter()) {
            protected Object parseWithTimeZone(DateTimeParserBucket bucket) {
                DateTimeZone zone = DateTimeZone.forOffsetMillis(bucket.getOffset());
                return new Interval(new DateTime(bucket.computeMillis(), validate(zone)), Months.ONE);
            }/*from  w  w  w  . j  a v a 2 s.com*/

            protected Object parseWithoutTimeZone(DateTimeParserBucket bucket) {
                return new LocalDate(bucket.computeMillis());
            }
        };
    }
    return yearMonthDataTypeParser;
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

public static IDataTypeParser year() {
    if (yearDataTypeParser == null) {
        yearDataTypeParser = new AbstractISO8601DataTypeParser(yearFormatter()) {
            protected Object parseWithTimeZone(DateTimeParserBucket bucket) {
                DateTimeZone zone = DateTimeZone.forOffsetMillis(bucket.getOffset());
                return new Interval(new DateTime(bucket.computeMillis(), validate(zone)), Years.ONE);
            }/*from   ww  w  . j a  v a 2 s .c  o  m*/

            protected Object parseWithoutTimeZone(DateTimeParserBucket bucket) {
                return new LocalDate(bucket.computeMillis());
            }
        };
    }
    return yearDataTypeParser;
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

public static IDataTypeParser monthDay() {
    if (monthDayDataTypeParser == null) {
        monthDayDataTypeParser = new AbstractISO8601DataTypeParser(monthDayFormatter()) {
            protected Object parseWithTimeZone(DateTimeParserBucket bucket) {
                DateTimeZone zone = DateTimeZone.forOffsetMillis(bucket.getOffset());
                return new Interval(new DateTime(bucket.computeMillis(), validate(zone)), Days.ONE);
            }//from w  ww  .j av  a 2  s  .  c  om

            protected Object parseWithoutTimeZone(DateTimeParserBucket bucket) {
                return new LocalDate(bucket.computeMillis());
            }
        };
    }
    return monthDayDataTypeParser;
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

public static IDataTypeParser month() {
    if (monthDataTypeParser == null) {
        monthDataTypeParser = new AbstractISO8601DataTypeParser(monthFormatter()) {
            protected Object parseWithTimeZone(DateTimeParserBucket bucket) {
                DateTimeZone zone = DateTimeZone.forOffsetMillis(bucket.getOffset());
                return new Interval(new DateTime(bucket.computeMillis(), validate(zone)), Months.ONE);
            }/* w w w .  jav  a  2  s .  co m*/

            protected Object parseWithoutTimeZone(DateTimeParserBucket bucket) {
                return new LocalDate(bucket.computeMillis());
            }
        };
    }
    return monthDataTypeParser;
}

From source file:org.whole.lang.xsd.parsers.SchemaDataTypeParsers.java

License:Open Source License

public static IDataTypeParser day() {
    if (dayDataTypeParser == null) {
        dayDataTypeParser = new AbstractISO8601DataTypeParser(dayFormatter()) {
            protected Object parseWithTimeZone(DateTimeParserBucket bucket) {
                DateTimeZone zone = DateTimeZone.forOffsetMillis(bucket.getOffset());
                return new Interval(new DateTime(bucket.computeMillis(), validate(zone)), Days.ONE);
            }/* w w  w.j a v  a 2 s  . c o  m*/

            protected Object parseWithoutTimeZone(DateTimeParserBucket bucket) {
                return new LocalDate(bucket.computeMillis());
            }
        };
    }
    return dayDataTypeParser;
}

From source file:uk.ac.ucl.excites.sapelli.storage.types.TimeStamp.java

License:Apache License

/**
 * Returns a DateTimeZone for the given millisecond offset.
 * /*from   w  w w .  ja va 2 s . co  m*/
 * <p><b>Note (2013-07-13):</b><br/>
 *    Implementation used to be:<br/>
 *       {@code return DateTimeZone.forTimeZone(uk.ac.ucl.excites.util.TimeUtils.getTimeZone(offsetMS));}<br/>
 *   Seems to make no difference w.r.t. offset (although we do not get "named" zones this way, but the names could have been wrong anyway, due to DST).</p>
 * 
 * @param offsetMS offset to UTC in milliseconds
 * @return a matching (but unnamed) DateTimeZone instance
 */
static public DateTimeZone getDateTimeZoneForMSOffset(int offsetMS) {
    return DateTimeZone.forOffsetMillis(offsetMS);
}