Example usage for java.util Calendar getMinimum

List of usage examples for java.util Calendar getMinimum

Introduction

In this page you can find the example usage for java.util Calendar getMinimum.

Prototype

public abstract int getMinimum(int field);

Source Link

Document

Returns the minimum value for the given calendar field of this Calendar instance.

Usage

From source file:com.viettel.ttbankplus.servicegw.hibernate.dao.transaction.TransCPDAO.java

public List<Map<String, Object>> getReportTotal(Date fromDate, Date toDate, String by, String bankCode,
        ArrayList<Long> lstCpId) {
    List<Map<String, Object>> lst = new ArrayList();
    try {/*from w ww  . j  av  a2 s  .c  o m*/
        //            String where = " where cp.trans_status = 2 and (cp.trans_type = 0 or cp.trans_type = 2) ";
        String where = " where (bp.error_code = '00' or bp.correct_code = '00') and (cp.trans_type = 0 or cp.trans_type = 2) ";
        where += " and cp.request_date >= to_date(:fromDate, 'dd/MM/yyyy hh24:mi:ss') and cp.request_date <= to_date(:toDate, 'dd/MM/yyyy hh24:mi:ss')";
        where += " and cp.content_provider_id in (:cpId) ";
        if (bankCode != null && !bankCode.equals("")) {
            where += " and upper(bp.bank_code) = :bankCode ";
        }
        String groupBy = "";
        String orderBy = "";
        String sql = "select bp.bank_code bankCode, to_char(cp.request_date, 'MM/yyyy') monDay, ";
        if (by.equals("MON")) {
            //Chuyen ngay thang thanh thang
            Calendar cal = Calendar.getInstance();
            cal.setTime(fromDate);
            Calendar calFrom = Calendar.getInstance();
            calFrom.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.getMinimum(Calendar.DAY_OF_MONTH),
                    0, 0, 0);

            cal.setTime(toDate);
            Calendar calTo = Calendar.getInstance();
            calTo.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.getMaximum(Calendar.DAY_OF_MONTH),
                    23, 59, 59);

            fromDate = calFrom.getTime();
            toDate = calTo.getTime();

            sql = "select bp.bank_code bankCode, to_char(cp.request_date, 'MM/yyyy') monDay, ";
            groupBy = " group by  to_char(cp.request_date, 'MM/yyyy'), bp.bank_code, p.cp_code, p.cp_name ";
            orderBy = " order by to_date(monDay, 'MM/yyyy') desc";
        } else {
            sql = "select bp.bank_code bankCode, to_char(cp.request_date, 'dd/MM/yyyy') monDay, ";
            groupBy = " group by to_char(cp.request_date, 'dd/MM/yyyy'), bp.bank_code, p.cp_code, p.cp_name ";
            orderBy = " order by to_date(monDay, 'dd/MM/yyyy') desc";
        }
        sql += " SUM(CASE cp.trans_type WHEN 0 THEN 1 ELSE 0 END) totalPay,";
        sql += " SUM(CASE cp.trans_type WHEN 2 THEN 1 ELSE 0 END) totalRefund,";
        sql += " SUM(CASE cp.trans_type WHEN 0 THEN cp.AMOUNT ELSE 0 END) payAmount,";
        sql += " SUM(CASE cp.trans_type WHEN 2 THEN cp.AMOUNT ELSE 0 END) refundAmount,";
        sql += " SUM(nvl(bp.fee,0)) totalFee,";
        sql += " p.cp_code cpCode, p.cp_name cpName ";
        sql += " from trans_cp cp left join trans_bankplus bp on cp.trans_cp_id = bp.trans_cp_id";
        sql += " left join content_provider p on cp.content_provider_id = p.content_provider_id ";
        sql += where;
        sql += groupBy;
        sql += orderBy;
        log.debug(sql);
        SQLQuery query = getSession().createSQLQuery(sql);
        //        query.setResultTransformer(Transformers.aliasToBean(ReportTotal.class));
        query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

        query.setParameter("fromDate", sdf.format(fromDate));
        query.setParameter("toDate", sdf.format(toDate));

        //            query.setParameter("fromDate", fromDate);
        //            query.setParameter("toDate", toDate);
        query.setParameterList("cpId", lstCpId);
        if (bankCode != null && !bankCode.equals("")) {
            query.setParameter("bankCode", bankCode.toUpperCase());
        }
        lst = query.list();
    } catch (Exception ex) {
        log.error("getReportTotal: ", ex);
    } finally {
        DAOFactory.commitCurrentSessions();
    }
    return lst;
}

From source file:com.viettel.ttbankplus.servicegw.hibernate.dao.transaction.TransCPDAO.java

public List<Map<String, Object>> getReportRefund(Date fromDate, Date toDate, String by, String bankCode,
        ArrayList<Long> lstCpId) {
    List<Map<String, Object>> lst = new ArrayList();
    try {/*from w  w w  .j  a v a2s .c o m*/
        String where = " where cp.trans_type = 2 ";
        where += " and cp.request_date >= to_date(:fromDate, 'dd/MM/yyyy hh24:mi:ss') and cp.request_date <= to_date(:toDate, 'dd/MM/yyyy hh24:mi:ss')";
        //            where += " and cp.request_date >= :fromDate and cp.request_date <= :toDate";
        where += " and cp.content_provider_id in (:cpId) ";
        if (bankCode != null && !bankCode.equals("")) {
            where += " and upper(bp.bank_code) = :bankCode ";
        }
        String groupBy = "";
        String orderBy = "";
        String sql = "select bp.bank_code bankCode, to_char(cp.request_date, 'MM/yyyy') monDay, ";
        if (by.equals("MON")) {
            //Chuyen ngay thang thanh thang
            Calendar cal = Calendar.getInstance();
            cal.setTime(fromDate);
            Calendar calFrom = Calendar.getInstance();
            calFrom.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.getMinimum(Calendar.DAY_OF_MONTH),
                    0, 0, 0);

            cal.setTime(toDate);
            Calendar calTo = Calendar.getInstance();
            calTo.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.getMaximum(Calendar.DAY_OF_MONTH),
                    23, 59, 59);

            fromDate = calFrom.getTime();
            toDate = calTo.getTime();

            sql = "select bp.bank_code bankCode, to_char(cp.request_date, 'MM/yyyy') monDay, ";
            groupBy = " group by  to_char(cp.request_date, 'MM/yyyy'), bp.bank_code, p.cp_code, p.cp_name";
            orderBy = " order by to_date(monDay, 'MM/yyyy') desc";
        } else {
            sql = "select bp.bank_code bankCode, to_char(cp.request_date, 'dd/MM/yyyy') monDay, ";
            groupBy = " group by  to_char(cp.request_date, 'dd/MM/yyyy'), bp.bank_code, p.cp_code, p.cp_name";
            orderBy = " order by to_date(monDay, 'dd/MM/yyyy') desc";
        }
        sql += " SUM(CASE cp.trans_status WHEN '0' THEN 1 ELSE 0 END) totalpending,";
        sql += " SUM(CASE cp.trans_status WHEN '2' THEN 1 ELSE 0 END) totalsuccess,";
        sql += " SUM(CASE cp.trans_status WHEN '4' THEN 1 ELSE 0 END) totalfailure,";
        sql += " SUM(CASE cp.trans_status WHEN '0' THEN cp.amount ELSE 0 END) amountpending,";
        sql += " SUM(CASE cp.trans_status WHEN '2' THEN cp.amount ELSE 0 END) amountsuccess,";
        sql += " SUM(CASE cp.trans_status WHEN '4' THEN cp.amount ELSE 0 END) amountfailure,";
        sql += " p.cp_code cpCode, p.cp_name cpName ";
        //            sql += " from trans_cp cp left join trans_bankplus bp on cp.trans_cp_id = bp.trans_cp_id";
        sql += " from trans_cp cp";
        sql += " join trans_cp cp2 on cp.original_trans_id = cp2.trans_id ";
        sql += " left join trans_bankplus bp on cp2.trans_cp_id = bp.trans_cp_id ";
        sql += " left join content_provider p on cp.content_provider_id = p.content_provider_id ";
        sql += where;
        sql += groupBy;
        sql += orderBy;
        log.debug(sql);
        SQLQuery query = getSession().createSQLQuery(sql);
        //        query.setResultTransformer(Transformers.aliasToBean(ReportTotal.class));
        query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

        query.setParameter("fromDate", sdf.format(fromDate));
        query.setParameter("toDate", sdf.format(toDate));
        //            query.setParameter("fromDate", fromDate);
        //            query.setParameter("toDate", toDate);
        query.setParameterList("cpId", lstCpId);
        if (bankCode != null && !bankCode.equals("")) {
            query.setParameter("bankCode", bankCode.toUpperCase());
        }
        lst = query.list();
    } catch (Exception ex) {
        log.error("getReportRefund: ", ex);
    } finally {
        DAOFactory.commitCurrentSessions();
    }
    return lst;
}

