Search in sources :

Example 41 with Calendar

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

the class UtilDateTime method getWeekEnd.

public static Timestamp getWeekEnd(Timestamp stamp, TimeZone timeZone, Locale locale) {
    Timestamp weekStart = getWeekStart(stamp, timeZone, locale);
    Calendar tempCal = toCalendar(weekStart, timeZone, locale);
    tempCal.add(Calendar.DAY_OF_MONTH, 6);
    return getDayEnd(new Timestamp(tempCal.getTimeInMillis()), timeZone, locale);
}
Also used : Calendar(com.ibm.icu.util.Calendar) Timestamp(java.sql.Timestamp)

Example 42 with Calendar

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

the class UtilDateTime method getYearEnd.

public static Timestamp getYearEnd(Timestamp stamp, TimeZone timeZone, Locale locale) {
    Calendar tempCal = toCalendar(stamp, timeZone, locale);
    tempCal.set(tempCal.get(Calendar.YEAR), tempCal.getActualMaximum(Calendar.MONTH) + 1, 0, 0, 0, 0);
    return getMonthEnd(new Timestamp(tempCal.getTimeInMillis()), timeZone, locale);
}
Also used : Calendar(com.ibm.icu.util.Calendar) Timestamp(java.sql.Timestamp)

Example 43 with Calendar

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

the class UtilDateTime method getDayStart.

public static Timestamp getDayStart(Timestamp stamp, int daysLater, TimeZone timeZone, Locale locale) {
    Calendar tempCal = toCalendar(stamp, timeZone, locale);
    tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    tempCal.add(Calendar.DAY_OF_MONTH, daysLater);
    Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
    retStamp.setNanos(0);
    return retStamp;
}
Also used : Calendar(com.ibm.icu.util.Calendar) Timestamp(java.sql.Timestamp)

Example 44 with Calendar

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

the class UtilDateTime method adjustTimestamp.

/**
 * Perform date/time arithmetic on a Timestamp. This is the only accurate way to
 * perform date/time arithmetic across locales and time zones.
 *
 * @param stamp date/time to perform arithmetic on
 * @param adjType the adjustment type to perform. Use one of the java.util.Calendar fields.
 * @param adjQuantity the adjustment quantity.
 * @param timeZone
 * @param locale
 * @return adjusted Timestamp
 * @see java.util.Calendar
 */
public static Timestamp adjustTimestamp(Timestamp stamp, int adjType, int adjQuantity, TimeZone timeZone, Locale locale) {
    Calendar tempCal = toCalendar(stamp, timeZone, locale);
    tempCal.add(adjType, adjQuantity);
    return new Timestamp(tempCal.getTimeInMillis());
}
Also used : Calendar(com.ibm.icu.util.Calendar) Timestamp(java.sql.Timestamp)

Example 45 with Calendar

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

the class UtilDateTime method adjustTimestamp.

public static Timestamp adjustTimestamp(Timestamp stamp, Integer adjType, Integer adjQuantity) {
    Calendar tempCal = toCalendar(stamp);
    tempCal.add(adjType, adjQuantity);
    return new Timestamp(tempCal.getTimeInMillis());
}
Also used : Calendar(com.ibm.icu.util.Calendar) Timestamp(java.sql.Timestamp)

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