Refine search
/** * Returns the current time in yyMMdd-hhmmss format. */ public static String yyMMdd_hhmmss() { return DateTimeFormat.forPattern("yyMMdd-hhmmss").print(new DateTime()); } }
@Override public String toString() { return "Version " + this.version.toString(DateTimeFormat.shortDateTime()) + " at path " + this.path; }
/** * Calls upon {@link DateTimeFormat} to parse the pattern and append the * results into this builder. * * @param pattern pattern specification * @throws IllegalArgumentException if the pattern is invalid * @see DateTimeFormat */ public DateTimeFormatterBuilder appendPattern(String pattern) { DateTimeFormat.appendPatternTo(this, pattern); return this; }
private DateTimeFormatter getFallbackFormatter(Type type) { switch (type) { case DATE: return DateTimeFormat.shortDate(); case TIME: return DateTimeFormat.shortTime(); default: return DateTimeFormat.shortDateTime(); } }
DateTimeFormatter dateTimeFormatter = null; if (StringUtils.hasLength(this.pattern)) { dateTimeFormatter = DateTimeFormat.forPattern(this.pattern); dateTimeFormatter = DateTimeFormat.forStyle(this.style); dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
public Builder timeFormatter(String formatOrConstant) { if (formatOrConstant == null || formatOrConstant.equalsIgnoreCase("NONE") || formatOrConstant.equalsIgnoreCase("FALSE")) { timeFormatter = null; } else if (formatOrConstant.length() == 0 || formatOrConstant.equalsIgnoreCase("DEFAULT")) { timeFormatter = DateTimeFormat.forPattern("HH:mm:ss.SSS"); } else if (formatOrConstant.equalsIgnoreCase("ISO8601")) { timeFormatter = ISODateTimeFormat.dateTime(); } else if (formatOrConstant.equalsIgnoreCase("SHORT")) { timeFormatter = DateTimeFormat.shortDateTime(); } else if (formatOrConstant.equalsIgnoreCase("MEDIUM")) { timeFormatter = DateTimeFormat.mediumDateTime(); } else if (formatOrConstant.equalsIgnoreCase("LONG")) { timeFormatter = DateTimeFormat.longDateTime(); } else { try { timeFormatter = DateTimeFormat.forPattern(formatOrConstant); } catch (IllegalArgumentException exp) { throw new IllegalArgumentException( "Cannot parse log date specification '" + formatOrConstant + "'." + "Must be either DEFAULT, NONE, ISO8601, SHORT, MEDIUM, LONG or a " + "format string parseable by DateTimeFormat. See " + "http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html"); } } return this; }
/** * Output the date using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern) { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).print(this); }
private DateTime getTime (String timeString) { DateTimeZone timeZone = DateTimeZone.forID(MRCompactor.DEFAULT_COMPACTION_TIMEZONE); int splits = StringUtils.countMatches(timeString, "/"); String timePattern = ""; if (splits == 3) { timePattern = "YYYY/MM/dd/HH"; } else if (splits == 2) { timePattern = "YYYY/MM/dd"; } DateTimeFormatter timeFormatter = DateTimeFormat.forPattern(timePattern).withZone(timeZone); return timeFormatter.parseDateTime (timeString); }
DateTimeFormatter event_fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); DateTime dt = new DateTime(zone); // timestamp to put on events event_fmt.print(dt), i, 0, i ); LOG.info("sending event: [%s]", event); dt = new DateTime(zone); queryStr = StringUtils.replace(queryStr, "%%DATASOURCE%%", fullDatasourceName); queryStr = StringUtils.replace(queryStr, "%%TIMEBOUNDARY_RESPONSE_TIMESTAMP%%", TIMESTAMP_FMT.print(dtFirst)); queryStr = StringUtils.replace(queryStr, "%%TIMEBOUNDARY_RESPONSE_MAXTIME%%", TIMESTAMP_FMT.print(dtLast)); queryStr = StringUtils.replace(queryStr, "%%TIMEBOUNDARY_RESPONSE_MINTIME%%", TIMESTAMP_FMT.print(dtFirst)); queryStr = StringUtils.replace(queryStr, "%%TIMESERIES_QUERY_START%%", INTERVAL_FMT.print(dtFirst)); String queryEnd = INTERVAL_FMT.print(dtFirst.plusMinutes(MINUTES_TO_SEND + 2)); queryStr = StringUtils.replace(queryStr, "%%TIMESERIES_QUERY_END%%", queryEnd); queryStr = StringUtils.replace(queryStr, "%%TIMESERIES_RESPONSE_TIMESTAMP%%", TIMESTAMP_FMT.print(dtFirst));
private static final long DATE_MILLIS_UTC = new DateTime(2011, 5, 6, 0, 0, UTC).getMillis(); private static final long DATE_DAYS = TimeUnit.MILLISECONDS.toDays(DATE_MILLIS_UTC); 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 final long TIMESTAMP = new DateTime(2011, 5, 6, 7, 8, 9, 123).getMillis(); private static final String TIMESTAMP_STRING = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS").print(TIMESTAMP);
formatter = defaultFormatter; } else { formatter = DateTimeFormat.forPattern(format); DateTimeZone offsetTime = DateTimeZone.forID(text); return (T) DateTimeFormat.forPattern(text); return (T) new DateTime(millis, DateTimeZone.forTimeZone(timeZone)); LocalDateTime localDateTime = new LocalDateTime(millis, DateTimeZone.forTimeZone(timeZone)); if (type == LocalDateTime.class) { return (T) localDateTime;
private void insertDailyPartition(Path dailyPartitionPath) throws Exception { String datasetPath = StringUtils.substringBeforeLast(dailyPartitionPath.toString(), Path.SEPARATOR + "daily"); DateTime partition = DateTimeFormat.forPattern(DAILY_PARTITION_PATTERN).parseDateTime( StringUtils.substringAfter(dailyPartitionPath.toString(), "daily" + Path.SEPARATOR)); PreparedStatement insert = connection.prepareStatement("INSERT INTO Daily_Partitions VALUES (?, ?, ?)"); insert.setString(1, datasetPath); insert.setString(2, dailyPartitionPath.toString()); insert.setTimestamp(3, new Timestamp(partition.getMillis())); insert.executeUpdate(); }
DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss") .withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("PST"))); new DateTime(record.get("LastModifiedDate")).toString(format)); Assert.assertEquals(jsonRecord.get("date_type").getAsString(), new DateTime(record.get("date_type")).toString(format)); format = DateTimeFormat.forPattern("HH:mm:ss").withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("PST"))); Assert.assertEquals(jsonRecord.get("time_type").getAsString(), new DateTime(record.get("time_type")).toString(format));
/** * Output the date using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @param locale Locale to use, null means default * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern, Locale locale) throws IllegalArgumentException { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); }
/** * Returns today's date formatted as "YYYY-MM-DD". */ public static String getTodayForHighlights() { DateTime dateTime = new DateTime(DateTimeZone.forTimeZone( TimeZone.getTimeZone("America/New_York"))); return DateTimeFormat.forPattern("yyyy-MM-dd").print(dateTime); }
List<GoogleWebmasterDataFetcher.Metric> requestedMetrics, JsonArray schemaJson, List<GoogleWebmasterDataFetcher> dataFetchers) { DateTimeFormatter watermarkFormatter = DateTimeFormat.forPattern("yyyyMMddHHmmss"); _startDate = watermarkFormatter.parseDateTime(Long.toString(lowWatermark)); _expectedHighWaterMark = expectedHighWaterMark; _expectedHighWaterMarkDate = watermarkFormatter.parseDateTime(Long.toString(expectedHighWaterMark)); log.info(String.format("Creating GoogleWebmasterExtractor for [%s, %s] for job %s.", _startDate.toString(), _expectedHighWaterMarkDate.toString(), wuState.getProp(ConfigurationKeys.SOURCE_ENTITY))); String startDate = dateFormatter.print(_startDate); String endDate = dateFormatter.print(_expectedHighWaterMarkDate); GoogleWebmasterExtractorIterator iterator =
this.googleAnalyticsFormatter = DateTimeFormat.forPattern(DATE_FORMAT) .withZone(DateTimeZone.forID(wuState.getProp(SOURCE_TIMEZONE, DEFAULT_SOURCE_TIMEZONE))); this.watermarkFormatter = DateTimeFormat.forPattern(WATERMARK_INPUTFORMAT) .withZone(DateTimeZone.forID(wuState.getProp(SOURCE_TIMEZONE, DEFAULT_SOURCE_TIMEZONE))); DateTime nextWatermarkDateTime = googleAnalyticsFormatter.parseDateTime(createdReport.getEndDate()).plusDays(1); nextWatermark = Long.parseLong(watermarkFormatter.print(nextWatermarkDateTime));
@Test public void dateToStringWithFormat() { JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar(); registrar.setDateTimeFormatter(org.joda.time.format.DateTimeFormat.shortDateTime()); setup(registrar); Date date = new Date(); Object actual = this.conversionService.convert(date, TypeDescriptor.valueOf(Date.class), TypeDescriptor.valueOf(String.class)); String expected = JodaTimeContextHolder.getFormatter(org.joda.time.format.DateTimeFormat.shortDateTime(), Locale.US).print(new DateTime(date)); assertEquals(expected, actual); }
@Test public void testWorksNoPrefix() throws IOException, DataRecordException { DatePartitionedAvroFileSource source = new DatePartitionedAvroFileSource(); SourceState state = new SourceState(); state.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, ConfigurationKeys.LOCAL_FS_URI); state.setProp(ConfigurationKeys.EXTRACT_NAMESPACE_NAME_KEY, SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY, OUTPUT_DIR + Path.SEPARATOR + SOURCE_ENTITY + Path.SEPARATOR + PREFIX); state.setProp(ConfigurationKeys.SOURCE_ENTITY, SOURCE_ENTITY); state.setProp(ConfigurationKeys.SOURCE_MAX_NUMBER_OF_PARTITIONS, 2); state.setProp("date.partitioned.source.partition.pattern", DATE_PATTERN); state.setProp("date.partitioned.source.min.watermark.value", DateTimeFormat.forPattern(DATE_PATTERN).print( this.startDateTime.minusMinutes(1))); state.setProp(ConfigurationKeys.EXTRACT_TABLE_TYPE_KEY, TableType.SNAPSHOT_ONLY); state.setProp("date.partitioned.source.partition.suffix", SUFFIX); //Read data partitioned by minutes, i.e each workunit is assigned records under the same YYYY/MM/dd/HH_mm directory List<WorkUnit> workunits = source.getWorkunits(state); Assert.assertEquals(workunits.size(), 4); verifyWorkUnits(workunits); }
public static Date strToDate(String dateTimeStr){ DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(STANDARD_FORMAT); DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr); return dateTime.toDate(); }