From source file:com.viettel.ttbankplus.servicegw.hibernate.dao.transaction.TransCPDAO.java

public List<Map<String, Object>> getReportTotalEVN(Date fromDate, Date toDate, String by, String bankCode,
        Long cpId) {/*from   w  w  w  .j  a v  a2 s  . c  o  m*/
    List<Map<String, Object>> lst = new ArrayList();
    try {

        String where = " where cp.trans_status = 2 and (cp.trans_type = 0 or cp.trans_type = 2) ";
        where += " and cp.request_date >= to_date(:fromDate, 'dd/MM/yyyy hh24:mi:ss') and cp.request_date <= to_date(:toDate, 'dd/MM/yyyy hh24:mi:ss')";
        //            where += " and cp.request_date >= :fromDate and cp.request_date <= :toDate";
        where += " and cp.content_provider_id = :cpId ";
        where += " and bp.process_code = '300001' ";
        where += " and bp.error_code = '00'  ";

        if (bankCode != null && !bankCode.equals("")) {
            where += " and upper(bp.bank_code) = :bankCode ";
        }
        String groupBy = " group by  to_char(cp.request_date, 'dd/MM/yyyy'), bp.bank_code";
        String orderBy = "";
        String sql = "select bp.bank_code bankCode, to_char(cp.request_date, 'MM/yyyy') monDay, sum(bs.num_order) totalBill, ";
        if (by.equals("MON")) {
            //Chuyen ngay thang thanh thang
            Calendar cal = Calendar.getInstance();
            cal.setTime(fromDate);
            Calendar calFrom = Calendar.getInstance();
            calFrom.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.getMinimum(Calendar.DAY_OF_MONTH),
                    0, 0, 0);

            cal.setTime(toDate);
            Calendar calTo = Calendar.getInstance();
            calTo.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.getMaximum(Calendar.DAY_OF_MONTH),
                    23, 59, 59);

            fromDate = calFrom.getTime();
            toDate = calTo.getTime();

            sql = "select bp.bank_code bankCode, to_char(cp.request_date, 'MM/yyyy') monDay, sum(bs.num_order) totalBill, ";
            groupBy = " group by  to_char(cp.request_date, 'MM/yyyy'), bp.bank_code";
            orderBy = " order by to_date(monDay, 'MM/yyyy') desc";
        } else {
            sql = "select bp.bank_code bankCode, to_char(cp.request_date, 'dd/MM/yyyy') monDay, sum(bs.num_order) totalBill, ";
            groupBy = " group by  to_char(cp.request_date, 'dd/MM/yyyy'), bp.bank_code";
            orderBy = " order by to_date(monDay, 'dd/MM/yyyy') desc";
        }
        sql += " SUM(CASE cp.trans_type WHEN 0 THEN 1 ELSE 0 END) totalPay,";
        sql += " SUM(CASE cp.trans_type WHEN 2 THEN 1 ELSE 0 END) totalRefund,";
        sql += " SUM(CASE cp.trans_type WHEN 0 THEN bp.amount ELSE 0 END) payAmount,";
        sql += " SUM(CASE cp.trans_type WHEN 2 THEN bp.amount ELSE 0 END) refundAmount";

        sql += " from trans_cp cp left join trans_bankplus bp on cp.trans_cp_id = bp.trans_cp_id";
        sql += " left join (select aa.*, cc.num_order from trans_bankplus aa ";
        //sql += " inner join billing_service bb on aa.trans_bankplus_id = bb.trans_bankplus_id";
        sql += " inner join (select trans_bankplus_id, count(*) num_order from billing_service group by trans_bankplus_id) cc";
        sql += " on aa.trans_bankplus_id = cc.trans_bankplus_id where aa.error_code = '00') bs";
        sql += " on bp.original_request_id = bs.request_id ";

        sql += where;
        sql += groupBy;
        sql += orderBy;
        log.debug(sql);
        SQLQuery query = getSession().createSQLQuery(sql);
        query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

        query.setParameter("fromDate", sdf.format(fromDate));
        query.setParameter("toDate", sdf.format(toDate));
        //            query.setParameter("fromDate", fromDate);
        //            query.setParameter("toDate", toDate);
        query.setParameter("cpId", cpId);

        if (bankCode != null && !bankCode.equals("")) {
            query.setParameter("bankCode", bankCode.toUpperCase());
        }
        lst = query.list();
    } catch (Exception ex) {
        log.error("getReportTotal: ", ex);
    } finally {
        DAOFactory.commitCurrentSessions();
    }
    return lst;
}

From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java

