Search in sources :

Example 16 with Calendar

use of com.ibm.icu.util.Calendar in project ofbiz-framework by apache.

the class UtilDateTime method getLatestDate.

public static Date getLatestDate() {
    Calendar cal = getCalendarInstance(TimeZone.getTimeZone("GMT"), Locale.getDefault());
    cal.set(Calendar.YEAR, cal.getActualMaximum(Calendar.YEAR));
    cal.set(Calendar.MONTH, cal.getActualMaximum(Calendar.MONTH));
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 999);
    return cal.getTime();
}
Also used : Calendar(com.ibm.icu.util.Calendar)

Example 17 with Calendar

use of com.ibm.icu.util.Calendar in project ofbiz-framework by apache.

the class UtilDateTime method toDateString.

/**
 * Makes a date String in the given from a Date
 *
 * @param date The Date
 * @return A date String in the given format
 */
public static String toDateString(java.util.Date date, String format) {
    if (date == null) {
        return "";
    }
    SimpleDateFormat dateFormat = null;
    if (format != null) {
        dateFormat = new SimpleDateFormat(format);
    } else {
        dateFormat = new SimpleDateFormat();
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return dateFormat.format(date);
}
Also used : Calendar(com.ibm.icu.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat)

Example 18 with Calendar

use of com.ibm.icu.util.Calendar in project ofbiz-framework by apache.

the class UtilDateTime method getEarliestDate.

public static Date getEarliestDate() {
    Calendar cal = getCalendarInstance(TimeZone.getTimeZone("GMT"), Locale.getDefault());
    cal.set(Calendar.YEAR, cal.getActualMinimum(Calendar.YEAR));
    cal.set(Calendar.MONTH, cal.getActualMinimum(Calendar.MONTH));
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}
Also used : Calendar(com.ibm.icu.util.Calendar)

Example 19 with Calendar

use of com.ibm.icu.util.Calendar in project ofbiz-framework by apache.

the class UtilDateTime method weekNumber.

public static int weekNumber(Timestamp input, int startOfWeek) {
    Calendar calendar = Calendar.getInstance();
    calendar.setFirstDayOfWeek(startOfWeek);
    if (startOfWeek == Calendar.MONDAY) {
        calendar.setMinimalDaysInFirstWeek(4);
    } else if (startOfWeek == Calendar.SUNDAY) {
        calendar.setMinimalDaysInFirstWeek(3);
    }
    calendar.setTime(new java.util.Date(input.getTime()));
    return calendar.get(Calendar.WEEK_OF_YEAR);
}
Also used : Date(java.util.Date) Calendar(com.ibm.icu.util.Calendar)

Example 20 with Calendar

use of com.ibm.icu.util.Calendar in project ofbiz-framework by apache.

the class UtilDateTime method getMonthNames.

/**
 * Returns a List of month name Strings - suitable for calendar headings.
 *
 * @param locale
 * @return List of month name Strings
 */
public static List<String> getMonthNames(Locale locale) {
    Calendar tempCal = Calendar.getInstance(locale);
    tempCal.set(Calendar.MONTH, Calendar.JANUARY);
    SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM", locale);
    List<String> resultList = new ArrayList<>();
    for (int i = Calendar.JANUARY; i <= tempCal.getActualMaximum(Calendar.MONTH); i++) {
        resultList.add(dateFormat.format(tempCal.getTime()));
        tempCal.roll(Calendar.MONTH, 1);
    }
    return resultList;
}
Also used : Calendar(com.ibm.icu.util.Calendar) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Calendar (com.ibm.icu.util.Calendar)75 Timestamp (java.sql.Timestamp)37 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)24 GenericValue (org.apache.ofbiz.entity.GenericValue)24 Delegator (org.apache.ofbiz.entity.Delegator)17 Date (java.util.Date)14 HashMap (java.util.HashMap)12 Locale (java.util.Locale)12 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)11 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)11 GregorianCalendar (com.ibm.icu.util.GregorianCalendar)10 ArrayList (java.util.ArrayList)8 SimpleDateFormat (java.text.SimpleDateFormat)6 LinkedList (java.util.LinkedList)6 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)6 Map (java.util.Map)5 TimeDuration (org.apache.ofbiz.base.util.TimeDuration)5 BigDecimal (java.math.BigDecimal)4 Time (java.sql.Time)4 UtilDateTime (org.apache.ofbiz.base.util.UtilDateTime)4