Java Code Examples for java.util.Calendar.getActualMinimum()

The following are Jave code examples for showing how to use getActualMinimum() of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: marathonv5   File: DailySalesHeatMapFacadeREST.java   View Source Code Vote up 6 votes
private HashMap<String, Long> runBaseQuery(Date date){
    Calendar cal = Calendar.getInstance();
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query baseQuery = em.createQuery(BASE_QUERY);
    HashMap<String, Long> result = new HashMap<String, Long>();
    {
        cal.setTime(date);
        int dayMin = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        cal.set(Calendar.DAY_OF_MONTH, dayMin);
        Parameter<Date> p1 = baseQuery.getParameter("oldStartDate", Date.class);
        baseQuery.setParameter(p1, cal.getTime());
        cal.set(Calendar.DAY_OF_MONTH, dayMax);
        Parameter<Date> p2 = baseQuery.getParameter("oldEndDate", Date.class);
        baseQuery.setParameter(p2, cal.getTime());

        List<Object[]> resultList = baseQuery.getResultList();

        DIFF = (System.currentTimeMillis() - TIME);
        System.out.println("    Q TIME = "+DIFF+"ms");

        for (int i=0; i < resultList.size(); i++){
            Object o[] = resultList.get(i);
            result.put((String)o[1],(Long)o[0]);
        }
    }
    return result;
}
 
Example 2
Project: Perfect-Day   File: CalendarView.java   View Source Code Vote up 6 votes
public void updateCalendar(HashSet<Date> events) {
    ArrayList<Date> cells = new ArrayList<>();
    Calendar calendar = (Calendar) currentDate.clone();

    new SimpleDateFormat("MMM").format(calendar.getTime());
    int actualMinimum = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
    int monthDisplayIndex = calendar.getTime().getDate() - actualMinimum + 1;

    while (cells.size() < DAYS_COUNT) {
        cells.add(calendar.getTime());
        calendar.add(Calendar.DAY_OF_MONTH, -1);
    }
    CalendarAdapter calendarAdapter = new CalendarAdapter(getContext(), cells, events, monthDisplayIndex);
    grid.setAdapter(calendarAdapter);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
    grid.setLayoutManager(layoutManager);
    calendarAdapter.notifyDataSetChanged();
    grid.setHasFixedSize(true);
}
 
Example 3
Project: marathonv5   File: DailySalesHeatMapFacadeREST.java   View Source Code Vote up 5 votes
private HashMap<String, Long> runBaseQuery(Date date){
    Calendar cal = Calendar.getInstance();
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query baseQuery = em.createQuery(BASE_QUERY);
    HashMap<String, Long> result = new HashMap<String, Long>();
    {
        cal.setTime(date);
        int dayMin = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        cal.set(Calendar.DAY_OF_MONTH, dayMin);
        Parameter<Date> p1 = baseQuery.getParameter("oldStartDate", Date.class);
        baseQuery.setParameter(p1, cal.getTime());
        cal.set(Calendar.DAY_OF_MONTH, dayMax);
        Parameter<Date> p2 = baseQuery.getParameter("oldEndDate", Date.class);
        baseQuery.setParameter(p2, cal.getTime());

        List<Object[]> resultList = baseQuery.getResultList();

        DIFF = (System.currentTimeMillis() - TIME);
        System.out.println("    Q TIME = "+DIFF+"ms");

        for (int i=0; i < resultList.size(); i++){
            Object o[] = resultList.get(i);
            result.put((String)o[1],(Long)o[0]);
        }
    }
    return result;
}
 
Example 4
Project: marathonv5   File: DailySalesHeatMapFacadeREST.java   View Source Code Vote up 5 votes
private HashMap<String, Long> runProductTypeQuery(Date date1, Integer productTypeId){
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query baseQuery = em.createQuery(BASE_TYPE_QUERY);
    Calendar cal = Calendar.getInstance();
    
    HashMap<String, Long> result = new HashMap<String, Long>();
    {
        cal.setTime(date1);
        int dayMin = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        cal.set(Calendar.DAY_OF_MONTH, dayMin);
        Parameter<Date> p1 = baseQuery.getParameter("oldStartDate", Date.class);
        baseQuery.setParameter(p1, cal.getTime());
        cal.set(Calendar.DAY_OF_MONTH, dayMax);
        Parameter<Date> p2 = baseQuery.getParameter("oldEndDate", Date.class);
        baseQuery.setParameter(p2, cal.getTime());
        Parameter<Integer> p3 = baseQuery.getParameter("productTypeId", Integer.class);
        baseQuery.setParameter(p3, productTypeId);

        List<Object[]> resultList = baseQuery.getResultList();

        DIFF = (System.currentTimeMillis() - TIME);
        System.out.println("    Q TIME = "+DIFF+"ms");

        for (int i=0; i < resultList.size(); i++){
            Object o[] = resultList.get(i);
            result.put((String)o[1],(Long)o[0]);
        }
    }
    
    return result;
}
 