public static long[] parseTimePeriod(String timeperiod) {

    if (null == timeperiod)
        timeperiod = "last60minutes";

    Date fromDate = null;/*from ww w  . j a v a  2s  .  c o m*/
    Date toDate = null;
    long dataPoints = 60;

    Calendar cal = Calendar.getInstance();
    Date now = cal.getTime();
    // Reset the day fields so we're at the beginning of the day.
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    // Compute "this week" by resetting the day of the week to the first day of the week
    cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
    Date thisWeekStart = cal.getTime();
    Date thisWeekEnd = now;
    // Compute last week - start with the end boundary which is 1 millisecond before the start of this week
    cal.add(Calendar.MILLISECOND, -1);
    Date lastWeekEnd = cal.getTime();
    // Add that millisecond back, subtract 7 days for the start boundary of "last week"
    cal.add(Calendar.MILLISECOND, 1);
    cal.add(Calendar.DAY_OF_YEAR, -7);
    Date lastWeekStart = cal.getTime();
    // Reset the time
    cal.setTime(now);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    // Reset to the 1st day of the month, make the the start boundary for "this month"
    cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DAY_OF_MONTH));
    Date thisMonthStart = cal.getTime();
    Date thisMonthEnd = now;
    // Compute last month
    cal.add(Calendar.MILLISECOND, -1);
    Date lastMonthEnd = cal.getTime();
    cal.add(Calendar.MILLISECOND, 1);
    cal.add(Calendar.MONTH, -1);
    Date lastMonthStart = cal.getTime();
    // Compute last 3 months
    cal.setTime(now);
    cal.add(Calendar.MONTH, -2);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Date last3MonthsStart = cal.getTime();
    Date last3MonthsEnd = now;
    // Compute last 7 days:
    cal.setTime(now);
    cal.add(Calendar.DAY_OF_YEAR, -6);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Date last7DaysStart = cal.getTime();
    Date last7DaysEnd = now;
    // Compute last 60 minutes;
    cal.setTime(now);
    cal.add(Calendar.MINUTE, -60);
    Date last60MinutesStart = cal.getTime();
    Date last60MinutesEnd = now;
    // Compute last 24 hours;
    cal.setTime(now);
    cal.add(Calendar.HOUR, -23);
    Date last24HoursStart = cal.getTime();
    Date last24HoursEnd = now;
    // Done, reset the cal internal date to now
    cal.setTime(now);

    if ("thisweek".equals(timeperiod)) {
        fromDate = thisWeekStart;
        toDate = thisWeekEnd;
        dataPoints = 7;
    } else if ("last7days".equals(timeperiod)) {
        fromDate = last7DaysStart;
        toDate = last7DaysEnd;
        dataPoints = 7;
    } else if ("lastweek".equals(timeperiod)) {
        fromDate = lastWeekStart;
        toDate = lastWeekEnd;
        dataPoints = 7;
    } else if ("thismonth".equals(timeperiod)) {
        fromDate = thisMonthStart;
        toDate = thisMonthEnd;
        dataPoints = 30;
    } else if ("lastmonth".equals(timeperiod)) {
        fromDate = lastMonthStart;
        toDate = lastMonthEnd;
        dataPoints = 30;
    } else if ("last3months".equals(timeperiod)) {
        fromDate = last3MonthsStart;
        toDate = last3MonthsEnd;
        dataPoints = (long) Math.ceil((toDate.getTime() - fromDate.getTime()) / WEEK);
    } else if ("last60minutes".equals(timeperiod)) {
        fromDate = last60MinutesStart;
        toDate = last60MinutesEnd;
        dataPoints = 60;
    } else if ("last24hours".equals(timeperiod)) {
        fromDate = last24HoursStart;
        toDate = last24HoursEnd;
        dataPoints = 48;
    } else {
        String[] dates = timeperiod.split("to");
        if (dates.length > 0) {
            DateFormat formDateFormatter = new SimpleDateFormat("MM/dd/yy");
            String fromDateParam = dates[0];
            String toDateParam = dates[1];
            if (fromDateParam != null) {
                try {
                    fromDate = formDateFormatter.parse(fromDateParam);
                } catch (Exception e) {
                    // ignore formatting exception
                }
            }
            if (toDateParam != null) {
                try {
                    toDate = formDateFormatter.parse(toDateParam);
                    // Make this date be the end of the day (so it's the day *inclusive*, not *exclusive*)
                    Calendar adjusted = Calendar.getInstance();
                    adjusted.setTime(toDate);
                    adjusted.set(Calendar.HOUR_OF_DAY, 23);
                    adjusted.set(Calendar.MINUTE, 59);
                    adjusted.set(Calendar.SECOND, 59);
                    adjusted.set(Calendar.MILLISECOND, 999);
                    toDate = adjusted.getTime();
                } catch (Exception e) {
                    // ignore formatting exception
                }
            }
            dataPoints = discoverDataPoints(fromDate, toDate);
        }
    }

    // default to last 60 minutes
    if (null == fromDate && null == toDate) {
        return new long[] { last60MinutesStart.getTime(), last60MinutesEnd.getTime(), dataPoints };
    } else if (null == fromDate) {
        return new long[] { 0, toDate.getTime(), dataPoints };
    } else if (null == toDate) {
        return new long[] { fromDate.getTime(), now.getTime(), dataPoints };
    } else {
        return new long[] { fromDate.getTime(), toDate.getTime(), dataPoints };
    }
}

From source file:com.markuspage.android.atimetracker.Tasks.java

/**
 * Creates a progressDialog to change the dates for which task times are
 * shown. Offers a short selection of pre-defined defaults, and the option
 * to choose a range from a progressDialog.
 *
 * @see arrays.xml//from www. ja  v  a 2 s  . c o m
 * @return the progressDialog to be displayed
 */
private Dialog openChangeViewDialog() {
    return new AlertDialog.Builder(Tasks.this).setItems(R.array.views, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            SharedPreferences.Editor ed = preferences.edit();
            ed.putInt(VIEW_MODE, which);
            ed.commit();
            if (which == 5) {
                Calendar calInstance = Calendar.getInstance();
                new DatePickerDialog(Tasks.this, new DatePickerDialog.OnDateSetListener() {
                    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                        Calendar start = Calendar.getInstance();
                        start.set(Calendar.YEAR, year);
                        start.set(Calendar.MONTH, monthOfYear);
                        start.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                        start.set(Calendar.HOUR, start.getMinimum(Calendar.HOUR));
                        start.set(Calendar.MINUTE, start.getMinimum(Calendar.MINUTE));
                        start.set(Calendar.SECOND, start.getMinimum(Calendar.SECOND));
                        start.set(Calendar.MILLISECOND, start.getMinimum(Calendar.MILLISECOND));
                        SharedPreferences.Editor ed = preferences.edit();
                        ed.putLong(START_DATE, start.getTime().getTime());
                        ed.commit();

                        new DatePickerDialog(Tasks.this, new DatePickerDialog.OnDateSetListener() {
                            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                                Calendar end = Calendar.getInstance();
                                end.set(Calendar.YEAR, year);
                                end.set(Calendar.MONTH, monthOfYear);
                                end.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                                end.set(Calendar.HOUR, end.getMaximum(Calendar.HOUR));
                                end.set(Calendar.MINUTE, end.getMaximum(Calendar.MINUTE));
                                end.set(Calendar.SECOND, end.getMaximum(Calendar.SECOND));
                                end.set(Calendar.MILLISECOND, end.getMaximum(Calendar.MILLISECOND));
                                SharedPreferences.Editor ed = preferences.edit();
                                ed.putLong(END_DATE, end.getTime().getTime());
                                ed.commit();
                                Tasks.this.switchView(5); // Update the list view
                            }
                        }, year, monthOfYear, dayOfMonth).show();
                    }
                }, calInstance.get(Calendar.YEAR), calInstance.get(Calendar.MONTH),
                        calInstance.get(Calendar.DAY_OF_MONTH)).show();
            } else {
                switchView(which);
            }
        }
    }).create();
}

From source file:org.apache.roller.weblogger.ui.core.tags.calendar.CalendarTag.java

/**
 * Write to a PrintWriter so that tag may be used from Velocity
 */// w w  w  . j  a v a  2  s . c om
