protected Calendar parseDate(String date) throws Exception { Calendar dateCalendar = null; try { dateCalendar = ISODateTimeFormat.dateTimeParser().withZone(DateTimeZone.forTimeZone( clockReader.getCurrentTimeZone())).parseDateTime(date).toCalendar(null); } catch (IllegalArgumentException e) { // try to parse a java.util.date to string back to a java.util.date dateCalendar = new GregorianCalendar(); DateFormat DATE_FORMAT = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy", Locale.ENGLISH); dateCalendar.setTime(DATE_FORMAT.parse(date)); } return dateCalendar; }
@Override public Date resolveEndDate(String endDateString) { return ISODateTimeFormat.dateTimeParser().withZone(DateTimeZone.forTimeZone(clockReader.getCurrentTimeZone())).parseDateTime(endDateString).toCalendar(null).getTime(); }
/** * Parses an {@code Instant} from the specified string. * <p> * This uses {@link ISODateTimeFormat#dateTimeParser()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static Instant parse(String str) { return parse(str, ISODateTimeFormat.dateTimeParser()); }
/** * Parses an {@code Instant} from the specified string. * <p> * This uses {@link ISODateTimeFormat#dateTimeParser()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static Instant parse(String str) { return parse(str, ISODateTimeFormat.dateTimeParser()); }
/** * Gets the millis, which is the ISO parsed string value. * * @param object the String to convert, must not be null * @param chrono the chronology to use, non-null result of getChronology * @return the millisecond value * @throws IllegalArgumentException if the value if invalid */ public long getInstantMillis(Object object, Chronology chrono) { String str = (String) object; DateTimeFormatter p = ISODateTimeFormat.dateTimeParser(); return p.withChronology(chrono).parseMillis(str); }
/** * Gets the millis, which is the ISO parsed string value. * * @param object the String to convert, must not be null * @param chrono the chronology to use, non-null result of getChronology * @return the millisecond value * @throws IllegalArgumentException if the value if invalid */ public long getInstantMillis(Object object, Chronology chrono) { String str = (String) object; DateTimeFormatter p = ISODateTimeFormat.dateTimeParser(); return p.withChronology(chrono).parseMillis(str); }
/** * Parses a {@code DateTime} from the specified string. * <p> * This uses {@link ISODateTimeFormat#dateTimeParser()}{@code .withOffsetParsed()} * which is different to passing a {@code String} to the constructor. * <p> * Sometimes this method and {@code new DateTime(str)} return different results. * This can be confusing as the difference is not visible in {@link #toString()}. * <p> * When passed a date-time string without an offset, such as '2010-06-30T01:20', * both the constructor and this method use the default time-zone. * As such, {@code DateTime.parse("2010-06-30T01:20")} and * {@code new DateTime("2010-06-30T01:20"))} are equal. * <p> * However, when this method is passed a date-time string with an offset, * the offset is directly parsed and stored. * As such, {@code DateTime.parse("2010-06-30T01:20+02:00")} and * {@code new DateTime("2010-06-30T01:20+02:00"))} are NOT equal. * The object produced via this method has a zone of {@code DateTimeZone.forOffsetHours(2)}. * The object produced via the constructor has a zone of {@code DateTimeZone.getDefault()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static DateTime parse(String str) { return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed()); }
/** * Parses a {@code MutableDateTime} from the specified string. * <p> * This uses {@link ISODateTimeFormat#dateTimeParser()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static MutableDateTime parse(String str) { return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed()); }
/** * Parses a {@code DateTime} from the specified string. * <p> * This uses {@link ISODateTimeFormat#dateTimeParser()}{@code .withOffsetParsed()} * which is different to passing a {@code String} to the constructor. * <p> * Sometimes this method and {@code new DateTime(str)} return different results. * This can be confusing as the difference is not visible in {@link #toString()}. * <p> * When passed a date-time string without an offset, such as '2010-06-30T01:20', * both the constructor and this method use the default time-zone. * As such, {@code DateTime.parse("2010-06-30T01:20")} and * {@code new DateTime("2010-06-30T01:20"))} are equal. * <p> * However, when this method is passed a date-time string with an offset, * the offset is directly parsed and stored. * As such, {@code DateTime.parse("2010-06-30T01:20+02:00")} and * {@code new DateTime("2010-06-30T01:20+02:00"))} are NOT equal. * The object produced via this method has a zone of {@code DateTimeZone.forOffsetHours(2)}. * The object produced via the constructor has a zone of {@code DateTimeZone.getDefault()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static DateTime parse(String str) { return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed()); }
/** * Parses a {@code DateMidnight} from the specified string. * <p> * This uses {@link ISODateTimeFormat#dateTimeParser()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static DateMidnight parse(String str) { return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed()); }
/** * Parses a {@code MutableDateTime} from the specified string. * <p> * This uses {@link ISODateTimeFormat#dateTimeParser()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static MutableDateTime parse(String str) { return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed()); }
/** * Parses a {@code DateMidnight} from the specified string. * <p> * This uses {@link ISODateTimeFormat#dateTimeParser()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static DateMidnight parse(String str) { return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed()); }
DateTimeFormatter dateTimeParser = ISODateTimeFormat.dateTimeParser().withOffsetParsed(); PeriodFormatter periodParser = ISOPeriodFormat.standard(); DateTime start = null;
DateTimeFormatter dateTimeParser = ISODateTimeFormat.dateTimeParser(); dateTimeParser = dateTimeParser.withChronology(chrono); PeriodFormatter periodParser = ISOPeriodFormat.standard();
DateTimeFormatter dateTimeParser = ISODateTimeFormat.dateTimeParser().withOffsetParsed(); PeriodFormatter periodParser = ISOPeriodFormat.standard(); DateTime start = null;
DateTimeFormatter dateTimeParser = ISODateTimeFormat.dateTimeParser(); dateTimeParser = dateTimeParser.withChronology(chrono); PeriodFormatter periodParser = ISOPeriodFormat.standard();
@ScalarFunction("from_iso8601_timestamp") @LiteralParameters("x") @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long fromISO8601Timestamp(ConnectorSession session, @SqlType("varchar(x)") Slice iso8601DateTime) { DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser() .withChronology(getChronology(session.getTimeZoneKey())) .withOffsetParsed(); return packDateTimeWithZone(parseDateTimeHelper(formatter, iso8601DateTime.toStringUtf8())); }
/** * Parses a {@code Instant} from the specified string. * <p> * This uses {@link ISODateTimeFormat#dateTimeParser()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static Instant parse(String str) { return parse(str, ISODateTimeFormat.dateTimeParser()); }
/** * Parses a {@code DateMidnight} from the specified string. * <p> * This uses {@link ISODateTimeFormat#dateTimeParser()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static DateMidnight parse(String str) { return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed()); }
/** * Parses a {@code MutableDateTime} from the specified string. * <p> * This uses {@link ISODateTimeFormat#dateTimeParser()}. * * @param str the string to parse, not null * @since 2.0 */ @FromString public static MutableDateTime parse(String str) { return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed()); }