Example 5
Project: marathonv5   File: DailySalesHeatMapFacadeREST.java   View Source Code Vote up 5 votes
private HashMap<String, Long> runProductTypeQuery(Date date1, Integer productTypeId){
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query baseQuery = em.createQuery(BASE_TYPE_QUERY);
    Calendar cal = Calendar.getInstance();
    
    HashMap<String, Long> result = new HashMap<String, Long>();
    {
        cal.setTime(date1);
        int dayMin = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        cal.set(Calendar.DAY_OF_MONTH, dayMin);
        Parameter<Date> p1 = baseQuery.getParameter("oldStartDate", Date.class);
        baseQuery.setParameter(p1, cal.getTime());
        cal.set(Calendar.DAY_OF_MONTH, dayMax);
        Parameter<Date> p2 = baseQuery.getParameter("oldEndDate", Date.class);
        baseQuery.setParameter(p2, cal.getTime());
        Parameter<Integer> p3 = baseQuery.getParameter("productTypeId", Integer.class);
        baseQuery.setParameter(p3, productTypeId);

        List<Object[]> resultList = baseQuery.getResultList();

        DIFF = (System.currentTimeMillis() - TIME);
        System.out.println("    Q TIME = "+DIFF+"ms");

        for (int i=0; i < resultList.size(); i++){
            Object o[] = resultList.get(i);
            result.put((String)o[1],(Long)o[0]);
        }
    }
    
    return result;
}
 
Example 6
Project: date-helper   File: DateHelper.java   View Source Code Vote up 5 votes
/**
 * Antwortet das Datum des ersten Tags des Monats, in der <code>date</code>
 * liegt
 *
 * @return Date
 */
public static Date getFirstDayOfMonth(Date date) {

	Calendar calendar = getCalendar(date);
	int firstDate = calendar.getActualMinimum(Calendar.DATE);
	calendar.set(Calendar.DATE, firstDate);
	return calendar.getTime();
}
 
Example 7
Project: myfaces-trinidad   File: ChooseDateRenderer.java   View Source Code Vote up 5 votes
/**
 * Get the first day of the month.
 */
private static int _getActualMinimumDayOfMonth(
  Calendar calendar
  )
{
  return calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
}
 
Example 8
Project: azeroth   File: DateUtils.java   View Source Code Vote up 5 votes
/**
 * 返回传入时间月份的第一天
 * */
public static Date firstDayOfMonth(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int value = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
    cal.set(Calendar.DAY_OF_MONTH, value);
    return cal.getTime();
}
 
Example 9
Project: openjdk-jdk10   File: DisabledAlgorithmConstraints.java   View Source Code Vote up 5 votes
DenyAfterConstraint(String algo, int year, int month, int day) {
    Calendar c;

    algorithm = algo;

    if (debug != null) {
        debug.println("DenyAfterConstraint read in as:  year " +
                year + ", month = " + month + ", day = " + day);
    }

    c = new Calendar.Builder().setTimeZone(TimeZone.getTimeZone("GMT"))
            .setDate(year, month - 1, day).build();

    if (year > c.getActualMaximum(Calendar.YEAR) ||
            year < c.getActualMinimum(Calendar.YEAR)) {
        throw new IllegalArgumentException(
                "Invalid year given in constraint: " + year);
    }
    if ((month - 1) > c.getActualMaximum(Calendar.MONTH) ||
            (month - 1) < c.getActualMinimum(Calendar.MONTH)) {
        throw new IllegalArgumentException(
                "Invalid month given in constraint: " + month);
    }
    if (day > c.getActualMaximum(Calendar.DAY_OF_MONTH) ||
            day < c.getActualMinimum(Calendar.DAY_OF_MONTH)) {
        throw new IllegalArgumentException(
                "Invalid Day of Month given in constraint: " + day);
    }

    denyAfterDate = c.getTime();
    if (debug != null) {
        debug.println("DenyAfterConstraint date set to: " +
                dateFormat.format(denyAfterDate));
    }
}
 
Example 10
Project: openjdk-jdk10   File: CalendarTest.java   View Source Code Vote up 5 votes
public void TestActualMinMax() {
    Calendar cal = new GregorianCalendar(1967, MARCH, 10);
    cal.setFirstDayOfWeek(SUNDAY);
    cal.setMinimalDaysInFirstWeek(3);

    if (cal.getActualMinimum(DAY_OF_MONTH) != 1) {
        errln("Actual minimum date for 3/10/1967 should have been 1; got "
                + cal.getActualMinimum(DAY_OF_MONTH));
    }
    if (cal.getActualMaximum(DAY_OF_MONTH) != 31) {
        errln("Actual maximum date for 3/10/1967 should have been 31; got "
                + cal.getActualMaximum(DAY_OF_MONTH));
    }

    cal.set(MONTH, FEBRUARY);
    if (cal.getActualMaximum(DAY_OF_MONTH) != 28) {
        errln("Actual maximum date for 2/10/1967 should have been 28; got "
                + cal.getActualMaximum(DAY_OF_MONTH));
    }
    if (cal.getActualMaximum(DAY_OF_YEAR) != 365) {
        errln("Number of days in 1967 should have been 365; got "
                + cal.getActualMaximum(DAY_OF_YEAR));
    }

    cal.set(YEAR, 1968);
    if (cal.getActualMaximum(DAY_OF_MONTH) != 29) {
        errln("Actual maximum date for 2/10/1968 should have been 29; got "
                + cal.getActualMaximum(DAY_OF_MONTH));
    }
    if (cal.getActualMaximum(DAY_OF_YEAR) != 366) {
        errln("Number of days in 1968 should have been 366; got "
                + cal.getActualMaximum(DAY_OF_YEAR));
    }
    // Using week settings of SUNDAY/3 (see above)
    if (cal.getActualMaximum(WEEK_OF_YEAR) != 52) {
        errln("Number of weeks in 1968 should have been 52; got "
                + cal.getActualMaximum(WEEK_OF_YEAR));
    }

    cal.set(YEAR, 1976);
    // Using week settings of SUNDAY/3 (see above)
    if (cal.getActualMaximum(WEEK_OF_YEAR) != 53) {
        errln("Number of weeks in 1976 should have been 53; got "
                + cal.getActualMaximum(WEEK_OF_YEAR));
    }
}