protected Integer getYear(List<YDate> dates) { for (YDate date : dates) { return date.getYear(); } return null; }
/** * Selects most appropriate (Publication's if available) data. */ protected static String selectBestDate(List<YDate> dates) { if (dates == null || dates.size() == 0) { return null; } int py = dates.get(0).getYear(); for (YDate date: dates) { //Search for English version if (date.getType().equals(YConstants.DT_PUBLISHED)) { py = date.getYear(); } } if (py > 1000) { return new Integer(py).toString(); } else { return null; } }
/** * Selects most apropriate (English if available) description. * * @param descriptions * list of available descriptions * @return best found description or null if list is empty */ protected static String selectBestDate(List<YDate> dates) { if (dates == null || dates.size() == 0) { return null; } StringBuilder text = new StringBuilder(); for (YDate date : dates) { text.append(date.getType() + ":"+date.getYear()+YElementToZentralBlattConverter.SUGGESTED_MULTIVALUE_FIELD_SEPARATOR); } return text.toString(); }
protected void convertDate(YElement yElement, BibEntry bibEntry) { YDate date = yElement.getDate(YConstants.DT_PUBLISHED); if (date != null) { if (bibEntry.getFirstFieldValue(BibEntry.FIELD_YEAR) == null) { bibEntry.setField(BibEntry.FIELD_YEAR, String.valueOf(date.getYear())); } bibEntry.setField(BibEntry.FIELD_MONTH, String.valueOf(date.getMonth())); date.getYear(); } }
protected void fillDates(YElement yElement, List<YExportable> referedElements, Map<String, List<StringWithAttributes>> ret) { // date element if (!yElement.getDates().isEmpty()) { ret.put(E_DATE, new ArrayList<StringWithAttributes>()); } for (YDate yDate : yElement.getDates()) { String yDateStr; String y = String.format("%02d", yDate.getYear()); String m = String.format("%02d", yDate.getMonth()); String d = String.format("%02d", yDate.getDay()); if (y != null && m != null && d != null) { yDateStr = y + "-" + m + "-" + d; } else if (y != null && m != null) { yDateStr = y + "-" + m; } else if (y != null) { yDateStr = y; } else { yDateStr = yDate.getText(); } StringWithAttributes dat = new StringWithAttributes(yDateStr); dat.addAttribute("dateType", yDate.getType()); ret.get(E_DATE).add(dat); // root.addContent(date); } }
@Override public BasicDBObject convert(YDate source) { if(source == null){ return null; } BasicDBObject object = new BasicDBObject(); object.put("year", source.getYear()); object.put("day", source.getDay()); object.put("month", source.getMonth()); object.put("type", source.getType()); object.put("text", source.getText()); DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); String dateString = String.format("%04d%02d%02d", getOneIfZero(source.getYear()), getOneIfZero(source.getMonth()), getOneIfZero(source.getDay())); try { Date parsedDate = dateFormat.parse(dateString); object.put("date", parsedDate); } catch (ParseException e) { LOGGER.warn("Couldn't parse date: " + dateString); } return object; }
private void addDateFromYElem(YDate publishedDate, CSLDateBuilder dateBuilder) { int year = publishedDate.getYear(); int month = publishedDate.getMonth(); int day = publishedDate.getDay(); boolean hasYear = year != 0; boolean hasMonth = month != 0; boolean hasDay = day != 0; if (hasYear && hasMonth && hasDay) { dateBuilder.dateParts(year, month, day); } else if (hasYear && hasMonth) { dateBuilder.dateParts(year, month); } else if(hasYear) { dateBuilder.dateParts(year); } }
private void addPublicationDate(CSLItemDataBuilder builder, ElementAncestors<YElement> elemAncest) { YDate publishedDate = elemAncest.getElement().getDate(YConstants.DT_PUBLISHED); CSLDateBuilder dateBuilder = new CSLDateBuilder(); if (publishedDate != null && (publishedDate.getYear() != 0)) { addDateFromYElem(publishedDate, dateBuilder); } else { addDateFromJournalYearAncest(elemAncest, dateBuilder); } builder.issued(dateBuilder.build()); }
public DateTime parseDate(final YDate yDate) throws InvalidDateException { DateTime parsedDate; try { parsedDate = new DateTime(yDate.getYear(), yDate.getMonth() > 0 ? yDate.getMonth() : 1, yDate.getDay() > 0 ? yDate.getDay() : 1, 0, 0, DateTimeZone.UTC); } catch (IllegalFieldValueException e) { throw new InvalidDateException("Incorrect values in YDates.", e); } if (yDate.getDay() == 0) { parsedDate = parsedDate.dayOfMonth().withMinimumValue(); } if (yDate.getMonth() == 0) { parsedDate = parsedDate.dayOfYear().withMinimumValue(); } return parsedDate; }
docMetadata.setYear(Integer.toString(yElement.getDate(YConstants.DT_PUBLISHED).getYear()));
docMetadata.setYear(Integer.toString(yElement.getDate(YConstants.DT_PUBLISHED).getYear()));