public TikaPoweredMetadataExtracter(String extractorContext, HashSet<String> supportedMimeTypes, HashSet<String> supportedEmbedMimeTypes) { super(supportedMimeTypes, supportedEmbedMimeTypes); this.extractorContext = extractorContext; // TODO Once TIKA-451 is fixed this list will get nicer DateTimeParser[] parsersUTC = { DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").getParser(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").getParser() }; DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").getParser(), DateTimeFormat.forPattern("yyyy-MM-dd").getParser(), DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").getParser(), DateTimeFormat.forPattern("yyyy/MM/dd").getParser(), DateTimeFormat.forPattern("EEE MMM dd hh:mm:ss zzz yyyy").getParser() }; this.tikaUTCDateFormater = new DateTimeFormatterBuilder().append(null, parsersUTC).toFormatter().withZone(DateTimeZone.UTC); this.tikaDateFormater = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); }
public static DateTimeFormatter dateTime() { if (hl7 == null) { hl7 = new DateTimeFormatterBuilder() .appendYear(4, 4) .appendMonthOfYear(2) .appendDayOfMonth(2) .appendHourOfDay(2) .appendMinuteOfHour(2) .appendSecondOfMinute(2) .appendLiteral('.') .appendMillisOfSecond(3) .appendTimeZoneOffset(null, false, 2, 2) .toFormatter(); } return hl7; }
/** * creates instance with specific rounding. * * @param rounding * rounding */ public TimeConverter(Rounding rounding) { this.rounding = rounding; char separator = DecimalFormatSymbols.getInstance().getDecimalSeparator(); DateTimeFormatterBuilder parseBuilder = new DateTimeFormatterBuilder().appendHourOfDay(2).appendLiteral(':') .appendMinuteOfHour(2); parseBuilder.appendOptional(new DateTimeFormatterBuilder().appendLiteral(separator) .appendFractionOfMinute(0, 1).toParser()); this.parse = parseBuilder.toFormatter(); DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().appendHourOfDay(1).appendLiteral(':') .appendMinuteOfHour(2); DateTimeFormatterBuilder builderFull = new DateTimeFormatterBuilder().appendHourOfDay(2).appendLiteral(':') .appendMinuteOfHour(2); if (rounding != Rounding.MINUTE) { builder.appendLiteral(separator).appendFractionOfMinute(1, 1); builderFull.appendLiteral(separator).appendFractionOfMinute(1, 1); } this.print = builder.toFormatter(); this.printFull = builderFull.toFormatter(); this.duration = new DecimalFormat("###.#"); this.printXml = ISODateTimeFormat.hourMinuteSecond(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Crashlytics.start(this); EventBus.getDefault().register(this); connection = getConnection(); setContentView(R.layout.activity_main); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); ButterKnife.inject(this, this); DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); formatter = builder.appendHourOfDay(2).appendLiteral(':') .appendMinuteOfHour(2).appendLiteral(':') .appendSecondOfMinute(2).toFormatter(); textView.setMovementMethod(new ScrollingMovementMethod()); textView.setTypeface(Typeface.MONOSPACE); if (savedInstanceState == null) { Intent intent = new Intent(this, BackServiceImpl.class); startService(intent); } else { String logText = savedInstanceState.getString(LOG_EXTRA); textView.setText(logText); } }
@Override protected DateTimeFormatter initialValue() { return new DateTimeFormatterBuilder() .append(DateTimeFormat.forPattern("yyyy-MM-dd")) .appendOptional( new DateTimeFormatterBuilder() .appendLiteral('T') .appendOptional( new DateTimeFormatterBuilder() .append(DateTimeFormat.forPattern("HH")) .appendOptional( new DateTimeFormatterBuilder() .append(DateTimeFormat.forPattern(":mm")) .appendOptional( new DateTimeFormatterBuilder() .append(DateTimeFormat.forPattern(":ss")) .toParser()) .toParser()) .toParser()) .toParser()) .toFormatter(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { setData(getArguments()); } DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); mFormatter = builder .appendYear(4, 4).appendLiteral("-") .appendMonthOfYear(2).appendLiteral("-") .appendDayOfMonth(2).appendLiteral(" at ") .appendHourOfDay(2).appendLiteral(":") .appendMinuteOfHour(2) .toFormatter(); }
/** * * @return a formatter for common ISO strings */ private DateTimeFormatter buildDTFormatter() { //build a parser for time stamps return new DateTimeFormatterBuilder() .appendYear(4, 4) //4 digit year (YYYY) .appendLiteral("-") .appendMonthOfYear(2) //2 digit month (MM) .appendLiteral("-") .appendDayOfMonth(2) //2 digit day (DD) .appendLiteral("T") .appendHourOfDay(2) //2 digit hour (hh) .appendLiteral(":") .appendMinuteOfHour(2) //2 digit minute (mm) .appendLiteral(":") .appendSecondOfMinute(2)//2 digit second (ss) //optional 3 digit milliseconds of second .appendOptional(new DateTimeFormatterBuilder() .appendLiteral(".") .appendMillisOfSecond(3) .toParser()) //optional time zone offset as (+|-)hh:mm .appendOptional(new DateTimeFormatterBuilder() .appendTimeZoneOffset("", true, 2, 2) .toParser()) .toFormatter(); }
public String toUIString() { DateTimeFormatter DF = new DateTimeFormatterBuilder() .appendYear(4, 4) .appendLiteral('-') .appendMonthOfYear(1) .appendLiteral('-') .appendDayOfMonth(1) .appendLiteral(" ") .appendHourOfDay(2) .appendLiteral(':') .appendMinuteOfHour(2) .appendLiteral(':') .appendSecondOfMinute(2) .appendLiteral('.') .appendMillisOfSecond(1) .toFormatter(); return DF.print( toDateTime()); }
public String toUIString() { DateTimeFormatter DF = new DateTimeFormatterBuilder() .appendYear(4, 4) .appendLiteral('-') .appendMonthOfYear(1) .appendLiteral('-') .appendDayOfMonth(1) .appendLiteral(" ") .appendHourOfDay(2) .appendLiteral(':') .appendMinuteOfHour(2) .appendLiteral(':') .appendSecondOfMinute(2) .appendLiteral('.') .appendMillisOfSecond(1) .toFormatter(); final String start = DF.print( this.start.toDateTime()); final String end = DF.print( this.end.toDateTime()); return start+" - "+end+" [ "+getDurationInMilliseconds()+" ms ]"; }
public static FormatDateTimeFormatter getStrictStandardDateFormatter() { // 2014/10/10 DateTimeFormatter shortFormatter = new DateTimeFormatterBuilder() .appendFixedDecimal(DateTimeFieldType.year(), 4) .appendLiteral('/') .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2) .appendLiteral('/') .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2) .toFormatter() .withZoneUTC(); // 2014/10/10 12:12:12 DateTimeFormatter longFormatter = new DateTimeFormatterBuilder() .appendFixedDecimal(DateTimeFieldType.year(), 4) .appendLiteral('/') .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2) .appendLiteral('/') .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2) .appendLiteral(' ') .appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2) .appendLiteral(':') .appendFixedSignedDecimal(DateTimeFieldType.minuteOfHour(), 2) .appendLiteral(':') .appendFixedSignedDecimal(DateTimeFieldType.secondOfMinute(), 2) .toFormatter() .withZoneUTC(); DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[]{longFormatter.getParser(), shortFormatter.getParser(), new EpochTimeParser(true)}); return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT); }
public void testMultiParsers() { DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); DateTimeParser[] parsers = new DateTimeParser[3]; parsers[0] = DateTimeFormat.forPattern("MM/dd/yyyy").withZone(DateTimeZone.UTC).getParser(); parsers[1] = DateTimeFormat.forPattern("MM-dd-yyyy").withZone(DateTimeZone.UTC).getParser(); parsers[2] = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZone(DateTimeZone.UTC).getParser(); builder.append(DateTimeFormat.forPattern("MM/dd/yyyy").withZone(DateTimeZone.UTC).getPrinter(), parsers); DateTimeFormatter formatter = builder.toFormatter(); formatter.parseMillis("2009-11-15 14:12:12"); }
public static DateTimeFormatter getDateTimeFormatter() { if (dateTimeTZFormat == null) { DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); DateTimeParser optionalTime = DateTimeFormat.forPattern(" HH:mm:ss").getParser(); DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser(); DateTimeParser optionalZone = DateTimeFormat.forPattern(" ZZZ").getParser(); dateTimeTZFormat = new DateTimeFormatterBuilder().append(dateFormatter).appendOptional(optionalTime).appendOptional(optionalSec).appendOptional(optionalZone).toFormatter(); } return dateTimeTZFormat; }
public static DateTimeFormatter getTimeFormatter() { if (timeFormat == null) { DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HH:mm:ss"); DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser(); timeFormat = new DateTimeFormatterBuilder().append(timeFormatter).appendOptional(optionalSec).toFormatter(); } return timeFormat; }
/** * * @param finishDate * @return * @throws Exception */ public static final DateTime validateInputDate(final String date, final String permittedDateFormats) throws Exception { logger.debug("----Inside validateInputDate, date: " + date + " & permittedDateFormats: " + permittedDateFormats); /* Seperate all the formats */ final String[] defaultDateFormats = permittedDateFormats.split(","); /* Create array for all date parsing formats */ final DateTimeParser[] dateTimeParser = new DateTimeParser[defaultDateFormats.length]; /* Parse with individual formats */ for (int i = 0; i < defaultDateFormats.length; i++) { /* If format is valid */ if (defaultDateFormats[i] != null && !"".equals(defaultDateFormats[i])) { /* Create new parser for each format */ dateTimeParser[i] = DateTimeFormat.forPattern(defaultDateFormats[i].trim()).getParser(); } } /* Final date formater builder */ final DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().append(null, dateTimeParser).toFormatter(); /* Parse user supplied date */ final DateTime updatedDate = dateTimeFormatter.parseDateTime(date); logger.debug("----Inside validateInputDate, updated date: " + updatedDate); /* Return updated date */ return updatedDate; }
/** * Gets a printer/parser for managing the offset id formatting. * * @return the formatter */ private static synchronized DateTimeFormatter offsetFormatter() { if (cOffsetFormatter == null) { cOffsetFormatter = new DateTimeFormatterBuilder() .appendTimeZoneOffset(null, true, 2, 4) .toFormatter(); } return cOffsetFormatter; }
static String getLocalAMString(DateTime now) { //we need an AM date DateTime dt = now.withTimeAtStartOfDay(); Locale locale= new ResourceLoader("calendar").getLocale(); DateTimeFormatter df = new DateTimeFormatterBuilder().appendHalfdayOfDayText().toFormatter().withLocale(locale); return df.print(dt); }
static String getLocalPMString(DateTime now) { //we need an PM date DateTime dt = now.withTimeAtStartOfDay().plusHours(14); Locale locale = new ResourceLoader("calendar").getLocale(); DateTimeFormatter df = new DateTimeFormatterBuilder().appendHalfdayOfDayText().toFormatter().withLocale(locale); return df.print(dt); }
public static String listTimezones() { DateTimeFormatter offsetFormatter = new DateTimeFormatterBuilder().appendTimeZoneOffset(null, true, 2, 4).toFormatter(); Set<String> idSet = DateTimeZone.getAvailableIDs(); Map<String, String> tzMap = new TreeMap(); Iterator<String> it = idSet.iterator(); String id, cid, offset, key, output; DateTimeZone tz; int i = 0; long millis = System.currentTimeMillis(); // collect canonical and alias IDs into a map while (it.hasNext()) { id = it.next(); tz = DateTimeZone.forID(id); cid = tz.getID(); offset = offsetFormatter.withZone(tz).print(tz.getStandardOffset(millis)); key = offset + " " + cid; if (id == cid) { // Canonical ID if (!tzMap.containsKey(key)) tzMap.put(key, ""); } else {// alias ID if (!tzMap.containsKey(key)) tzMap.put(key, ""); tzMap.put(key, tzMap.get(key) + ", " + id); } } // assemble result output = "StandardOffset CanonicalID, Aliases\n"; for (Map.Entry<String, String> e : tzMap.entrySet()) output += e.getKey() + e.getValue()+"\n"; return output; }
public static PointInTimeFormatter pointInTimeParser() { if (ptp == null) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendYear(4, 4) .appendOptional(twoDigitNumber(DateTimeFieldType.monthOfYear())) .appendOptional(twoDigitNumber(DateTimeFieldType.dayOfMonth())) .appendOptional(twoDigitNumber(DateTimeFieldType.hourOfDay())) .appendOptional(twoDigitNumber(DateTimeFieldType.minuteOfHour())) .appendOptional(twoDigitNumber(DateTimeFieldType.secondOfMinute())) .appendOptional(dotMilliseconds()) .toFormatter(); ptp = new PointInTimeFormatter(f.getPrinter(), f.getParser()); } return ptp; }
public static DateTimeFormatter date() { if (d == null) { d = new DateTimeFormatterBuilder() .append(year()) .append(monthOfYear()) .append(dayOfMonth()) .toFormatter(); } return d; }
public static PointInTimeFormatter pointInTimeParser() { if (ptp == null) { DateTimeFormatter f = new DateTimeFormatterBuilder() .append(date()) .toFormatter(); ptp = new PointInTimeFormatter(f.getPrinter(), f.getParser()); } return ptp; }
public static DateTimeFormatter dateTime() { if (dt == null) { dt = new DateTimeFormatterBuilder() .appendPattern("dd MMM yyyy hh:mm:ss") // .appendLiteral(' ') // .appendTimeZoneOffset("", false, 2, 2) .toFormatter(); } return dt; }
private static List<String> getMatchingPathes(String path, String[] pathStream, ArrayList<String> arrayList, FTPClient fc, DateTime lastReadout, DateTimeFormatterBuilder dtfbuilder) { int nextTokenPos = getPathTokens(path).length; if (nextTokenPos == pathStream.length - 1) { arrayList.add(path); return arrayList; } String nextToken = pathStream[nextTokenPos]; String nextFolder = null; try { if (containsDateToken(nextToken)) { FTPFile[] listDirectories = fc.listFiles(path); // DateTimeFormatter ftmTemp = getDateFormatter(nextToken); for (FTPFile folder : listDirectories) { if (!matchDateString(folder.getName(), nextToken)) { continue; } // System.out.println("listdir," + folder.getName()); // if (containsDate(folder.getName(), ftmTemp)) { DateTime folderTime = getFolderTime(path + folder.getName() + "/", pathStream); if (folderTime.isAfter(lastReadout)) { nextFolder = folder.getName(); // System.out.println("dateFolder," + nextFolder); getMatchingPathes(path + nextFolder + "/", pathStream, arrayList, fc, lastReadout, dtfbuilder); } // } } } else { nextFolder = nextToken; // System.out.println("normalFolder," + nextFolder); getMatchingPathes(path + nextFolder + "/", pathStream, arrayList, fc, lastReadout, dtfbuilder); } } catch (IOException ex) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, ex.getMessage()); } return arrayList; }
private static List<String> getSFTPMatchingPathes(String path, String[] pathStream, ArrayList<String> arrayList, ChannelSftp fc, DateTime lastReadout, DateTimeFormatterBuilder dtfbuilder) { int nextTokenPos = getPathTokens(path).length; if (nextTokenPos == pathStream.length - 1) { arrayList.add(path); return arrayList; } String nextToken = pathStream[nextTokenPos]; String nextFolder = null; try { if (containsDateToken(nextToken)) { Vector listDirectories = fc.ls(path); for (Object folder : listDirectories) { LsEntry currentFolder = (LsEntry) folder; if (!matchDateString(currentFolder.getFilename(), nextToken)) { continue; } DateTime folderTime = getFolderTime(path + currentFolder.getFilename() + "/", pathStream); if (folderTime.isAfter(lastReadout)) { nextFolder = currentFolder.getFilename(); getSFTPMatchingPathes(path + nextFolder + "/", pathStream, arrayList, fc, lastReadout, dtfbuilder); } // } } } else { nextFolder = nextToken; getSFTPMatchingPathes(path + nextFolder + "/", pathStream, arrayList, fc, lastReadout, dtfbuilder); } } catch (SftpException ex) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Cant find suitable files on the device"); } return arrayList; }
public static String hhMMAMPM(Date date) { org.joda.time.format.DateTimeFormatter formatter = new DateTimeFormatterBuilder() .appendClockhourOfHalfday(1).appendLiteral(":") .appendMinuteOfHour(2).appendLiteral(" ") .appendHalfdayOfDayText().toFormatter(); if (date != null) { return formatter.print(date.getTime()); } else { return ""; } }
public static String onlyDate(Date date) { org.joda.time.format.DateTimeFormatter formatter = new DateTimeFormatterBuilder() .appendDayOfMonth(2).appendLiteral("/").appendMonthOfYear(2) .appendLiteral("/").appendYear(2, 4).toFormatter(); return formatter.print(date.getTime()); }
public static String literalDate(Date date) { DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder() .appendDayOfWeekShortText().appendLiteral(" ") .appendDayOfMonth(1).appendLiteral(". ") .appendMonthOfYearShortText(); if (date.getYear() != new Date().getYear()) { builder.appendLiteral(" ").appendYear(2, 4); } org.joda.time.format.DateTimeFormatter formatter = builder .toFormatter(); return formatter.print(date.getTime()); }
public static String hhMM(Date date) { org.joda.time.format.DateTimeFormatter formatter = new DateTimeFormatterBuilder() .appendClockhourOfHalfday(2).appendLiteral(":") .appendMinuteOfHour(2).appendLiteral(" ").toFormatter(); return formatter.print(date.getTime()); }
public static String getPeriodTitle(Context context, int type, long start, long end) { final String result; switch (type) { case TYPE_DAY: result = DateUtils.formatDateTime(context, start, 0); break; case TYPE_WEEK: result = DateUtils.formatDateRange(context, start, end, 0); break; case TYPE_MONTH: final DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); builder.appendMonthOfYearText(); if (new DateTime(System.currentTimeMillis()).year().get() != new DateTime(start).year().get()) builder.appendLiteral(' ').appendYear(4, 4); result = builder.toFormatter().print(start); break; case TYPE_YEAR: final Calendar c = Calendar.getInstance(); c.setTimeInMillis(start); result = String.valueOf(c.get(Calendar.YEAR)); break; default: result = "?"; break; } return result; }
public void start() { int errorCount = 0; final String facilityStr = getFirstOption(); if (facilityStr == null) { addError("was expecting a facility string as an option"); return; } facility = SyslogAppenderBase.facilityStringToint(facilityStr); localHostName = getLocalHostname(); try { isoFormatter = new DateTimeFormatterBuilder() .appendPattern("yyyy-MM-dd'T'HH:mm:ss.SSS") .appendTimeZoneOffset("Z", true, 2, 4) .toFormatter(); } catch (Exception e) { addError("Could not instantiate Joda DateTimeFormatter", e); errorCount++; } if (errorCount == 0) { super.start(); } }