Search in sources :

Example 46 with Calendar

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

the class UtilDateTime method monthBegin.

/**
 * Makes a Timestamp for the beginning of the month
 *
 * @return A Timestamp of the beginning of the month
 */
public static java.sql.Timestamp monthBegin() {
    Calendar mth = Calendar.getInstance();
    mth.set(Calendar.DAY_OF_MONTH, 1);
    mth.set(Calendar.HOUR_OF_DAY, 0);
    mth.set(Calendar.MINUTE, 0);
    mth.set(Calendar.SECOND, 0);
    mth.set(Calendar.MILLISECOND, 0);
    mth.set(Calendar.AM_PM, Calendar.AM);
    return new java.sql.Timestamp(mth.getTime().getTime());
}
Also used : Calendar(com.ibm.icu.util.Calendar) Timestamp(java.sql.Timestamp)

Example 47 with Calendar

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

the class UtilDateTime method getWeekStart.

public static Timestamp getWeekStart(Timestamp stamp, int daysLater, int weeksLater, 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);
    tempCal.set(Calendar.DAY_OF_WEEK, tempCal.getFirstDayOfWeek());
    tempCal.add(Calendar.WEEK_OF_MONTH, weeksLater);
    Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
    retStamp.setNanos(0);
    return retStamp;
}
Also used : Calendar(com.ibm.icu.util.Calendar) Timestamp(java.sql.Timestamp)

Example 48 with Calendar

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

the class UtilDateTime method getDayNames.

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

Example 49 with Calendar

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

the class UtilDateTime method getDayEnd.

public static Timestamp getDayEnd(Timestamp stamp, Long 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), 23, 59, 59);
    tempCal.add(Calendar.DAY_OF_MONTH, daysLater.intValue());
    Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
    retStamp.setNanos(0);
    // MSSQL datetime field has accuracy of 3 milliseconds and setting the nano seconds cause the date to be rounded to next day
    return retStamp;
}
Also used : Calendar(com.ibm.icu.util.Calendar) Timestamp(java.sql.Timestamp)

Example 50 with Calendar

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

the class UtilDateTime method getYearStart.

public static Timestamp getYearStart(Timestamp stamp, int daysLater, int monthsLater, int yearsLater, TimeZone timeZone, Locale locale) {
    Calendar tempCal = toCalendar(stamp, timeZone, locale);
    tempCal.set(tempCal.get(Calendar.YEAR), Calendar.JANUARY, 1, 0, 0, 0);
    tempCal.add(Calendar.YEAR, yearsLater);
    tempCal.add(Calendar.MONTH, monthsLater);
    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)

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