List of usage examples for org.joda.time.format DateTimeFormat forPattern
public static DateTimeFormatter forPattern(String pattern)
From source file:com.netflix.raigad.utils.SystemUtils.java
License:Apache License
public static String formatDate(DateTime dateTime, String dateFormat) { DateTimeFormatter fmt = DateTimeFormat.forPattern(dateFormat); return dateTime.toString(fmt); }
From source file:com.netflix.suro.input.JsonLog4jFormatter.java
License:Apache License
@Inject public JsonLog4jFormatter(ClientConfig config, ObjectMapper jsonMapper) { this.config = config; if (jsonMapper == null) this.jsonMapper = new DefaultObjectMapper(); else/*from w ww. ja v a 2 s. c om*/ this.jsonMapper = jsonMapper; fmt = DateTimeFormat.forPattern(config.getLog4jDateTimeFormat()); stringFormatter = new StringLog4jFormatter(config); Monitors.registerObject(this); }
From source file:com.netflix.suro.input.StringLog4jFormatter.java
License:Apache License
@Inject public StringLog4jFormatter(ClientConfig config) { this.config = config; fmt = DateTimeFormat.forPattern(config.getLog4jDateTimeFormat()); }
From source file:com.netflix.suro.sink.remotefile.formatter.DateRegionStackFormatter.java
License:Apache License
@JsonCreator public DateRegionStackFormatter(@JsonProperty("date") String dateFormat, @JsonProperty("region") @JacksonInject("region") String region, @JsonProperty("stack") @JacksonInject("stack") String stack) { this.format = DateTimeFormat.forPattern(dateFormat); this.region = region; this.stack = stack; }
From source file:com.nextdoor.bender.ipc.es.ElasticSearchTransportSerializer.java
License:Apache License
public ElasticSearchTransportSerializer(boolean useHashId, String documentType, String index, String indexTimeFormat, boolean usePartitionsForRouting, String routingFieldName) { this.useHashId = useHashId; this.index = index; this.documentType = documentType; this.usePartitionsForRouting = usePartitionsForRouting; this.routingFieldName = routingFieldName; if (indexTimeFormat != null) { this.dtFormat = DateTimeFormat.forPattern(indexTimeFormat).withZoneUTC(); } else {// w w w . ja v a 2 s.c om this.dtFormat = null; } }
From source file:com.nextdoor.bender.partition.PartitionSpec.java
License:Apache License
private void setDateTimeFormatter() { if (format != null && (this.interpreter == Interpreter.MILLISECONDS || this.interpreter == Interpreter.SECONDS)) { dateTimeFormatter = DateTimeFormat.forPattern(format).withZoneUTC(); } else {// ww w.j a v a 2 s.c o m dateTimeFormatter = null; } }
From source file:com.nextdoor.bender.S3SnsNotifier.java
License:Apache License
public static void main(String[] args) throws ParseException, InterruptedException, IOException { formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withZoneUTC(); /*// w w w.j av a2 s . c o m * Parse cli arguments */ Options options = new Options(); options.addOption(Option.builder().longOpt("bucket").hasArg().required() .desc("Name of S3 bucket to list s3 objects from").build()); options.addOption(Option.builder().longOpt("key-file").hasArg().required() .desc("Local file of S3 keys to process").build()); options.addOption( Option.builder().longOpt("sns-arn").hasArg().required().desc("SNS arn to publish to").build()); options.addOption(Option.builder().longOpt("throttle-ms").hasArg() .desc("Amount of ms to wait between publishing to SNS").build()); options.addOption(Option.builder().longOpt("processed-file").hasArg() .desc("Local file to use to store procssed S3 object names").build()); options.addOption(Option.builder().longOpt("skip-processed").hasArg(false) .desc("Whether to skip S3 objects that have been processed").build()); options.addOption( Option.builder().longOpt("dry-run").hasArg(false).desc("If set do not publish to SNS").build()); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); String bucket = cmd.getOptionValue("bucket"); String keyFile = cmd.getOptionValue("key-file"); String snsArn = cmd.getOptionValue("sns-arn"); String processedFile = cmd.getOptionValue("processed-file", null); boolean skipProcessed = cmd.hasOption("skip-processed"); dryRun = cmd.hasOption("dry-run"); long throttle = Long.parseLong(cmd.getOptionValue("throttle-ms", "-1")); if (processedFile != null) { File file = new File(processedFile); if (!file.exists()) { logger.debug("creating local file to store processed s3 object names: " + processedFile); file.createNewFile(); } } /* * Import S3 keys that have been processed */ if (skipProcessed && processedFile != null) { try (BufferedReader br = new BufferedReader(new FileReader(processedFile))) { String line; while ((line = br.readLine()) != null) { alreadyPublished.add(line.trim()); } } } /* * Setup writer for file containing processed S3 keys */ FileWriter fw = null; BufferedWriter bw = null; if (processedFile != null) { fw = new FileWriter(processedFile, true); bw = new BufferedWriter(fw); } /* * Create clients */ AmazonS3Client s3Client = new AmazonS3Client(); AmazonSNSClient snsClient = new AmazonSNSClient(); /* * Get S3 object list */ try (BufferedReader br = new BufferedReader(new FileReader(keyFile))) { String line; while ((line = br.readLine()) != null) { String key = line.trim(); if (alreadyPublished.contains(key)) { logger.info("skipping " + key); } ObjectMetadata om = s3Client.getObjectMetadata(bucket, key); S3EventNotification s3Notification = getS3Notification(key, bucket, om.getContentLength()); String json = s3Notification.toJson(); /* * Publish to SNS */ if (publish(snsArn, json, snsClient, key) && processedFile != null) { bw.write(key + "\n"); bw.flush(); } if (throttle != -1) { Thread.sleep(throttle); } } } if (processedFile != null) { bw.close(); fw.close(); } }
From source file:com.niroshpg.android.earthquakemonitor.Utility.java
License:Apache License
/** * Helper method to convert the database representation of the date into something to display * to users. As classy and polished a user experience as "20140102" is, we can do better. * * @param context Context to use for resource localization * @param dateStr The db formatted date string, expected to be of the form specified * in Utility.DATE_FORMAT * @return a user-friendly representation of the date. *//*from w w w . j a v a 2 s. c om*/ public static String getFriendlyDayString(Context context, String dateStr) { // The day string for earthquake events uses the following logic: // For today: "Today, June 8" // For tomorrow: "Tomorrow" // For the next 5 days: "Wednesday" (just the day name) // For all days after that: "Mon Jun 8" Date todayDate = new Date(); String todayStr = EarthQuakeDataContract.getDbDateString(todayDate); DateTime inputDateUTC = DateTimeFormat.forPattern(DATETIME_FORMAT).withZone(DateTimeZone.UTC) .parseDateTime(dateStr); // currentTimeZone.inDaylightTime() DateTime inputDateCurrentTZ = inputDateUTC .toDateTime(DateTimeZone.forOffsetMillis(currentTimeZone.getRawOffset())); // If the date we're building the String for is today's date, the format // is "Today, June 24" if (todayStr.equals(dateStr)) { String today = context.getString(R.string.today); int formatId = R.string.format_full_friendly_date; return String.format(context.getString(formatId, today, getFormattedMonthDay(context, dateStr))); } else { DateTimeFormatter shortenedDateTimeFormat = DateTimeFormat.forPattern("EEE MMM dd HH:mm:ss"); return inputDateCurrentTZ.toString(shortenedDateTimeFormat); // } } }
From source file:com.njlabs.amrita.aid.gpms.client.Gpms.java
License:Open Source License
public DateTimeFormatter getLongDateTimeFormatter() { return DateTimeFormat.forPattern(dateFormat); }
From source file:com.nkapps.billing.services.CustomJodaTimeSerializer.java
@Override public void serialize(LocalDateTime t, JsonGenerator gen, SerializerProvider arg2) throws IOException, JsonProcessingException { DateTimeFormatter dtf = DateTimeFormat.forPattern("dd.MM.yyyy HH:mm:ss"); String formattedDate = dtf.print(t); gen.writeString(formattedDate);// w w w. j a v a 2 s . c om }