public int doStartTag(PrintWriter pw) throws JspException {
    try {
        // build week day names
        this.buildDayNames();

        Date day = null; // day to be displayed
        Calendar dayCal; // set to day to be displayed
        Calendar cal; // for iterating through days of month
        Calendar todayCal; // for iterating through days of month
        CalendarModel model; // the calendar model

        // ---------------------------------
        // --- initialize date variables ---
        // ---------------------------------

        // check for parameter map and target url
        StringTokenizer toker = new StringTokenizer(mModelName, ".");
        String tok1 = toker.nextToken();
        if (toker.hasMoreTokens()) {
            String tok2 = toker.nextToken();
            Object bean = pageContext.findAttribute(tok1);
            model = (CalendarModel) PropertyUtils.getProperty(bean, tok2);
        } else {
            model = (CalendarModel) pageContext.findAttribute(mModelName);
        }

        // no model specified, nothing to generate
        if (model == null) {
            return SKIP_BODY;
        }

        day = model.getDay();

        // ceate object to represent today
        todayCal = model.getCalendar();
        todayCal.setTime(new Date());

        // formatter Month-Year title of calendar
        SimpleDateFormat formatTitle = new SimpleDateFormat("MMMM yyyy", mLocale);

        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

        // get Resource Bundle
        ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources", mLocale);

        // go back to first day in month
        cal = model.getCalendar();
        day = DateUtil.getNoonOfDay(day, cal);
        cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DAY_OF_MONTH));

        // Go back to first day of week before that (Sunday in US, Monday in France, e.g.)
        // in the calendar
        while (cal.get(Calendar.DAY_OF_WEEK) != cal.getFirstDayOfWeek()) {
            cal.add(Calendar.DATE, -1);
        }

        // create table of 5 weeks, 7 days per row
        dayCal = model.getCalendar();
        dayCal.setTime(day);

        // -------------------------
        // --- draw the calendar ---
        // -------------------------
        pw.print("<table cellspacing=\"0\" border=\"0\" ");
        pw.print(" summary=\"" + bundle.getString("calendar.summary") + "\" class=\"hCalendarTable"
                + mClassSuffix + "\">");
        pw.print("<tr>");
        pw.print(
                "<td colspan=\"7\" align=\"center\" " + "class=\"hCalendarMonthYearRow" + mClassSuffix + "\">");
        if (model.getPrevMonth() != null) {
            pw.print("<a href=\"" + model.computePrevMonthUrl() + "\" title=\""
                    + bundle.getString("calendar.prev") + "\" class=\"hCalendarNavBar\">&laquo;</a> ");
        }
        pw.print(formatTitle.format(day));
        if (model.getNextMonth() != null) {
            pw.print(" <a href=\"" + model.computeNextMonthUrl() + "\" title=\""
                    + bundle.getString("calendar.next") + "\" class=\"hCalendarNavBar\">&raquo;</a>");
        }
        pw.print("</td></tr>");

        // emit the HTML calendar
        for (int w = -1; w < 6; w++) {
            pw.print("<tr>");
            for (int d = 0; d < 7; d++) {
                if (w == -1) {
                    pw.print("<th class=\"hCalendarDayNameRow" + mClassSuffix + "\" align=\"center\">");
                    pw.print(mDayNames[d]);
                    pw.print("</th>");
                    continue;
                }

                // determine URL for this calendar day
                Date tddate = cal.getTime();
                String url = model.computeUrl(tddate, false, false);
                String content = model.getContent(tddate);

                if // day is in calendar month
                ((cal.get(Calendar.MONTH) == dayCal.get(Calendar.MONTH))
                        && (cal.get(Calendar.YEAR) == dayCal.get(Calendar.YEAR))) {
                    if // day is today then use today style
                    ((cal.get(Calendar.DAY_OF_MONTH) == todayCal.get(Calendar.DAY_OF_MONTH))
                            && (cal.get(Calendar.MONTH) == todayCal.get(Calendar.MONTH))
                            && (cal.get(Calendar.YEAR) == todayCal.get(Calendar.YEAR))) {
                        printToday(pw, cal, url, content);
                    } else {
                        printDayInThisMonth(pw, cal, url, content);
                    }
                } else // apply day-not-in-month style ;-)
                {
                    printDayNotInMonth(pw, cal);
                }

                // increment calendar by one day
                cal.add(Calendar.DATE, 1);
            }
            pw.print("</tr>");
        }

        pw.print("<tr class=\"hCalendarNextPrev" + mClassSuffix + "\">");
        pw.print("<td colspan=\"7\" align=\"center\">");

        pw.print("<a href=\"" + model.computeTodayMonthUrl() + "\" class=\"hCalendarNavBar\">"
                + bundle.getString("calendar.today") + "</a>");

        pw.print("</td>");
        pw.print("</tr>");

        pw.print("</table>");
    } catch (Exception e) {
        pw.print("<span class=\"error\">");
        pw.print("<p><b>An ERROR has occured CalendarTag</b></p>");
        pw.print("</span>");
        mLogger.error("Calendar tag exception", e);
    }
    return Tag.SKIP_BODY;
}

From source file:egovframework.oe1.cms.cmm.web.EgovOe1SchdulManageController.java

/**
 *  ? /*from  w  w w.  j ava2 s  . c  om*/
 * @param searchVO
 * @param commandMap
 * @param deptSchdulManageVO
 * @param model
 * @return "/cms/cmm/EgovSchdulManageWeekList"
 * @throws Exception
 */
