@Override @Nullable public Object convert(String value) { if (value == null || value.isEmpty()) { return null; } final Parser parser = new Parser(timeZone.toTimeZone()); final List<DateGroup> r = parser.parse(value); if (r.isEmpty() || r.get(0).getDates().isEmpty()) { return null; } return new DateTime(r.get(0).getDates().get(0), timeZone); } }
/** * Get the date time as a <code>java.util.GregorianCalendar</code>, * assigning exactly the same millisecond instant. * <p> * The JDK and Joda-Time both have time zone implementations and these * differ in accuracy. Joda-Time's implementation is generally more up to * date and thus more accurate - for example JDK1.3 has no historical data. * The effect of this is that the field values of the <code>Calendar</code> * may differ from those of this object, even though the millisecond value * is the same. Most of the time this just means that the JDK field values * are wrong, as our time zone information is more up to date. * * @return a GregorianCalendar initialised with this datetime */ public GregorianCalendar toGregorianCalendar() { DateTimeZone zone = getZone(); GregorianCalendar cal = new GregorianCalendar(zone.toTimeZone()); cal.setTime(toDate()); return cal; }
/** * Get the date time as a <code>java.util.Calendar</code>, assigning * exactly the same millisecond instant. * The locale is passed in, enabling Calendar to select the correct * localized subclass. * <p> * The JDK and Joda-Time both have time zone implementations and these * differ in accuracy. Joda-Time's implementation is generally more up to * date and thus more accurate - for example JDK1.3 has no historical data. * The effect of this is that the field values of the <code>Calendar</code> * may differ from those of this object, even though the millisecond value * is the same. Most of the time this just means that the JDK field values * are wrong, as our time zone information is more up to date. * * @param locale the locale to get the Calendar for, or default if null * @return a localized Calendar initialised with this datetime */ public Calendar toCalendar(Locale locale) { if (locale == null) { locale = Locale.getDefault(); } DateTimeZone zone = getZone(); Calendar cal = Calendar.getInstance(zone.toTimeZone(), locale); cal.setTime(toDate()); return cal; }
@Override protected DateTime evaluate(FunctionArgs args, EvaluationContext context, DateTimeZone timezone) { final String time = valueParam.required(args, context); final List<DateGroup> dates = new Parser(timezone.toTimeZone()).parse(time); if (dates.size() == 0) { final Optional<DateTime> defaultTime = defaultParam.optional(args, context); if (defaultTime.isPresent()) { return defaultTime.get(); } // TODO really? this should probably throw an exception of some sort to be handled in the interpreter return null; } return new DateTime(dates.get(0).getDates().get(0), timezone); }
/** * Get the date time as a <code>java.util.GregorianCalendar</code>, * assigning exactly the same millisecond instant. * <p> * The JDK and Joda-Time both have time zone implementations and these * differ in accuracy. Joda-Time's implementation is generally more up to * date and thus more accurate - for example JDK1.3 has no historical data. * The effect of this is that the field values of the <code>Calendar</code> * may differ from those of this object, even though the millisecond value * is the same. Most of the time this just means that the JDK field values * are wrong, as our time zone information is more up to date. * * @return a GregorianCalendar initialised with this datetime */ public GregorianCalendar toGregorianCalendar() { DateTimeZone zone = getZone(); GregorianCalendar cal = new GregorianCalendar(zone.toTimeZone()); cal.setTime(toDate()); return cal; }
/** * Get the date time as a <code>java.util.Calendar</code>, assigning * exactly the same millisecond instant. * The locale is passed in, enabling Calendar to select the correct * localized subclass. * <p> * The JDK and Joda-Time both have time zone implementations and these * differ in accuracy. Joda-Time's implementation is generally more up to * date and thus more accurate - for example JDK1.3 has no historical data. * The effect of this is that the field values of the <code>Calendar</code> * may differ from those of this object, even though the millisecond value * is the same. Most of the time this just means that the JDK field values * are wrong, as our time zone information is more up to date. * * @param locale the locale to get the Calendar for, or default if null * @return a localized Calendar initialised with this datetime */ public Calendar toCalendar(Locale locale) { if (locale == null) { locale = Locale.getDefault(); } DateTimeZone zone = getZone(); Calendar cal = Calendar.getInstance(zone.toTimeZone(), locale); cal.setTime(toDate()); return cal; }
@Test public void testCastToTimeWithTimeZone() { assertFunction("cast(TIME '03:04:05.321' as time with time zone)", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, DATE_TIME_ZONE).getMillis(), DATE_TIME_ZONE.toTimeZone())); }
private static SqlTimestampWithTimeZone toTimestampWithTimeZone(DateTime dateTime) { return new SqlTimestampWithTimeZone(dateTime.getMillis(), dateTime.getZone().toTimeZone()); } }
@Test public void testCastToTimestampWithTimeZone() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 321, DATE_TIME_ZONE).getMillis(), DATE_TIME_ZONE.toTimeZone())); functionAssertions.assertFunctionString("cast(TIMESTAMP '2001-1-22 03:04:05.321' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, "2001-01-22 03:04:05.321 " + DATE_TIME_ZONE.getID()); }
public static void assertTimeZone(String zoneId, DateTimeZone dateTimeZone) { long dateTimeWithTimeZone = packDateTimeWithZone(new DateTime(42, dateTimeZone)); assertEquals(packDateTimeWithZone((long) 42, dateTimeZone.toTimeZone().getID()), dateTimeWithTimeZone); DateTimeZone unpackedZone = unpackDateTimeZone(dateTimeWithTimeZone); assertDateTimeZoneEquals(zoneId, unpackedZone); }
@Test public void testToTimeZone() { DateTimeZone zone = DateTimeZone.forID("Europe/Paris"); TimeZone tz = zone.toTimeZone(); assertEquals("Europe/Paris", tz.getID()); }
@Test public void testCastToTimeWithTimeZoneWithTZWithRulesChanged() { TimeZoneKey timeZoneThatChangedSince1970 = getTimeZoneKey("Asia/Kathmandu"); DateTimeZone dateTimeZoneThatChangedSince1970 = getDateTimeZone(timeZoneThatChangedSince1970); Session session = Session.builder(this.session) .setTimeZoneKey(timeZoneThatChangedSince1970) .build(); try (FunctionAssertions localAssertions = new FunctionAssertions(session)) { localAssertions.assertFunction( "cast(TIME '03:04:05.321' as time with time zone)", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, dateTimeZoneThatChangedSince1970).getMillis(), dateTimeZoneThatChangedSince1970.toTimeZone())); } }
@Test public void testTimeZoneConversion() { TimeZone jdkTimeZone = TimeZone.getTimeZone("GMT-10"); assertEquals("GMT-10:00", jdkTimeZone.getID()); DateTimeZone jodaTimeZone = DateTimeZone.forTimeZone(jdkTimeZone); assertEquals("-10:00", jodaTimeZone.getID()); assertEquals(jdkTimeZone.getRawOffset(), jodaTimeZone.getOffset(0L)); TimeZone convertedTimeZone = jodaTimeZone.toTimeZone(); assertEquals("GMT-10:00", jdkTimeZone.getID()); assertEquals(jdkTimeZone.getID(), convertedTimeZone.getID()); assertEquals(jdkTimeZone.getRawOffset(), convertedTimeZone.getRawOffset()); }
protected Message decodeCEF(@Nonnull RawMessage rawMessage, String s) { try { final MappedMessage cef = new MappedMessage(parser.parse(s, timezone.toTimeZone(), locale), useFullNames); // Build standard message. Message result = new Message(buildMessageSummary(cef), decideSource(cef, rawMessage), new DateTime(cef.timestamp())); // Add all extensions. result.addFields(cef.mappedExtensions()); // Add standard CEF fields. result.addField("device_vendor", cef.deviceVendor()); result.addField("device_product", cef.deviceProduct()); result.addField("device_version", cef.deviceVersion()); result.addField("event_class_id", cef.deviceEventClassId()); result.addField("name", cef.name()); result.addField("severity", cef.severity()); return result; } catch (Exception e) { throw new RuntimeException("Could not decode CEF message.", e); } }
.setTimeZone(nonDefaultTimeZone().toTimeZone().getID()) .setMaxSplitSize(new DataSize(256, Unit.MEGABYTE)) .setMaxPartitionsPerScan(123)
public JacksonJodaDateFormat(DateTimeFormatter defaultFormatter) { super(); _formatter = defaultFormatter; DateTimeZone tz = defaultFormatter.getZone(); _jdkTimezone = (tz == null) ? null : tz.toTimeZone(); _explicitTimezone = false; _adjustToContextTZOverride = null; _writeZoneId = null; }
@Override public TimeZone getTimeZone() { return formatter.getZone().toTimeZone(); } }
/** * Get the date time as a <code>java.util.GregorianCalendar</code>, * assigning exactly the same millisecond instant. * <p> * The JDK and Joda-Time both have time zone implementations and these * differ in accuracy. Joda-Time's implementation is generally more up to * date and thus more accurate - for example JDK1.3 has no historical data. * The effect of this is that the field values of the <code>Calendar</code> * may differ from those of this object, even though the milliseond value * is the same. Most of the time this just means that the JDK field values * are wrong, as our time zone information is more up to date. * * @return a GregorianCalendar initialised with this datetime */ public GregorianCalendar toGregorianCalendar() { DateTimeZone zone = getZone(); GregorianCalendar cal = new GregorianCalendar(zone.toTimeZone()); cal.setTime(toDate()); return cal; }
.withPort(mysqlPort) .withUser("mysqlUser", "mysqlPass") .withTimeZone(DateTimeZone.UTC.toTimeZone()) .build();
/** * Get the date time as a <code>java.util.Calendar</code>, assigning * exactly the same millisecond instant. * The locale is passed in, enabling Calendar to select the correct * localized subclass. * <p> * The JDK and Joda-Time both have time zone implementations and these * differ in accuracy. Joda-Time's implementation is generally more up to * date and thus more accurate - for example JDK1.3 has no historical data. * The effect of this is that the field values of the <code>Calendar</code> * may differ from those of this object, even though the milliseond value * is the same. Most of the time this just means that the JDK field values * are wrong, as our time zone information is more up to date. * * @param locale the locale to get the Calendar for, or default if null * @return a localized Calendar initialised with this datetime */ public Calendar toCalendar(Locale locale) { if (locale == null) { locale = Locale.getDefault(); } DateTimeZone zone = getZone(); Calendar cal = Calendar.getInstance(zone.toTimeZone(), locale); cal.setTime(toDate()); return cal; }