use of org.mycore.common.MCRCalendar in project mycore by MyCoRe-Org.
the class MCRXMLFunctions method getISODateFromMCRHistoryDate.
/**
* The method get a date String in format yyyy-MM-ddThh:mm:ssZ for ancient date values.
*
* @param date_value the date string
* @param field_name the name of field of MCRMetaHistoryDate, it should be 'von' or 'bis'
* @param calendar_name the name if the calendar defined in MCRCalendar
* @return the date in format yyyy-MM-ddThh:mm:ssZ
*/
public static String getISODateFromMCRHistoryDate(String date_value, String field_name, String calendar_name) throws ParseException {
String formatted_date;
if (field_name == null || field_name.trim().length() == 0) {
return "";
}
boolean use_last_value = false;
if ("bis".equals(field_name)) {
use_last_value = true;
}
try {
Calendar calendar = MCRCalendar.getHistoryDateAsCalendar(date_value, use_last_value, calendar_name);
GregorianCalendar g_calendar = MCRCalendar.getGregorianCalendarOfACalendar(calendar);
formatted_date = MCRCalendar.getCalendarDateToFormattedString(g_calendar, "yyyy-MM-dd") + "T00:00:00.000Z";
if (g_calendar.get(GregorianCalendar.ERA) == GregorianCalendar.BC) {
formatted_date = "-" + formatted_date;
}
} catch (Exception e) {
String errorMsg = "Error while converting date string : " + date_value + " - " + use_last_value + " - " + calendar_name;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(errorMsg, e);
}
LOGGER.warn(errorMsg);
return "";
}
return formatted_date;
}
Aggregations