Java Code Examples for org.joda.time.MutableDateTime#setZone()
The following examples show how to use
org.joda.time.MutableDateTime#setZone() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: 1_DateTimeFormatter.java From SimFix with GNU General Public License v2.0 | 5 votes |
/** * 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)); }
Example 2
Source File: MConvertTZ.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output) { long original = inputs.get(0).getInt64(); long[] ymd = MDateAndTime.decodeDateTime(original); if(!MDateAndTime.isValidDateTime(ymd, ZeroFlag.YEAR)) { output.putNull(); } else { try { DateTimeZone fromTz = MDateAndTime.parseTimeZone(inputs.get(1).getString()); DateTimeZone toTz = MDateAndTime.parseTimeZone(inputs.get(2).getString()); MutableDateTime date = MDateAndTime.toJodaDateTime(ymd, fromTz); // If the value falls out of the supported range of the TIMESTAMP // when converted from fromTz to UTC, no conversion occurs. date.setZone(DateTimeZone.UTC); final long converted; if(MDateAndTime.isValidTimestamp(date)) { date.setZone(toTz); converted = MDateAndTime.encodeDateTime(date); } else { converted = original; } output.putInt64(converted); } catch(InvalidDateFormatException e) { context.warnClient(e); output.putNull(); } } }
Example 3
Source File: Cardumen_0073_s.java From coming with MIT License | 5 votes |
/** * 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)); }
Example 4
Source File: Cardumen_0073_t.java From coming with MIT License | 5 votes |
/** * 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)); }
Example 5
Source File: Time_16_DateTimeFormatter_s.java From coming with MIT License | 5 votes |
/** * 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)); }
Example 6
Source File: Time_16_DateTimeFormatter_t.java From coming with MIT License | 5 votes |
/** * 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)); }
Example 7
Source File: Time_7_DateTimeFormatter_s.java From coming with MIT License | 5 votes |
/** * 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)); }
Example 8
Source File: Time_7_DateTimeFormatter_t.java From coming with MIT License | 5 votes |
/** * 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)); }
Example 9
Source File: DateTimeFormatter.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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)); }
Example 10
Source File: DateTimeFormatter.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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)); }
Example 11
Source File: Asn1UTCTime.java From supl-client with Apache License 2.0 | 4 votes |
/** * Parses a text representation of a time into the new value of this instance. * * <p>The format definition of UTCTime: * * <p>http://www.obj-sys.com/asn1tutorial/node15.html * http://www.obj-sys.com/asn1tutorial/node14.html * * <p>We currently support "[YY]YYMMDDHHMM[SS][Z]" or "[YY]YYMMDDHHMM[SS][+|-]HHMM" * * @param asn1IA5String the text representation * @throws IllegalArgumentException if asn1IA5String contains a malformed representation or the * date part values are out of range * @throws NumberFormatException if parts of asn1IA5String that should parse to numbers can't */ private void retrieveResult(Asn1IA5String asn1IA5String) { TimeTextAndZone timeTextAndZone = extractZone(asn1IA5String.getValue()); int yearLength; int timeLength = timeTextAndZone.timeString.length(); boolean hasSecond = true; switch (timeLength) { case 10: // 2 digit year, no seconds hasSecond = false; // Fall-through case 12: // 2 digit year, with seconds yearLength = LENGTH_OF_2_DIGIT; break; case 14: // 4 digit year, with seconds yearLength = 2 * LENGTH_OF_2_DIGIT; break; default: throw new IllegalArgumentException( "malformed UTCTime format: " + timeTextAndZone.timeString); } int year = Integer.parseInt(timeTextAndZone.timeString.substring(0, yearLength)); // Two-digit year's range is from 1954 to 2053. if (yearLength == LENGTH_OF_2_DIGIT) { if (year > 53) { year += 1900; } else { year += 2000; } } List<String> fields = SPLITTER_2_DIGIT.splitToList( timeTextAndZone.timeString.subSequence(yearLength, timeLength)); int month = Integer.parseInt(fields.get(0)); int day = Integer.parseInt(fields.get(1)); int hour = Integer.parseInt(fields.get(2)); int minute = Integer.parseInt(fields.get(3)); int second = 0; if (hasSecond) { second = Integer.parseInt(fields.get(4)); } value = new MutableDateTime(year, month, day, hour, minute, second, 0, timeTextAndZone.zone); if (!DateTimeZone.UTC.equals(timeTextAndZone.zone)) { value.setZone(DateTimeZone.UTC); } }
Example 12
Source File: Asn1UTCTime.java From supl-client with Apache License 2.0 | 2 votes |
/** * Sets the value from a {@link DateTime}. * * @param dateTime the datetime */ public void setValue(DateTime dateTime) { value = new MutableDateTime(dateTime); value.setZone(DateTimeZone.UTC); }