@RequestMapping(value = "/cms/cmm/EgovOe1SchdulManageWeekList.do")
public String EgovDeptSchdulManageWeekList(@ModelAttribute("searchVO") EgovOe1ComDefaultVO searchVO,
        Map commandMap, EgovOe1SchdulManageVO deptSchdulManageVO, ModelMap model) throws Exception {
    //Spring Security
    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
    if (!isAuthenticated) {
        return "/cms/com/EgovLoginUsr"; //? ??
    }

    //?  
    model.addAttribute("searchKeyword",
            commandMap.get("searchKeyword") == null ? "" : (String) commandMap.get("searchKeyword"));
    model.addAttribute("searchCondition",
            commandMap.get("searchCondition") == null ? "" : (String) commandMap.get("searchCondition"));

    // ?
    EgovOe1ComDefaultCodeVO vo = new EgovOe1ComDefaultCodeVO();
    vo.setCodeId("OE1028");
    List schdulSeCode_result = cmmUseService.selectCmmCodeDetail(vo);
    model.addAttribute("schdulSeCode_result", schdulSeCode_result);

    // ?
    vo = new EgovOe1ComDefaultCodeVO();
    vo.setCodeId("OE1008");
    List year_result = cmmUseService.selectCmmCodeDetail(vo);
    model.addAttribute("year_result", year_result);

    // 
    vo = new EgovOe1ComDefaultCodeVO();
    vo.setCodeId("OE1013");
    List month_result = cmmUseService.selectCmmCodeDetail(vo);
    model.addAttribute("month_result", month_result);

    /* *****************************************************************
     // ?  ?
    ****************************************************************** */
    Calendar calNow = Calendar.getInstance();
    Calendar calBefore = Calendar.getInstance();
    Calendar calNext = Calendar.getInstance();

    String strYear = deptSchdulManageVO.getSearchYear();
    String strMonth = deptSchdulManageVO.getSearchMonth();
    String strWeek = deptSchdulManageVO.getSearchWeek();
    String strSchdulSeCode = deptSchdulManageVO.getSearchSchdulSeCode();

    int iNowYear = 0;
    int iNowMonth = 0;
    int iNowDate = 0;
    int iNowWeek = 0;

    if ((strYear != null && !"".equals(strYear)) && (strMonth != null && !"".equals(strMonth))
            && (strWeek != null && !"".equals(strWeek))) {
        iNowYear = Integer.parseInt(strYear);
        iNowMonth = Integer.parseInt(strMonth);
        iNowWeek = Integer.parseInt(strWeek);
    } else {
        iNowYear = calNow.get(Calendar.YEAR);
        iNowMonth = (calNow.get(Calendar.MONTH) + 1);
        iNowDate = calNow.get(Calendar.DATE);
    }

    //System.out.println("strYear=====>"   + strYear);
    //System.out.println("strMonth=====>"   + strMonth);
    //System.out.println("strWeek=====>"   + strWeek);
    //System.out.println("iNowYear=====>"   + iNowYear);
    //System.out.println("iNowMonth=====>"+ iNowMonth);
    //System.out.println("iNowDate=====>"   + iNowDate);
    //System.out.println("Calendar.WEEK_OF_MONTH==>"+Calendar.WEEK_OF_MONTH);

    //?/ 
    calNow.set(iNowYear, iNowMonth - 1, 1);
    calBefore.set(iNowYear, iNowMonth - 1, 1);
    calNext.set(iNowYear, iNowMonth - 1, 1);

    calBefore.add(Calendar.MONTH, -1);
    calNext.add(Calendar.MONTH, +1);

    int startDay = calNow.getMinimum(Calendar.DATE);
    int endDay = calNow.getActualMaximum(Calendar.DAY_OF_MONTH);
    int startWeek = calNow.get(Calendar.DAY_OF_WEEK);

    //System.out.println(" ?===>"+startWeek);

    ArrayList listWeekGrop = new ArrayList();
    ArrayList listWeekDate = new ArrayList();

    String sUseDate = "";

    calBefore.add(Calendar.DATE, calBefore.getActualMaximum(Calendar.DAY_OF_MONTH) - (startWeek - 1));
    for (int i = 1; i < startWeek; i++) {
        sUseDate = Integer.toString(calBefore.get(Calendar.YEAR));
        sUseDate += DateTypeIntForString(calBefore.get(Calendar.MONTH) + 1);
        sUseDate += DateTypeIntForString(calBefore.get(Calendar.DATE));
        listWeekDate.add(sUseDate);
        calBefore.add(Calendar.DATE, +1);
    }

    int iBetweenCount = startWeek;

    //  ?. BETWEEN 
    for (int i = 1; i <= endDay; i++) {
        sUseDate = Integer.toString(iNowYear);
        sUseDate += Integer.toString(iNowMonth).length() == 1 ? "0" + Integer.toString(iNowMonth)
                : Integer.toString(iNowMonth);
        sUseDate += Integer.toString(i).length() == 1 ? "0" + Integer.toString(i) : Integer.toString(i);

        listWeekDate.add(sUseDate);

        if (iBetweenCount % 7 == 0) {
            listWeekGrop.add(listWeekDate);
            listWeekDate = new ArrayList();

            if ((strYear == null || "".equals(strYear)) && i < iNowDate) {
                iNowWeek++;
            }
        }

        // 7? ??
        if (i == endDay) {

            for (int j = listWeekDate.size(); j < 7; j++) {
                String sUseNextDate = Integer.toString(calNext.get(Calendar.YEAR));
                sUseNextDate += DateTypeIntForString(calNext.get(Calendar.MONTH) + 1);
                sUseNextDate += DateTypeIntForString(calNext.get(Calendar.DATE));
                listWeekDate.add(sUseNextDate);
                calNext.add(Calendar.DATE, +1);
            }

            listWeekGrop.add(listWeekDate);
        }

        iBetweenCount++;
    }

    model.addAttribute("year", iNowYear + "");
    model.addAttribute("month", ((iNowMonth) + "").length() == 1 ? "0" + (iNowMonth) : (iNowMonth));
    model.addAttribute("week", iNowWeek + "");
    model.addAttribute("dayOfMonth", (Calendar.WEEK_OF_MONTH) + "");

    model.addAttribute("listWeekGrop", listWeekGrop);

    List listWeek = (List) listWeekGrop.get(iNowWeek);
    commandMap.put("searchMode", "WEEK");
    commandMap.put("schdulBgnde", (String) listWeek.get(0));
    commandMap.put("schdulEndde", (String) listWeek.get(listWeek.size() - 1));
    commandMap.put("searchSchdulSeCode", strSchdulSeCode);

    String sNowMonth = "";
    if (((iNowMonth) + "").length() == 1) {
        sNowMonth = "0" + (iNowMonth);
    } else {
        sNowMonth = (iNowMonth) + "";
    }
    deptSchdulManageVO.setSearchYear(iNowYear + "");
    deptSchdulManageVO.setSearchMonth(sNowMonth);
    deptSchdulManageVO.setSearchWeek(iNowWeek + "");

    //?   ?   ??.
    model.addAttribute("searchMode", deptSchdulManageVO);

    List resultList = egovDeptSchdulManageService.selectDeptSchdulManageRetrieve(commandMap);
    model.addAttribute("resultList", resultList);

    return "/cms/cmm/EgovSchdulManageWeekList";
}

From source file:org.alfresco.solr.query.Solr4QueryParser.java

private Pair<Date, Integer> parseDateString(String dateString) {
    try {//from  ww  w.jav  a 2s.  c om
        Pair<Date, Integer> result = CachingDateFormat.lenientParse(dateString, Calendar.YEAR);
        return result;
    } catch (java.text.ParseException e) {
        SimpleDateFormat oldDf = CachingDateFormat.getDateFormat();
        try {
            Date date = oldDf.parse(dateString);
            return new Pair<Date, Integer>(date, Calendar.SECOND);
        } catch (java.text.ParseException ee) {
            if (dateString.equalsIgnoreCase("min")) {
                Calendar cal = Calendar.getInstance(I18NUtil.getLocale());
                cal.set(Calendar.YEAR, cal.getMinimum(Calendar.YEAR));
                cal.set(Calendar.DAY_OF_YEAR, cal.getMinimum(Calendar.DAY_OF_YEAR));
                cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
                cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
                cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
                cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
                return new Pair<Date, Integer>(cal.getTime(), Calendar.MILLISECOND);
            } else if (dateString.equalsIgnoreCase("now")) {
                return new Pair<Date, Integer>(new Date(), Calendar.MILLISECOND);
            } else if (dateString.equalsIgnoreCase("today")) {
                Calendar cal = Calendar.getInstance(I18NUtil.getLocale());
                cal.setTime(new Date());
                cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
                cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
                cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
                cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
                return new Pair<Date, Integer>(cal.getTime(), Calendar.DAY_OF_MONTH);
            } else if (dateString.equalsIgnoreCase("max")) {
                Calendar cal = Calendar.getInstance(I18NUtil.getLocale());
                cal.set(Calendar.YEAR, cal.getMaximum(Calendar.YEAR));
                cal.set(Calendar.DAY_OF_YEAR, cal.getMaximum(Calendar.DAY_OF_YEAR));
                cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY));
                cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE));
                cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND));
                cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
                return new Pair<Date, Integer>(cal.getTime(), Calendar.MILLISECOND);
            } else {
                return null; // delegate to SOLR date parsing
            }
        }
    }
}

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneQueryParser.java

