use of com.ibm.icu.util.Calendar in project mycore by MyCoRe-Org.
the class MCRMetaHistoryDate method setBisDate.
/**
* This method set the bis to the given date.
*
* @param set_date
* a date string
* @param calstr
* the calendar as String, one of CALENDARS.
*/
public final void setBisDate(String set_date, String calstr) {
Calendar c = bis;
try {
c = MCRCalendar.getHistoryDateAsCalendar(set_date, true, calstr);
} catch (Exception e) {
LOGGER.warn("The bis date {} for calendar {} is false.", set_date, calstr);
c = null;
}
setBisDate(c);
}
use of com.ibm.icu.util.Calendar in project mycore by MyCoRe-Org.
the class MCRCalendarTest method getDateToFormattedString.
/*
* Test method for 'org.mycore.datamodel.metadata.MCRCalendar.getDateToFormattedString()'
*/
@Test
public void getDateToFormattedString() {
GregorianCalendar default_calendar = new GregorianCalendar();
default_calendar.set(1964, 1, 24);
String dstring;
Calendar cal;
// gregorian without format
cal = (GregorianCalendar) default_calendar.clone();
dstring = MCRCalendar.getCalendarDateToFormattedString(cal);
assertEquals("calendar without format", "1964-02-24 AD", dstring);
// gregorian with format
cal = (GregorianCalendar) default_calendar.clone();
dstring = MCRCalendar.getCalendarDateToFormattedString(cal, "dd.MM.yyyy G");
assertEquals("calendar with format dd.MM.yyyy G", "24.02.1964 AD", dstring);
// gregorian with format
cal = (GregorianCalendar) default_calendar.clone();
dstring = MCRCalendar.getCalendarDateToFormattedString(cal, "yyyy-MM-dd");
assertEquals("gregorian with format yyyy-MM-dd", "1964-02-24", dstring);
}
use of com.ibm.icu.util.Calendar 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;
}
use of com.ibm.icu.util.Calendar in project ofbiz-framework by apache.
the class TechDataServices method capacityRemaining.
/**
* Used to to request the remain capacity available for dateFrom in a TechDataCalenda,
* If the dateFrom (param in) is not in an available TechDataCalendar period, the return value is zero.
*
* @param techDataCalendar The TechDataCalendar cover
* @param dateFrom the date
* @return long capacityRemaining
*/
public static long capacityRemaining(GenericValue techDataCalendar, Timestamp dateFrom) {
GenericValue techDataCalendarWeek = null;
// TODO read TechDataCalendarExcWeek to manage execption week (maybe it's needed to refactor the entity definition
try {
techDataCalendarWeek = techDataCalendar.getRelatedOne("TechDataCalendarWeek", true);
} catch (GenericEntityException e) {
Debug.logError("Pb reading Calendar Week associated with calendar" + e.getMessage(), module);
return 0;
}
// TODO read TechDataCalendarExcDay to manage execption day
Calendar cDateTrav = Calendar.getInstance();
cDateTrav.setTime(dateFrom);
Map<String, Object> position = dayStartCapacityAvailable(techDataCalendarWeek, cDateTrav.get(Calendar.DAY_OF_WEEK));
int moveDay = ((Integer) position.get("moveDay")).intValue();
if (moveDay != 0)
return 0;
Time startTime = (Time) position.get("startTime");
Double capacity = (Double) position.get("capacity");
Timestamp startAvailablePeriod = new Timestamp(UtilDateTime.getDayStart(dateFrom).getTime() + startTime.getTime() + cDateTrav.get(Calendar.ZONE_OFFSET) + cDateTrav.get(Calendar.DST_OFFSET));
if (dateFrom.before(startAvailablePeriod))
return 0;
Timestamp endAvailablePeriod = new Timestamp(startAvailablePeriod.getTime() + capacity.longValue());
if (dateFrom.after(endAvailablePeriod))
return 0;
return endAvailablePeriod.getTime() - dateFrom.getTime();
}
use of com.ibm.icu.util.Calendar in project ofbiz-framework by apache.
the class TechDataServices method endPreviousDay.
/**
* Used to move in a TechDataCalenda, produce the Timestamp for the end of the previous day available and its associated capacity.
* If the dateFrom (param in) is not in an available TechDataCalendar period, the return value is the previous day available
*
* @param techDataCalendar The TechDataCalendar cover
* @param dateFrom the date
* @return a map with Timestamp dateTo, Double previousCapacity
*/
public static Map<String, Object> endPreviousDay(GenericValue techDataCalendar, Timestamp dateFrom) {
Map<String, Object> result = new HashMap<String, Object>();
Timestamp dateTo = null;
GenericValue techDataCalendarWeek = null;
// TODO read TechDataCalendarExcWeek to manage exception week (maybe it's needed to refactor the entity definition
try {
techDataCalendarWeek = techDataCalendar.getRelatedOne("TechDataCalendarWeek", true);
} catch (GenericEntityException e) {
Debug.logError("Pb reading Calendar Week associated with calendar" + e.getMessage(), module);
return ServiceUtil.returnError("Pb reading Calendar Week associated with calendar");
}
// TODO read TechDataCalendarExcDay to manage execption day
Calendar cDateTrav = Calendar.getInstance();
cDateTrav.setTime(dateFrom);
Map<String, Object> position = dayEndCapacityAvailable(techDataCalendarWeek, cDateTrav.get(Calendar.DAY_OF_WEEK));
Time startTime = (Time) position.get("startTime");
int moveDay = ((Integer) position.get("moveDay")).intValue();
Double capacity = (Double) position.get("capacity");
dateTo = (moveDay == 0) ? dateFrom : UtilDateTime.getDayEnd(dateFrom, Long.valueOf(moveDay));
Timestamp endAvailablePeriod = new Timestamp(UtilDateTime.getDayStart(dateTo).getTime() + startTime.getTime() + capacity.longValue() + cDateTrav.get(Calendar.ZONE_OFFSET) + cDateTrav.get(Calendar.DST_OFFSET));
if (dateTo.after(endAvailablePeriod)) {
dateTo = endAvailablePeriod;
} else {
dateTo = UtilDateTime.getDayStart(dateTo, -1);
cDateTrav.setTime(dateTo);
position = dayEndCapacityAvailable(techDataCalendarWeek, cDateTrav.get(Calendar.DAY_OF_WEEK));
startTime = (Time) position.get("startTime");
moveDay = ((Integer) position.get("moveDay")).intValue();
capacity = (Double) position.get("capacity");
if (moveDay != 0)
dateTo = UtilDateTime.getDayStart(dateTo, moveDay);
dateTo.setTime(dateTo.getTime() + startTime.getTime() + capacity.longValue() + cDateTrav.get(Calendar.ZONE_OFFSET) + cDateTrav.get(Calendar.DST_OFFSET));
}
result.put("dateTo", dateTo);
result.put("previousCapacity", position.get("capacity"));
return result;
}
Aggregations