/** * Returns a ISO 8601 representation of the given date, which is * in an unknown timezone. This method is thread safe and non-blocking. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-495">TIKA-495</a> * @param date given date * @return ISO 8601 date string, without timezone details */ public static String formatDateUnknownTimezone(Date date) { // Create the Calendar object in the system timezone Calendar calendar = GregorianCalendar.getInstance(TimeZone.getDefault(), Locale.US); calendar.setTime(date); // Have it formatted String formatted = formatDate(calendar); // Strip the timezone details before returning return formatted.substring(0, formatted.length()-1); } private static String doFormatDate(Calendar calendar) {
/** * Parses the given date string. This method is synchronized to prevent * concurrent access to the thread-unsafe date formats. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-495">TIKA-495</a> * @param date date string * @return parsed date, or <code>null</code> if the date can't be parsed */ private static synchronized Date parseDate(String date) { return DATE_UTILS.tryToParse(date); }
private List<DateFormat> loadDateFormats() { List<DateFormat> dateFormats = new ArrayList<>(); // yyyy-mm-ddThh... dateFormats.add(createDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", UTC)); // UTC/Zulu dateFormats.add(createDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", null)); // With timezone dateFormats.add(createDateFormat("yyyy-MM-dd'T'HH:mm:ss", null)); // Without timezone // yyyy-mm-dd hh... dateFormats.add(createDateFormat("yyyy-MM-dd' 'HH:mm:ss'Z'", UTC)); // UTC/Zulu dateFormats.add(createDateFormat("yyyy-MM-dd' 'HH:mm:ssZ", null)); // With timezone dateFormats.add(createDateFormat("yyyy-MM-dd' 'HH:mm:ss", null)); // Without timezone // Date without time, set to Midday UTC dateFormats.add(createDateFormat("yyyy-MM-dd", MIDDAY)); // Normal date format dateFormats.add(createDateFormat("yyyy:MM:dd", MIDDAY)); // Image (IPTC/EXIF) format return dateFormats; }
/** * Returns a ISO 8601 representation of the given date. This method * is thread safe and non-blocking. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-495">TIKA-495</a> * @param date given date * @return ISO 8601 date string, including timezone details */ public static String formatDate(Calendar date) { // Explicitly switch it into UTC before formatting date.setTimeZone(UTC); return doFormatDate(date); } /**
/** * Some documents, like jpegs, might have date in unspecified time zone * which should be handled like strings but verified to have parseable ISO 8601 format */ @Test public void testGetSetDateUnspecifiedTimezone() { Metadata meta = new Metadata(); // Set explictly without a timezone meta.set(TikaCoreProperties.CREATED, "1970-01-01T00:00:01"); assertEquals("should return string without time zone specifier because zone is not known", "1970-01-01T00:00:01", meta.get(TikaCoreProperties.CREATED)); // Now ask DateUtils to format for us without one meta.set(TikaCoreProperties.CREATED, DateUtils.formatDateUnknownTimezone(new Date(1000))); assertEquals("should return string without time zone specifier because zone is not known", "1970-01-01T00:00:01", meta.get(TikaCoreProperties.CREATED)); }
/** * Returns a ISO 8601 representation of the given date. This method * is thread safe and non-blocking. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-495">TIKA-495</a> * @param date given date * @return ISO 8601 date string, including timezone details */ public static String formatDate(Date date) { Calendar calendar = GregorianCalendar.getInstance(UTC, Locale.US); calendar.setTime(date); return doFormatDate(calendar); } /**
private void getMetaDataDateInfo(Metadata metadata, DefaultMetadata defaultMetaData){ ArrayList<CitationDate> citationDateList= (ArrayList<CitationDate>) defaultMetaData.getDateInfo(); for(CitationDate c:citationDateList){ if(c.getDateType()!=null) { String date = DateUtils.formatDate(c.getDate()); metadata.add("DateInfo ",c.getDateType().name()+" "+date); } } }
private void startEditedSection(EditType editType, Attributes atts) { String editAuthor = atts.getValue(W_NS, "author"); String editDateString = atts.getValue(W_NS, "date"); Date editDate = null; if (editDateString != null) { editDate = dateUtils.tryToParse(editDateString); } bodyContentsHandler.startEditedSection(editAuthor, editDate, editType); this.editType = editType; }
/** * Returns a ISO 8601 representation of the given date. This method * is thread safe and non-blocking. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-495">TIKA-495</a> * @param date given date * @return ISO 8601 date string, including timezone details */ public static String formatDate(Calendar date) { // Explicitly switch it into UTC before formatting date.setTimeZone(UTC); return doFormatDate(date); } /**
private List<DateFormat> loadDateFormats() { List<DateFormat> dateFormats = new ArrayList<>(); // yyyy-mm-ddThh... dateFormats.add(createDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", UTC)); // UTC/Zulu dateFormats.add(createDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", null)); // With timezone dateFormats.add(createDateFormat("yyyy-MM-dd'T'HH:mm:ss", null)); // Without timezone // yyyy-mm-dd hh... dateFormats.add(createDateFormat("yyyy-MM-dd' 'HH:mm:ss'Z'", UTC)); // UTC/Zulu dateFormats.add(createDateFormat("yyyy-MM-dd' 'HH:mm:ssZ", null)); // With timezone dateFormats.add(createDateFormat("yyyy-MM-dd' 'HH:mm:ss", null)); // Without timezone // Date without time, set to Midday UTC dateFormats.add(createDateFormat("yyyy-MM-dd", MIDDAY)); // Normal date format dateFormats.add(createDateFormat("yyyy:MM:dd", MIDDAY)); // Image (IPTC/EXIF) format return dateFormats; }
/** * Sets the date value of the identified metadata property. * * @since Apache Tika 0.8 * @param property simple integer property definition * @param date property value */ public void set(Property property, Date date) { if(property.getPrimaryProperty().getPropertyType() != Property.PropertyType.SIMPLE) { throw new PropertyTypeException(Property.PropertyType.SIMPLE, property.getPrimaryProperty().getPropertyType()); } if(property.getPrimaryProperty().getValueType() != Property.ValueType.DATE) { throw new PropertyTypeException(Property.ValueType.DATE, property.getPrimaryProperty().getValueType()); } String dateString = null; if (date != null) { dateString = formatDate(date); } set(property, dateString); }
/** * Parses the given date string. This method is synchronized to prevent * concurrent access to the thread-unsafe date formats. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-495">TIKA-495</a> * @param date date string * @return parsed date, or <code>null</code> if the date can't be parsed */ private static synchronized Date parseDate(String date) { return DATE_UTILS.tryToParse(date); }
/** * Returns a ISO 8601 representation of the given date. This method * is thread safe and non-blocking. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-495">TIKA-495</a> * @param date given date * @return ISO 8601 date string, including timezone details */ public static String formatDate(Calendar date) { // Explicitly switch it into UTC before formatting date.setTimeZone(UTC); return doFormatDate(date); } /**
private List<DateFormat> loadDateFormats() { List<DateFormat> dateFormats = new ArrayList<>(); // yyyy-mm-ddThh... dateFormats.add(createDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", UTC)); // UTC/Zulu dateFormats.add(createDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", null)); // With timezone dateFormats.add(createDateFormat("yyyy-MM-dd'T'HH:mm:ss", null)); // Without timezone // yyyy-mm-dd hh... dateFormats.add(createDateFormat("yyyy-MM-dd' 'HH:mm:ss'Z'", UTC)); // UTC/Zulu dateFormats.add(createDateFormat("yyyy-MM-dd' 'HH:mm:ssZ", null)); // With timezone dateFormats.add(createDateFormat("yyyy-MM-dd' 'HH:mm:ss", null)); // Without timezone // Date without time, set to Midday UTC dateFormats.add(createDateFormat("yyyy-MM-dd", MIDDAY)); // Normal date format dateFormats.add(createDateFormat("yyyy:MM:dd", MIDDAY)); // Image (IPTC/EXIF) format return dateFormats; }
/** * Sets the date value of the identified metadata property. * * @since Apache Tika 0.8 * @param property simple integer property definition * @param date property value */ public void set(Property property, Calendar date) { if(property.getPrimaryProperty().getPropertyType() != Property.PropertyType.SIMPLE) { throw new PropertyTypeException(Property.PropertyType.SIMPLE, property.getPrimaryProperty().getPropertyType()); } if(property.getPrimaryProperty().getValueType() != Property.ValueType.DATE) { throw new PropertyTypeException(Property.ValueType.DATE, property.getPrimaryProperty().getValueType()); } String dateString = null; if (date != null) { dateString = formatDate(date); } set(property, dateString); }
/** * Parses the given date string. This method is synchronized to prevent * concurrent access to the thread-unsafe date formats. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-495">TIKA-495</a> * @param date date string * @return parsed date, or <code>null</code> if the date can't be parsed */ private static synchronized Date parseDate(String date) { return DATE_UTILS.tryToParse(date); }
/** * Returns a ISO 8601 representation of the given date. This method * is thread safe and non-blocking. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-495">TIKA-495</a> * @param date given date * @return ISO 8601 date string, including timezone details */ public static String formatDate(Date date) { Calendar calendar = GregorianCalendar.getInstance(UTC, Locale.US); calendar.setTime(date); return doFormatDate(calendar); } /**
String dateString = (when == null) ? "" : DateUtils.formatDate(when); softwareAgent = (softwareAgent == null) ? "" : softwareAgent;
private void startEditedSection(EditType editType, Attributes atts) { String editAuthor = atts.getValue(W_NS, "author"); String editDateString = atts.getValue(W_NS, "date"); Date editDate = null; if (editDateString != null) { editDate = dateUtils.tryToParse(editDateString); } bodyContentsHandler.startEditedSection(editAuthor, editDate, editType); this.editType = editType; }
/** * Returns a ISO 8601 representation of the given date. This method * is thread safe and non-blocking. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-495">TIKA-495</a> * @param date given date * @return ISO 8601 date string, including timezone details */ public static String formatDate(Date date) { Calendar calendar = GregorianCalendar.getInstance(UTC, Locale.US); calendar.setTime(date); return doFormatDate(calendar); } /**