private String dateFormat(final DateTime x) { return x.toString(DateTimeFormat.forPattern(Tools.ES_DATE_FORMAT_NO_MS).withZoneUTC()); } }
public SyslogParser() { timeParser = DateTimeFormat.forPattern(timePat).withZoneUTC(); timestampCache = CacheBuilder.newBuilder().maximumSize(TS_CACHE_MAX).build( new CacheLoader<String, Long>() { @Override public Long load(String key) throws Exception { return timeParser.parseMillis(key); } }); }
private static DateTimeFormatter localDateParser() { if (ldp == null) { return dateElementParser().withZoneUTC(); } return ldp; }
private static DateTimeFormatter localDateParser() { if (ldp == null) { return dateElementParser().withZoneUTC(); } return ldp; }
public static boolean timestampHasTimeZone(String value) { try { try { TIMESTAMP_WITH_TIME_ZONE_FORMATTER.parseMillis(value); return true; } catch (RuntimeException e) { // `.withZoneUTC()` makes `timestampHasTimeZone` return value independent of JVM zone TIMESTAMP_WITHOUT_TIME_ZONE_FORMATTER.withZoneUTC().parseMillis(value); return false; } } catch (RuntimeException e) { throw new IllegalArgumentException(format("Invalid timestamp '%s'", value)); } }
public CustomDateTimeJsonFieldDecoder(DecoderColumnHandle columnHandle) { this.columnHandle = requireNonNull(columnHandle, "columnHandle is null"); if (!SUPPORTED_TYPES.contains(columnHandle.getType())) { throwUnsupportedColumnType(columnHandle); } checkArgument(columnHandle.getFormatHint() != null, "format hint not defined for column '%s'", columnHandle.getName()); try { formatter = DateTimeFormat.forPattern(columnHandle.getFormatHint()).withLocale(Locale.ENGLISH).withZoneUTC(); } catch (IllegalArgumentException e) { throw new PrestoException( GENERIC_USER_ERROR, format("invalid joda pattern '%s' passed as format hint for column '%s'", columnHandle.getFormatHint(), columnHandle.getName())); } }
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.date().withZoneUTC(); filter.add(dateTimeFormatter.print(TimeUnit.DAYS.toMillis((long) value)));
entries.add(new Object[]{"5:MINUTES:EPOCH", 1498892400000L, Long.class, 4996308L}); entries.add(new Object[]{"1:DAYS:SIMPLE_DATE_FORMAT:yyyyMMdd", 1498892400000L, String.class, DateTimeFormat .forPattern("yyyyMMdd").withZoneUTC().print(1498892400000L)}); entries.add( new Object[]{"1:DAYS:SIMPLE_DATE_FORMAT:yyyyMMdd tz(America/New_York)", 1498892400000L, String.class, DateTimeFormat 1498892400000L)}); entries.add(new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH", 1498892400000L, String.class, DateTimeFormat .forPattern("yyyyMMdd HH").withZoneUTC().print(1498892400000L)}); entries.add( new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH tz(IST)", 1498892400000L, String.class, DateTimeFormat 1498892400000L)}); entries.add(new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH Z", 1498892400000L, String.class, DateTimeFormat .forPattern("yyyyMMdd HH Z").withZoneUTC().print(1498892400000L)}); entries.add( new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH Z tz(GMT+0500)", 1498892400000L, String.class, DateTimeFormat entries.add( new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:M/d/yyyy h:mm:ss a", 1498892400000L, String.class, DateTimeFormat .forPattern("M/d/yyyy h:mm:ss a").withZoneUTC().print(1498892400000L)}); entries.add(new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:M/d/yyyy h a", 1502066750000L, String.class, DateTimeFormat .forPattern("M/d/yyyy h a").withZoneUTC().print(1502066750000L)}); return entries.toArray(new Object[entries.size()][]);
@DataProvider(name = "testFromFormatToMillisDataProvider") public Object[][] provideTestFromFormatToMillisData() { List<Object[]> entries = new ArrayList<>(); entries.add(new Object[]{"1:HOURS:EPOCH", 416359L, 1498892400000L}); entries.add(new Object[]{"1:MILLISECONDS:EPOCH", 1498892400000L, 1498892400000L}); entries.add(new Object[]{"1:HOURS:EPOCH", 0L, 0L}); entries.add(new Object[]{"5:MINUTES:EPOCH", 4996308L, 1498892400000L}); entries.add(new Object[]{"1:DAYS:SIMPLE_DATE_FORMAT:yyyyMMdd", "20170701", DateTimeFormat.forPattern("yyyyMMdd") .withZoneUTC().parseMillis("20170701")}); entries.add(new Object[]{"1:DAYS:SIMPLE_DATE_FORMAT:yyyyMMdd tz(America/Chicago)", "20170701", DateTimeFormat .forPattern("yyyyMMdd").withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("America/Chicago"))).parseMillis( "20170701")}); entries.add( new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH", "20170701 00", DateTimeFormat.forPattern("yyyyMMdd HH") .withZoneUTC().parseMillis("20170701 00")}); entries.add(new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH tz(GMT+0600)", "20170701 00", DateTimeFormat .forPattern("yyyyMMdd HH").withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT+0600"))).parseMillis( "20170701 00")}); entries.add(new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:yyyyMMdd HH Z", "20170701 00 -07:00", 1498892400000L}); entries.add(new Object[]{"1:HOURS:SIMPLE_DATE_FORMAT:M/d/yyyy h:mm:ss a", "8/7/2017 12:45:50 AM", 1502066750000L}); return entries.toArray(new Object[entries.size()][]); }
/** Example of running a query with timestamp query parameters. */ public void runQueryWithTimestampParameters() throws InterruptedException { // [START bigquery_query_params_timestamps] // BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); DateTime timestamp = new DateTime(2016, 12, 7, 8, 0, 0, DateTimeZone.UTC); String query = "SELECT TIMESTAMP_ADD(@ts_value, INTERVAL 1 HOUR);"; // Note: Standard SQL is required to use query parameters. QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query) .addNamedParameter( "ts_value", QueryParameterValue.timestamp( // Timestamp takes microseconds since 1970-01-01T00:00:00 UTC timestamp.getMillis() * 1000)) .build(); // Print the results. DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC(); for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) { System.out.printf( "%s\n", formatter.print( new DateTime( // Timestamp values are returned in microseconds since 1970-01-01T00:00:00 UTC, // but org.joda.time.DateTime constructor accepts times in milliseconds. row.get(0).getTimestampValue() / 1000, DateTimeZone.UTC))); System.out.printf("\n"); } // [END bigquery_query_params_timestamps] }
private static DateTimeFormatter localTimeParser() { if (ltp == null) { return new DateTimeFormatterBuilder() .appendOptional(literalTElement().getParser()) .append(timeElementParser()) .toFormatter().withZoneUTC(); } return ltp; }
/** * Accepts our ElasticSearch time formats without milliseconds. * * @return A DateTimeFormatter suitable to parse an ES_DATE_FORMAT formatted string to a * DateTime Object even if it contains no milliseconds. */ public static DateTimeFormatter timeFormatterWithOptionalMilliseconds() { // This is the .SSS part DateTimeParser ms = new DateTimeFormatterBuilder() .appendLiteral(".") .appendFractionOfSecond(1, 3) .toParser(); return new DateTimeFormatterBuilder() .append(DateTimeFormat.forPattern(ES_DATE_FORMAT_NO_MS).withZoneUTC()) .appendOptional(ms) .toFormatter(); }
private static DateTimeFormatter localTimeParser() { if (ltp == null) { return new DateTimeFormatterBuilder() .appendOptional(literalTElement().getParser()) .append(timeElementParser()) .toFormatter().withZoneUTC(); } return ltp; }
private static DateTimeFormatter localDateOptionalTimeParser() { if (ldotp == null) { DateTimeParser time = new DateTimeFormatterBuilder() .appendLiteral('T') .append(timeElementParser()) .toParser(); return new DateTimeFormatterBuilder() .append(dateElementParser()) .appendOptional(time) .toFormatter().withZoneUTC(); } return ldotp; }
private static DateTimeFormatter localDateOptionalTimeParser() { if (ldotp == null) { DateTimeParser time = new DateTimeFormatterBuilder() .appendLiteral('T') .append(timeElementParser()) .toParser(); return new DateTimeFormatterBuilder() .append(dateElementParser()) .appendOptional(time) .toFormatter().withZoneUTC(); } return ldotp; }
private static DateTimeFormatter[] createDateTimeFormats() { return new DateTimeFormatter[] { DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").withZoneUTC(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").withZoneUTC(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZ").withZoneUTC(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").withZoneUTC(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS").withZoneUTC(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS").withZoneUTC(), DateTimeFormat.forPattern("yyyy-MM-ddZ").withZoneUTC(), DateTimeFormat.forPattern("yyyy-MM-dd").withZoneUTC() }; }
private static DateTimeFormatter[] createDateFormats() { return new DateTimeFormatter[] { DateTimeFormat.forPattern("yyyy-MM-ddZ").withZoneUTC(), DateTimeFormat.forPattern("yyyy-MM-dd").withZoneUTC() }; }
private static final String DATE_STRING = DateTimeFormat.forPattern("yyyy-MM-dd").withZoneUTC().print(DATE_MILLIS_UTC); private static final Date SQL_DATE = new Date(UTC.getMillisKeepLocal(DateTimeZone.getDefault(), DATE_MILLIS_UTC));
private static DateTimeFormatter localDateParser() { if (ldp == null) { return dateElementParser().withZoneUTC(); } return ldp; }
private static DateTimeFormatter localTimeParser() { if (ltp == null) { return new DateTimeFormatterBuilder() .appendOptional(literalTElement().getParser()) .append(timeElementParser()) .toFormatter().withZoneUTC(); } return ltp; }