private Query buildEnd(String field, Calendar cal, int startField, int padField, int resolutionField) {
    BooleanQuery range = new BooleanQuery();
    Query part;//  w w w. j  a v  a2 s .  com

    switch (startField) {
    case Calendar.YEAR:
        if (padField == Calendar.YEAR) {
            if (Calendar.YEAR < resolutionField) {
                if (cal.get(Calendar.YEAR) > cal.getMinimum(Calendar.YEAR)) {
                    part = new ConstantScoreRangeQuery(field, "YE" + cal.getMinimum(Calendar.YEAR),
                            "YE" + (cal.get(Calendar.YEAR) - 1), true, true);
                    range.add(part, Occur.MUST);
                } else {
                    return null;
                }
            } else if (Calendar.YEAR == resolutionField) {
                part = new ConstantScoreRangeQuery(field, "YE" + cal.getMinimum(Calendar.YEAR),
                        "YE" + (cal.get(Calendar.YEAR)), true, true);
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
            break;
        } else {
            if (Calendar.YEAR <= resolutionField) {
                part = new TermQuery(new Term(field, "YE" + cal.get(Calendar.YEAR)));
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
        }
    case Calendar.MONTH:
        if (padField == Calendar.MONTH) {
            if (Calendar.MONTH < resolutionField) {
                if (cal.get(Calendar.MONTH) > cal.getMinimum(Calendar.MONTH)) {
                    part = new ConstantScoreRangeQuery(field, build2SF("MO", cal.getMinimum(Calendar.MONTH)),
                            build2SF("MO", (cal.get(Calendar.MONTH) - 1)), true, true);
                    range.add(part, Occur.MUST);
                } else {
                    return null;
                }
            } else if (Calendar.MONTH == resolutionField) {
                part = new ConstantScoreRangeQuery(field, build2SF("MO", cal.getMinimum(Calendar.MONTH)),
                        build2SF("MO", (cal.get(Calendar.MONTH))), true, true);
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
            break;
        } else {
            if (Calendar.MONTH <= resolutionField) {
                part = new TermQuery(new Term(field, build2SF("MO", cal.get(Calendar.MONTH))));
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
        }
    case Calendar.DAY_OF_MONTH:
        if (padField == Calendar.DAY_OF_MONTH) {
            if (Calendar.DAY_OF_MONTH < resolutionField) {
                if (cal.get(Calendar.DAY_OF_MONTH) > cal.getMinimum(Calendar.DAY_OF_MONTH)) {
                    part = new ConstantScoreRangeQuery(field,
                            build2SF("DA", cal.getMinimum(Calendar.DAY_OF_MONTH)),
                            build2SF("DA", (cal.get(Calendar.DAY_OF_MONTH) - 1)), true, true);
                    range.add(part, Occur.MUST);
                } else {
                    return null;
                }
            } else if (Calendar.DAY_OF_MONTH == resolutionField) {
                part = new ConstantScoreRangeQuery(field, build2SF("DA", cal.getMinimum(Calendar.DAY_OF_MONTH)),
                        build2SF("DA", (cal.get(Calendar.DAY_OF_MONTH))), true, true);
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
            break;
        } else {
            if (Calendar.DAY_OF_MONTH <= resolutionField) {
                part = new TermQuery(new Term(field, build2SF("DA", cal.get(Calendar.DAY_OF_MONTH))));
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
        }
    case Calendar.HOUR_OF_DAY:
        if (padField == Calendar.HOUR_OF_DAY) {
            if (Calendar.HOUR_OF_DAY < resolutionField) {
                if (cal.get(Calendar.HOUR_OF_DAY) > cal.getMinimum(Calendar.HOUR_OF_DAY)) {
                    part = new ConstantScoreRangeQuery(field,
                            build2SF("HO", cal.getMinimum(Calendar.HOUR_OF_DAY)),
                            build2SF("HO", (cal.get(Calendar.HOUR_OF_DAY) - 1)), true, true);
                    range.add(part, Occur.MUST);
                } else {
                    return null;
                }

            } else if (Calendar.HOUR_OF_DAY == resolutionField) {
                part = new ConstantScoreRangeQuery(field, build2SF("HO", cal.getMinimum(Calendar.HOUR_OF_DAY)),
                        build2SF("HO", (cal.get(Calendar.HOUR_OF_DAY))), true, true);
                range.add(part, Occur.MUST);

            } else {
                return null;
            }
            break;
        } else {
            if (Calendar.HOUR_OF_DAY <= resolutionField) {
                part = new TermQuery(new Term(field, build2SF("HO", cal.get(Calendar.HOUR_OF_DAY))));
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
        }
    case Calendar.MINUTE:
        if (padField == Calendar.MINUTE) {
            if (Calendar.MINUTE < resolutionField) {
                if (cal.get(Calendar.MINUTE) > cal.getMinimum(Calendar.MINUTE)) {
                    part = new ConstantScoreRangeQuery(field, build2SF("MI", cal.getMinimum(Calendar.MINUTE)),
                            build2SF("MI", (cal.get(Calendar.MINUTE) - 1)), true, true);
                    range.add(part, Occur.MUST);
                } else {
                    return null;
                }
            } else if (Calendar.MINUTE == resolutionField) {
                part = new ConstantScoreRangeQuery(field, build2SF("MI", cal.getMinimum(Calendar.MINUTE)),
                        build2SF("MI", (cal.get(Calendar.MINUTE))), true, true);
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
            break;
        } else {
            if (Calendar.MINUTE <= resolutionField) {
                part = new TermQuery(new Term(field, build2SF("MI", cal.get(Calendar.MINUTE))));
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
        }
    case Calendar.SECOND:
        if (padField == Calendar.SECOND) {
            if (Calendar.SECOND < resolutionField) {
                if (cal.get(Calendar.SECOND) > cal.getMinimum(Calendar.SECOND)) {
                    part = new ConstantScoreRangeQuery(field, build2SF("SE", cal.getMinimum(Calendar.SECOND)),
                            build2SF("SE", (cal.get(Calendar.SECOND) - 1)), true, true);
                    range.add(part, Occur.MUST);
                } else {
                    return null;
                }
            } else if (Calendar.SECOND == resolutionField) {
                part = new ConstantScoreRangeQuery(field, build2SF("SE", cal.getMinimum(Calendar.SECOND)),
                        build2SF("SE", (cal.get(Calendar.SECOND))), true, true);
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
            break;
        }

        else {
            if (Calendar.SECOND <= resolutionField) {
                part = new TermQuery(new Term(field, build2SF("SE", cal.get(Calendar.SECOND))));
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
        }
    case Calendar.MILLISECOND:
        if ((cal.get(Calendar.MILLISECOND) >= cal.getMinimum(Calendar.MILLISECOND))
                && (cal.get(Calendar.MILLISECOND) < cal.getMaximum(Calendar.MILLISECOND))) {
            if (Calendar.MILLISECOND <= resolutionField) {
                part = new ConstantScoreRangeQuery(field, build3SF("MS", cal.getMinimum(Calendar.MILLISECOND)),
                        build3SF("MS", cal.get(Calendar.MILLISECOND)), true, true);
                range.add(part, Occur.MUST);
            } else {
                break;
            }
        }
    default:
    }

    return getNonEmptyBooleanQuery(range);
}

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneQueryParser.java

/**
 * @param field String//from ww w .j a v a 2 s .  c  om
 * @param part1 String
 * @param part2 String
 * @param includeLower boolean
 * @param includeUpper boolean
 * @param analysisMode AnalysisMode
 * @param luceneFunction LuceneFunction
 * @return the query
 * @exception ParseException
 *                throw in overridden method to disallow
 */
public Query getRangeQuery(String field, String part1, String part2, boolean includeLower, boolean includeUpper,
        AnalysisMode analysisMode, LuceneFunction luceneFunction) throws ParseException {
    if (field.equals(FIELD_PATH)) {
        throw new UnsupportedOperationException("Range Queries are not support for " + FIELD_PATH);
    } else if (field.equals(FIELD_PATHWITHREPEATS)) {
        throw new UnsupportedOperationException("Range Queries are not support for " + FIELD_PATHWITHREPEATS);
    } else if (field.equals(FIELD_TEXT)) {
        Set<String> text = searchParameters.getTextAttributes();
        if ((text == null) || (text.size() == 0)) {
            Query query = getRangeQuery(PROPERTY_FIELD_PREFIX + ContentModel.PROP_CONTENT.toString(), part1,
                    part2, includeLower, includeUpper, analysisMode, luceneFunction);
            if (query == null) {
                return createNoMatchQuery();
            }

            return query;
        } else {
            BooleanQuery query = new BooleanQuery();
            for (String fieldName : text) {
                Query part = getRangeQuery(fieldName, part1, part2, includeLower, includeUpper, analysisMode,
                        luceneFunction);
                if (part != null) {
                    query.add(part, Occur.SHOULD);
                } else {
                    query.add(createNoMatchQuery(), Occur.SHOULD);
                }
            }
            return query;
        }

    }
    // FIELD_ID uses the default
    // FIELD_DBID uses the default
    // FIELD_ISROOT uses the default
    // FIELD_ISCONTAINER uses the default
    // FIELD_ISNODE uses the default
    // FIELD_TX uses the default
    // FIELD_PARENT uses the default
    // FIELD_PRIMARYPARENT uses the default
    // FIELD_QNAME uses the default
    // FIELD_PRIMARYASSOCTYPEQNAME uses the default
    // FIELD_ASSOCTYPEQNAME uses the default
    // FIELD_CLASS uses the default
    // FIELD_TYPE uses the default
    // FIELD_EXACTTYPE uses the default
    // FIELD_ASPECT uses the default
    // FIELD_EXACTASPECT uses the default
    // FIELD_TYPE uses the default
    // FIELD_TYPE uses the default
    if (field.startsWith(PROPERTY_FIELD_PREFIX)) {
        String fieldName;
        PropertyDefinition propertyDef = matchPropertyDefinition(field.substring(1));
        if (propertyDef != null) {
            fieldName = PROPERTY_FIELD_PREFIX + propertyDef.getName();
        } else {
            fieldName = expandAttributeFieldName(field);
        }

        IndexTokenisationMode tokenisationMode = IndexTokenisationMode.TRUE;
        if (propertyDef != null) {
            tokenisationMode = propertyDef.getIndexTokenisationMode();
            if (tokenisationMode == null) {
                tokenisationMode = IndexTokenisationMode.TRUE;
            }
        }

        if (propertyDef != null) {
            // LOWER AND UPPER
            if (luceneFunction != LuceneFunction.FIELD) {
                if (luceneFunction == LuceneFunction.LOWER) {
                    if ((false == part1.toLowerCase().equals(part1))
                            || (false == part2.toLowerCase().equals(part2))) {
                        return createNoMatchQuery();
                    }
                }

                if (luceneFunction == LuceneFunction.UPPER) {
                    if ((false == part1.toUpperCase().equals(part1))
                            || (false == part2.toUpperCase().equals(part2))) {
                        return createNoMatchQuery();
                    }
                }

                if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT)) {
                    BooleanQuery booleanQuery = new BooleanQuery();
                    MLAnalysisMode mlAnalysisMode = searchParameters.getMlAnalaysisMode() == null
                            ? defaultSearchMLAnalysisMode
                            : searchParameters.getMlAnalaysisMode();
                    List<Locale> locales = searchParameters.getLocales();
                    List<Locale> expandedLocales = new ArrayList<Locale>();
                    for (Locale locale : (((locales == null) || (locales.size() == 0))
                            ? Collections.singletonList(I18NUtil.getLocale())
                            : locales)) {
                        expandedLocales.addAll(MLAnalysisMode.getLocales(mlAnalysisMode, locale, false));
                    }
                    for (Locale locale : (((expandedLocales == null) || (expandedLocales.size() == 0))
                            ? Collections.singletonList(I18NUtil.getLocale())
                            : expandedLocales)) {
                        addLocaleSpecificUntokenisedTextRangeFunction(fieldName, part1, part2, includeLower,
                                includeUpper, luceneFunction, booleanQuery, mlAnalysisMode, locale,
                                tokenisationMode);
                    }
                    return booleanQuery;
                } else {
                    throw new UnsupportedOperationException("Lucene Function");
                }
            }

            if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT)) {
                throw new UnsupportedOperationException("Range is not supported against ml-text");
            } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT)) {
                throw new UnsupportedOperationException("Range is not supported against content");
            } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT)) {
                BooleanQuery booleanQuery = new BooleanQuery();
                MLAnalysisMode mlAnalysisMode = searchParameters.getMlAnalaysisMode() == null
                        ? defaultSearchMLAnalysisMode
                        : searchParameters.getMlAnalaysisMode();
                List<Locale> locales = searchParameters.getLocales();
                List<Locale> expandedLocales = new ArrayList<Locale>();
                for (Locale locale : (((locales == null) || (locales.size() == 0))
                        ? Collections.singletonList(I18NUtil.getLocale())
                        : locales)) {
                    expandedLocales.addAll(MLAnalysisMode.getLocales(mlAnalysisMode, locale, false));
                }
                for (Locale locale : (((expandedLocales == null) || (expandedLocales.size() == 0))
                        ? Collections.singletonList(I18NUtil.getLocale())
                        : expandedLocales)) {

                    addTextRange(field, part1, part2, includeLower, includeUpper, analysisMode, fieldName,
                            propertyDef, tokenisationMode, booleanQuery, mlAnalysisMode, locale);

                }
                return booleanQuery;
            } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME)) {
                String analyserClassName = propertyDef.resolveAnalyserClassName();
                boolean usesDateTimeAnalyser = analyserClassName
                        .equals(DateTimeAnalyser.class.getCanonicalName());
                // Expand query for internal date time format

                if (usesDateTimeAnalyser) {
                    Calendar start = Calendar.getInstance();
                    int startResolution;
                    Calendar end = Calendar.getInstance();
                    int endResolution;
                    try {
                        Pair<Date, Integer> result = CachingDateFormat.lenientParse(part1, Calendar.YEAR);
                        start.setTime(result.getFirst());
                        startResolution = result.getSecond();
                    } catch (java.text.ParseException e) {
                        SimpleDateFormat oldDf = CachingDateFormat.getDateFormat();
                        try {
                            Date date = oldDf.parse(part1);
                            start.setTime(date);
                            start.set(Calendar.MILLISECOND, 0);
                            startResolution = Calendar.SECOND;
                        } catch (java.text.ParseException ee) {
                            if (part1.equalsIgnoreCase("min")) {
                                start.set(Calendar.YEAR, start.getMinimum(Calendar.YEAR));
                                start.set(Calendar.DAY_OF_YEAR, start.getMinimum(Calendar.DAY_OF_YEAR));
                                start.set(Calendar.HOUR_OF_DAY, start.getMinimum(Calendar.HOUR_OF_DAY));
                                start.set(Calendar.MINUTE, start.getMinimum(Calendar.MINUTE));
                                start.set(Calendar.SECOND, start.getMinimum(Calendar.SECOND));
                                start.set(Calendar.MILLISECOND, start.getMinimum(Calendar.MILLISECOND));
                                startResolution = Calendar.MILLISECOND;
                            } else if (part1.equalsIgnoreCase("now")) {
                                start.setTime(new Date());
                                startResolution = Calendar.MILLISECOND;
                            } else if (part1.equalsIgnoreCase("today")) {
                                start.setTime(new Date());
                                start.set(Calendar.HOUR_OF_DAY, start.getMinimum(Calendar.HOUR_OF_DAY));
                                start.set(Calendar.MINUTE, start.getMinimum(Calendar.MINUTE));
                                start.set(Calendar.SECOND, start.getMinimum(Calendar.SECOND));
                                start.set(Calendar.MILLISECOND, start.getMinimum(Calendar.MILLISECOND));
                                startResolution = Calendar.DAY_OF_MONTH;

                            } else {
                                return createNoMatchQuery();
                            }
                        }
                    }
                    try {
                        Pair<Date, Integer> result = CachingDateFormat.lenientParse(part2, Calendar.YEAR);
                        end.setTime(result.getFirst());
                        endResolution = result.getSecond();
                    } catch (java.text.ParseException e) {
                        SimpleDateFormat oldDf = CachingDateFormat.getDateFormat();
                        try {
                            Date date = oldDf.parse(part2);
                            end.setTime(date);
                            end.set(Calendar.MILLISECOND, 0);
                            endResolution = Calendar.SECOND;
                        } catch (java.text.ParseException ee) {
                            if (part2.equalsIgnoreCase("max")) {
                                end.set(Calendar.YEAR, end.getMaximum(Calendar.YEAR));
                                end.set(Calendar.DAY_OF_YEAR, end.getMaximum(Calendar.DAY_OF_YEAR));
                                end.set(Calendar.HOUR_OF_DAY, end.getMaximum(Calendar.HOUR_OF_DAY));
                                end.set(Calendar.MINUTE, end.getMaximum(Calendar.MINUTE));
                                end.set(Calendar.SECOND, end.getMaximum(Calendar.SECOND));
                                end.set(Calendar.MILLISECOND, end.getMaximum(Calendar.MILLISECOND));
                                endResolution = Calendar.MILLISECOND;
                            } else if (part2.equalsIgnoreCase("now")) {
                                end.setTime(new Date());
                                endResolution = Calendar.MILLISECOND;
                            } else if (part2.equalsIgnoreCase("today")) {
                                end.setTime(new Date());
                                end.set(Calendar.HOUR_OF_DAY, end.getMinimum(Calendar.HOUR_OF_DAY));
                                end.set(Calendar.MINUTE, end.getMinimum(Calendar.MINUTE));
                                end.set(Calendar.SECOND, end.getMinimum(Calendar.SECOND));
                                end.set(Calendar.MILLISECOND, end.getMinimum(Calendar.MILLISECOND));
                                endResolution = Calendar.DAY_OF_MONTH;
                            } else {
                                return createNoMatchQuery();
                            }
                        }
                    }

                    // Build a composite query for all the bits
                    Query rq = buildDateTimeRange(fieldName, start, startResolution, end, endResolution,
                            includeLower, includeUpper);
                    return rq;
                } else {
                    // Old Date time
                    String first = getToken(fieldName, part1, AnalysisMode.DEFAULT);
                    String last = getToken(fieldName, part2, AnalysisMode.DEFAULT);
                    return new ConstantScoreRangeQuery(fieldName, first, last, includeLower, includeUpper);
                }
            } else {
                // Default property behaviour
                String first = getToken(fieldName, part1, AnalysisMode.DEFAULT);
                String last = getToken(fieldName, part2, AnalysisMode.DEFAULT);
                return new ConstantScoreRangeQuery(fieldName, first, last, includeLower, includeUpper);
            }
        } else {
            // No DD def
            String first = getToken(fieldName, part1, AnalysisMode.DEFAULT);
            String last = getToken(fieldName, part2, AnalysisMode.DEFAULT);
            return new ConstantScoreRangeQuery(fieldName, first, last, includeLower, includeUpper);
        }
    } else if (field.equals(FIELD_ALL)) {
        Set<String> all = searchParameters.getAllAttributes();
        if ((all == null) || (all.size() == 0)) {
            Collection<QName> contentAttributes = dictionaryService.getAllProperties(null);
            BooleanQuery query = new BooleanQuery();
            for (QName qname : contentAttributes) {
                Query part = getRangeQuery(PROPERTY_FIELD_PREFIX + qname.toString(), part1, part2, includeLower,
                        includeUpper, analysisMode, luceneFunction);
                query.add(part, Occur.SHOULD);
            }
            return query;
        } else {
            BooleanQuery query = new BooleanQuery();
            for (String fieldName : all) {
                Query part = getRangeQuery(fieldName, part1, part2, includeLower, includeUpper, analysisMode,
                        luceneFunction);
                query.add(part, Occur.SHOULD);
            }
            return query;
        }

    }
    // FIELD_ISUNSET uses the default
    // FIELD_ISNULL uses the default
    // FIELD_ISNOTNULL uses the default
    else if (matchDataTypeDefinition(field) != null) {
        Collection<QName> contentAttributes = dictionaryService
                .getAllProperties(matchDataTypeDefinition(field).getName());
        BooleanQuery query = new BooleanQuery();
        for (QName qname : contentAttributes) {
            Query part = getRangeQuery(PROPERTY_FIELD_PREFIX + qname.toString(), part1, part2, includeLower,
                    includeUpper, analysisMode, luceneFunction);
            query.add(part, Occur.SHOULD);
        }
        return query;
    }
    // FIELD_FTSSTATUS uses the default
    if (field.equals(FIELD_TAG)) {
        throw new UnsupportedOperationException("Range Queries are not support for " + FIELD_TAG);
    } else {
        // None property - leave alone
        if (getLowercaseExpandedTerms()) {
            part1 = part1.toLowerCase();
            part2 = part2.toLowerCase();
        }
        return new ConstantScoreRangeQuery(field, part1, part2, includeLower, includeUpper);
    }
}