Example usage for java.util Date getMonth

List of usage examples for java.util Date getMonth

Introduction

In this page you can find the example usage for java.util Date getMonth.

Prototype

@Deprecated
public int getMonth() 

Source Link

Document

Returns a number representing the month that contains or begins with the instant in time represented by this Date object.

Usage

From source file:org.skt.runtime.html5apis.contacts.ContactAccessorSdk5.java

/**
 * Take the search criteria passed into the method and create a SQL WHERE clause.
 * @param fields the properties to search against
 * @param searchTerm the string to search for
 * @return an object containing the selection and selection args
 *///from w  w w  .  j  a  va  2 s.  c  o  m
private WhereOptions buildWhereClause(JSONArray fields, String searchTerm) {

    ArrayList<String> where = new ArrayList<String>();
    ArrayList<String> whereArgs = new ArrayList<String>();

    WhereOptions options = new WhereOptions();

    /*
     * Special case where the user wants all fields returned
     */
    if (isWildCardSearch(fields)) {
        // Get all contacts with all properties
        if ("%".equals(searchTerm)) {
            options.setWhere("(" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? )");
            options.setWhereArgs(new String[] { searchTerm });
            return options;
        } else {
            // Get all contacts that match the filter but return all properties 
            where.add("(" + dbMap.get("displayName") + " LIKE ? )");
            whereArgs.add(searchTerm);
            where.add("(" + dbMap.get("name") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("nickname") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("phoneNumbers") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE
                    + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("emails") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
            where.add(
                    "(" + dbMap.get("addresses") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("ims") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("organizations") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE
                    + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("note") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("urls") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
        }
    }

    /*
     * Special case for when the user wants all the contacts but
     */
    if ("%".equals(searchTerm)) {
        options.setWhere("(" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? )");
        options.setWhereArgs(new String[] { searchTerm });
        return options;
    }

    String key;
    try {
        //Log.d(LOG_TAG, "How many fields do we have = " + fields.length());
        for (int i = 0; i < fields.length(); i++) {
            key = fields.getString(i);

            if (key.equals("id")) {
                where.add("(" + dbMap.get(key) + " = ? )");
                whereArgs.add(searchTerm.substring(1, searchTerm.length() - 1));
            } else if (key.startsWith("displayName")) {
                where.add("(" + dbMap.get(key) + " LIKE ? )");
                whereArgs.add(searchTerm);
            } else if (key.startsWith("name")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("nickname")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("phoneNumbers")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("emails")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("addresses")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("ims")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("organizations")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("birthday")) {
                try {
                    SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM dd, yyyy");
                    Date searchDate = format.parse(searchTerm.substring(1, searchTerm.length() - 1));
                    // Have to subtract one from the month as JavaScript's January is 01
                    // while Java's January is 00.
                    searchDate.setMonth(searchDate.getMonth() - 1);
                    SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd");

                    where.add("(" + dbMap.get(key) + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                    whereArgs.add(newFormat.format(searchDate));
                    whereArgs.add(ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE);
                } catch (ParseException e) {
                    Log.d(LOG_TAG, "Bad romance format");
                }
            } else if (key.startsWith("note")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("urls")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
            }
        }
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
    }

    // Creating the where string
    StringBuffer selection = new StringBuffer();
    for (int i = 0; i < where.size(); i++) {
        selection.append(where.get(i));
        if (i != (where.size() - 1)) {
            selection.append(" OR ");
        }
    }
    options.setWhere(selection.toString());

    // Creating the where args array
    String[] selectionArgs = new String[whereArgs.size()];
    for (int i = 0; i < whereArgs.size(); i++) {
        selectionArgs[i] = whereArgs.get(i);
    }
    options.setWhereArgs(selectionArgs);

    return options;
}

From source file:com.krawler.spring.crm.common.crmManagerDAOImpl.java

/**
 * To convert a date and time selected separately by user into corresponding combined datetime
 * from users selected timezone to systems timezone
 *
 * The first step is to keep track of the time difference in order to change the date if required.
 * Two time only objects dtold and dtcmp are created for this purpose.
 *
 * The date passed and the time passed that are in system timezone are formatted without
 * timezone and then parsed into the required timezone and then the time values are set
 * back to the date value sent./*  w ww.ja va  2s .c o  m*/
 *
 **/
public Date converttz(String timeZoneDiff, Date dt, String time) {
    Calendar cal = Calendar.getInstance();
    try {
        if (timeZoneDiff == null || timeZoneDiff.isEmpty()) {
            timeZoneDiff = "-7:00";
        }
        String val;
        SimpleDateFormat sdf = new SimpleDateFormat("HHmm 'Hrs'");
        Date dtold = sdf.parse("0000 Hrs");
        if (!time.endsWith("Hrs")) {
            sdf = new SimpleDateFormat("hh:mm a");
            dtold = sdf.parse("00:00 AM");
        }
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
        sdf2.setTimeZone(TimeZone.getTimeZone("GMT" + timeZoneDiff)); // Setting the timezone passed

        Date dt1 = sdf.parse(time); // Setting the passed time to the date object in system timezone

        sdf.setTimeZone(TimeZone.getTimeZone("GMT" + timeZoneDiff)); // Setting the timezone passed
        Date dtcmp = sdf.parse(time); // Parsing the time to timezone using passed values
        dt1.setMonth(dt.getMonth()); // Setting the date values sent to the system time only value
        dt1.setDate(dt.getDate());
        dt1.setYear(dt.getYear());
        dt1 = sdf2.parse(sdf1.format(dt1)); // Parsing datetime into required timezone
        dt.setHours(dt1.getHours()); // Setting the time values into the sent date
        dt.setMinutes(dt1.getMinutes());
        dt.setSeconds(0);
        cal.setTime(dt);
        if (dtcmp.compareTo(dtold) < 0) { // Comparing for time value change
            cal.add(Calendar.DATE, -1); //  in order to change the date accordingly
        }
        dtold.setDate(2);
        if (dtcmp.compareTo(dtold) > 0 || dtcmp.compareTo(dtold) == 0) {
            cal.add(Calendar.DATE, 1);
        }

    } catch (ParseException ex) {
        System.out.println(ex);
    } finally {
        return cal.getTime();
    }
}

From source file:com.android.mms.ui.MessageUtils.java

public static String getTimeDividerString(Context context, long when) {
    Time then = new Time();
    then.set(when);/*from  ww  w  . ja v  a  2s  .c  om*/
    Time now = new Time();
    now.setToNow();

    // Basic settings for formatDateTime() we want for all cases.
    int formatFlags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM;

    // If the message is from a different year, show the date and year.
    if (then.year != now.year) {
        formatFlags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    } else if (then.yearDay != now.yearDay) {
        // If it is from a different day than today, show only the date.
        formatFlags |= DateUtils.FORMAT_SHOW_DATE;
        Date curDate = new Date();
        Date cur = new Date(curDate.getYear(), curDate.getMonth(), curDate.getDate(), 0, 0, 0);
        long oneDay = 24 * 60 * 60 * 1000;
        long elapsedTime = cur.getTime() - when;
        if (elapsedTime < oneDay && elapsedTime > 0) {
            return context.getResources().getString(R.string.str_ipmsg_yesterday);
        }
    } else {
        return context.getString(R.string.str_ipmsg_today);
    }
    return DateUtils.formatDateTime(context, when, formatFlags);
}

From source file:com.android.mms.ui.MessageUtils.java

public static boolean shouldShowTimeDivider(long curTime, long nextTime) {
    Date curDate = new Date(curTime);
    Date nextDate = new Date(nextTime);
    Date cur = new Date(curDate.getYear(), curDate.getMonth(), curDate.getDate(), 0, 0, 0);
    Date next = new Date(nextDate.getYear(), nextDate.getMonth(), nextDate.getDate(), 0, 0, 0);
    return (cur.getTime() != next.getTime());
}

From source file:com.homeworkreminder.Main.java

@SuppressWarnings("deprecation")
private void initCalendarPage() {
    lastSelectedCalendarDate = Calendar.getInstance().getTime();
    calView = this.inflater.inflate(R.layout.calendar, main_content, false);
    if (caldroidFragment == null) {
        caldroidFragment = new CaldroidFragment();
        Bundle args = new Bundle();
        Calendar cal = Calendar.getInstance();
        args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1);
        args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR));
        args.putBoolean(CaldroidFragment.ENABLE_SWIPE, true);
        args.putBoolean(CaldroidFragment.SIX_WEEKS_IN_CALENDAR, true);
        caldroidFragment.setArguments(args);
    }/*from  w  ww.jav  a 2 s  .com*/
    caldroidFragment.setBackgroundResourceForDate(R.color.bg_blue, Calendar.getInstance().getTime());
    caldroidFragment.setTextColorForDate(R.color.pure_white, Calendar.getInstance().getTime());
    info_list = (ListView) calView.findViewById(R.id.info_listview);

    main_content.addView(calView);

    FragmentTransaction t = getSupportFragmentManager().beginTransaction();
    t.replace(R.id.calendar_container, caldroidFragment);
    t.commit();
    tv_calendar_notaskfordate = (TextView) findViewById(R.id.tv_calendar_notaskfordate);
    final CaldroidListener listener = new CaldroidListener() {

        @Override
        public void onSelectDate(Date date, View view) {
            initInfoListForDate(date);
            Calendar c = Calendar.getInstance();
            c.set(Calendar.YEAR, date.getYear() + 1900);
            c.set(Calendar.MONTH, date.getMonth());
            c.set(Calendar.DAY_OF_MONTH, date.getDate());
            c.set(Calendar.HOUR_OF_DAY, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MILLISECOND, 0);
            Calendar r = Calendar.getInstance();
            r.set(Calendar.YEAR, lastSelectedCalendarDate.getYear() + 1900);
            r.set(Calendar.MONTH, lastSelectedCalendarDate.getMonth());
            r.set(Calendar.DAY_OF_MONTH, lastSelectedCalendarDate.getDate());
            r.set(Calendar.HOUR_OF_DAY, 0);
            r.set(Calendar.MINUTE, 0);
            r.set(Calendar.SECOND, 0);
            r.set(Calendar.MILLISECOND, 0);
            if (c.get(Calendar.MONTH) != currCalendarMonth.get(Calendar.MONTH)) {
                caldroidFragment.setBackgroundResourceForDate(R.drawable.border_bg, date);
                caldroidFragment.setTextColorForDate(R.color.caldroid_gray, date);
            } else {
                if (TaskMap.containsKey(c) && !TaskMap.get(c).isEmpty()) {
                    caldroidFragment.setTextColorForDate(R.color.pure_white, date);
                    caldroidFragment.setBackgroundResourceForDate(R.drawable.border_bg_green, date);
                } else {
                    caldroidFragment.setBackgroundResourceForDate(R.drawable.border_bg, date);
                    caldroidFragment.setTextColorForDate(R.color.black, date);
                }
            }
            if (r.get(Calendar.MONTH) != currCalendarMonth.get(Calendar.MONTH)) {
                caldroidFragment.setBackgroundResourceForDate(R.color.pure_white, lastSelectedCalendarDate);
                caldroidFragment.setTextColorForDate(R.color.caldroid_gray, lastSelectedCalendarDate);
            } else {
                if (TaskMap.containsKey(r) && !TaskMap.get(r).isEmpty()) {
                    caldroidFragment.setTextColorForDate(R.color.pure_white, lastSelectedCalendarDate);
                    caldroidFragment.setBackgroundResourceForDate(R.color.bg_green, lastSelectedCalendarDate);
                } else {
                    caldroidFragment.setBackgroundResourceForDate(R.color.pure_white, lastSelectedCalendarDate);
                    caldroidFragment.setTextColorForDate(R.color.black, lastSelectedCalendarDate);
                }
            }

            lastSelectedCalendarDate = new Date(date.getTime());
            caldroidFragment.setBackgroundResourceForDate(R.color.bg_blue, Calendar.getInstance().getTime());
            caldroidFragment.setTextColorForDate(R.color.pure_white, Calendar.getInstance().getTime());
            caldroidFragment.refreshView();
        }

        @Override
        public void onChangeMonth(int month, int year) {
            month--;
            currCalendarMonth.set(Calendar.MONTH, month);
            currCalendarMonth.set(Calendar.YEAR, year);
            Calendar v = Calendar.getInstance();
            v.set(Calendar.YEAR, lastSelectedCalendarDate.getYear() + 1900);
            v.set(Calendar.MONTH, lastSelectedCalendarDate.getMonth());
            v.set(Calendar.DAY_OF_MONTH, lastSelectedCalendarDate.getDate());
            v.set(Calendar.HOUR_OF_DAY, 0);
            v.set(Calendar.MINUTE, 0);
            v.set(Calendar.SECOND, 0);
            v.set(Calendar.MILLISECOND, 0);
            if (v.get(Calendar.MONTH) != month) {
                caldroidFragment.setBackgroundResourceForDate(R.color.pure_white, lastSelectedCalendarDate);
                caldroidFragment.setTextColorForDate(R.color.caldroid_gray, lastSelectedCalendarDate);
            } else {
                if (TaskMap.containsKey(v)) {
                    caldroidFragment.setTextColorForDate(R.color.pure_white, lastSelectedCalendarDate);
                    caldroidFragment.setBackgroundResourceForDate(R.color.bg_green, lastSelectedCalendarDate);
                } else {
                    caldroidFragment.setBackgroundResourceForDate(R.color.pure_white, lastSelectedCalendarDate);
                    caldroidFragment.setTextColorForDate(R.color.black, lastSelectedCalendarDate);
                }
            }
            Calendar k = Calendar.getInstance();
            k.set(Calendar.DAY_OF_MONTH, 1);
            k.set(Calendar.YEAR, year);
            k.set(Calendar.MONTH, month);
            Calendar prev = Calendar.getInstance();
            Calendar nxt = Calendar.getInstance();
            prev.set(Calendar.YEAR, k.get(Calendar.YEAR));
            nxt.set(Calendar.YEAR, k.get(Calendar.YEAR));
            prev.set(Calendar.MONTH, k.get(Calendar.MONTH) - 1);
            nxt.set(Calendar.MONTH, k.get(Calendar.MONTH) + 1);
            prev.set(Calendar.DAY_OF_MONTH, 1);
            int prev_month = prev.get(Calendar.MONTH);
            nxt.set(Calendar.DAY_OF_MONTH, 1);
            int nxt_month = nxt.get(Calendar.MONTH);
            while (k.get(Calendar.MONTH) == month) {
                caldroidFragment.setBackgroundResourceForDate(R.color.pure_white, k.getTime());
                caldroidFragment.setTextColorForDate(R.color.black, k.getTime());
                k.add(Calendar.DAY_OF_MONTH, 1);
            }
            while (prev.get(Calendar.MONTH) == prev_month) {
                caldroidFragment.setBackgroundResourceForDate(R.color.pure_white, prev.getTime());
                caldroidFragment.setTextColorForDate(R.color.caldroid_gray, prev.getTime());
                prev.add(Calendar.DAY_OF_MONTH, 1);
            }

            while (nxt.get(Calendar.MONTH) == nxt_month) {
                caldroidFragment.setBackgroundResourceForDate(R.color.pure_white, nxt.getTime());
                caldroidFragment.setTextColorForDate(R.color.caldroid_gray, nxt.getTime());
                nxt.add(Calendar.DAY_OF_MONTH, 1);
            }
            setCalendarTaskForMonth(month, year);
            Date r = new Date(year - 1900, month, 1, 0, 0, 0);
            if (initInfoListForDate(r)) {
                caldroidFragment.setTextColorForDate(R.color.pure_white, r);
                caldroidFragment.setBackgroundResourceForDate(R.drawable.border_bg_green, r);
            } else {
                caldroidFragment.setBackgroundResourceForDate(R.drawable.border_bg, r);
                caldroidFragment.setTextColorForDate(R.color.black, r);
            }
            lastSelectedCalendarDate = (Date) r.clone();
            caldroidFragment.setBackgroundResourceForDate(R.color.bg_blue, Calendar.getInstance().getTime());
            caldroidFragment.setTextColorForDate(R.color.pure_white, Calendar.getInstance().getTime());
            caldroidFragment.refreshView();
        }

        @Override
        public void onLongClickDate(Date date, View view) {
        }

        @Override
        public void onCaldroidViewCreated() {
        }

    };

    caldroidFragment.setCaldroidListener(listener);
    caldroidFragment.setBackgroundResourceForDate(R.color.bg_blue, Calendar.getInstance().getTime());
    caldroidFragment.setTextColorForDate(R.color.pure_white, Calendar.getInstance().getTime());
    setCalendarTaskForMonth(Calendar.getInstance().get(Calendar.MONTH),
            Calendar.getInstance().get(Calendar.YEAR));
}

From source file:org.openlmis.report.service.AverageConsumptionReportDataProvider.java

public AverageConsumptionReportParam getReportFilterData(Map<String, String[]> filterCriteria) {
    averageConsumptionReportParam = new AverageConsumptionReportParam();
    if (filterCriteria != null) {

        Date originalStart = new Date();
        Date originalEnd = new Date();

        averageConsumptionReportParam.setZoneId(StringUtils.isBlank(filterCriteria.get("zoneId")[0]) ? 0L
                : Long.parseLong(filterCriteria.get("zoneId")[0])); //defaults to 0
        averageConsumptionReportParam//w w  w .j  a  v  a  2s . c  om
                .setFacilityTypeId(StringUtils.isBlank(filterCriteria.get("facilityTypeId")[0]) ? 0
                        : Integer.parseInt(filterCriteria.get("facilityTypeId")[0])); //defaults to 0
        averageConsumptionReportParam.setFacilityType(
                StringUtils.isBlank(filterCriteria.get("facilityType")[0]) ? "All Facility Types"
                        : filterCriteria.get("facilityType")[0]);
        averageConsumptionReportParam.setFacilityId(StringUtils.isBlank(filterCriteria.get("facility")[0]) ? 0
                : Long.parseLong(filterCriteria.get("facility")[0])); //defaults to 0

        averageConsumptionReportParam
                .setProductCategoryId(StringUtils.isBlank(filterCriteria.get("productCategoryId")[0]) ? 0
                        : Long.parseLong(filterCriteria.get("productCategoryId")[0])); //defaults to 0
        averageConsumptionReportParam.setProductId(StringUtils.isBlank(filterCriteria.get("productId")[0]) ? "0"
                : (filterCriteria.get("productId")[0]).toString().replace("]", "}").replace("[", "{")
                        .replaceAll("\"", ""));
        averageConsumptionReportParam.setRgroupId(StringUtils.isBlank(filterCriteria.get("rgroupId")[0]) ? 0
                : Long.parseLong(filterCriteria.get("rgroupId")[0])); //defaults to 0
        averageConsumptionReportParam.setProgramId(StringUtils.isBlank(filterCriteria.get("programId")[0]) ? 0
                : Long.parseLong(filterCriteria.get("programId")[0])); //defaults to 0

        //monthly
        averageConsumptionReportParam
                .setYearFrom(StringUtils.isBlank(filterCriteria.get("fromYear")[0]) ? originalStart.getYear()
                        : Integer.parseInt(filterCriteria.get("fromYear")[0])); //defaults to 0
        averageConsumptionReportParam
                .setYearTo(StringUtils.isBlank(filterCriteria.get("toYear")[0]) ? originalEnd.getYear()
                        : Integer.parseInt(filterCriteria.get("toYear")[0])); //defaults to 0
        averageConsumptionReportParam
                .setMonthFrom(StringUtils.isBlank(filterCriteria.get("fromMonth")[0]) ? originalStart.getMonth()
                        : Integer.parseInt(filterCriteria.get("fromMonth")[0])); //defaults to 0
        averageConsumptionReportParam
                .setMonthTo(StringUtils.isBlank(filterCriteria.get("toMonth")[0]) ? originalEnd.getMonth()
                        : Integer.parseInt(filterCriteria.get("toMonth")[0])); //defaults to 0

        averageConsumptionReportParam.setPdformat(StringUtils.isBlank(filterCriteria.get("pdformat")[0]) ? 0
                : Integer.parseInt(filterCriteria.get("pdformat")[0])); //defaults to 0
        averageConsumptionReportParam
                .setPeriodType(StringUtils.isBlank(filterCriteria.get("periodType")[0]) ? ""
                        : filterCriteria.get("periodType")[0].toString());
        averageConsumptionReportParam
                .setQuarterFrom(StringUtils.isBlank(filterCriteria.get("fromQuarter")[0]) ? 1
                        : Integer.parseInt(filterCriteria.get("fromQuarter")[0]));
        averageConsumptionReportParam.setQuarterTo(StringUtils.isBlank(filterCriteria.get("toQuarter")[0]) ? 1
                : Integer.parseInt(filterCriteria.get("toQuarter")[0]));
        averageConsumptionReportParam
                .setSemiAnnualFrom(StringUtils.isBlank(filterCriteria.get("fromSemiAnnual")[0]) ? 1
                        : Integer.parseInt(filterCriteria.get("fromSemiAnnual")[0]));
        averageConsumptionReportParam
                .setSemiAnnualTo(StringUtils.isBlank(filterCriteria.get("toSemiAnnual")[0]) ? 1
                        : Integer.parseInt(filterCriteria.get("toSemiAnnual")[0]));

        int monthFrom = 0;
        int monthTo = 0;
        String periodType = averageConsumptionReportParam.getPeriodType();

        if (periodType.equals(Constants.PERIOD_TYPE_QUARTERLY)) {
            monthFrom = 3 * (averageConsumptionReportParam.getQuarterFrom() - 1);
            monthTo = 3 * averageConsumptionReportParam.getQuarterTo() - 1;

        } else if (periodType.equals(Constants.PERIOD_TYPE_MONTHLY)) {
            monthFrom = averageConsumptionReportParam.getMonthFrom();
            monthTo = averageConsumptionReportParam.getMonthTo();

        } else if (periodType.equals(Constants.PERIOD_TYPE_SEMI_ANNUAL)) {
            monthFrom = 6 * (averageConsumptionReportParam.getSemiAnnualFrom() - 1);
            monthTo = 6 * averageConsumptionReportParam.getSemiAnnualTo() - 1;
        } else if (periodType.equals(Constants.PERIOD_TYPE_ANNUAL)) {
            monthFrom = 0;
            monthTo = 11;
        }

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, averageConsumptionReportParam.getYearFrom());
        calendar.set(Calendar.MONTH, monthFrom);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        averageConsumptionReportParam.setStartDate(calendar.getTime());

        calendar.set(Calendar.YEAR, averageConsumptionReportParam.getYearTo());
        calendar.set(Calendar.MONTH, monthTo);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        averageConsumptionReportParam.setEndDate(calendar.getTime());

    }
    return averageConsumptionReportParam;

}

From source file:org.sakaiproject.myshowcase.logic.MyShowcaseService.java

public String formattedLongDate(Date date) {
    return ordinalOfInteger(date.getDate()) + " " + monthName(date.getMonth() + 1) + " "
            + (1900 + date.getYear());//from www  .j  a v  a 2 s .  com
}

From source file:com.zoho.creator.jframework.XMLParser.java

private static void parseAndSetCalendarRecords(ZCView zcView, Node calendarNode) {

    zcView.setGrouped(true);//from www. j  a v a  2s .  c o m
    NodeList eventsList = calendarNode.getChildNodes();
    int year = zcView.getRecordsMonthYear().getTwo() - 1900;
    int month = zcView.getRecordsMonthYear().getOne();

    GregorianCalendar cureentmnthcalendar = new GregorianCalendar();
    Date currentDate = new Date();

    for (int i = 0; i < eventsList.getLength(); i++) {
        Node eventNode = eventsList.item(i);
        NamedNodeMap eventAttrMap = eventNode.getAttributes();
        long recordid = Long.parseLong(eventAttrMap.getNamedItem("id").getNodeValue()); //No I18N
        String title = getChildNodeValue(eventNode, "title"); //eventAttrMap.getNamedItem("title").getNodeValue(); //No I18N
        boolean isAllDay = Boolean.parseBoolean(eventAttrMap.getNamedItem("allDay").getNodeValue()); //No I18N
        // 07/31/2013 08:00:00
        String dateFormat = "MM/dd/yyyy HH:mm:ss"; //No I18N
        if (isAllDay) {
            dateFormat = "MM/dd/yyyy"; //No I18N
        }

        Date startTime = getDateValue(eventAttrMap.getNamedItem("start").getNodeValue(), dateFormat); //No I18N

        ZCRecord record = zcView.getRecord(recordid);

        record.setEventTitle(title);
        if (isAllDay) {
            zcView.setIsAllDay(isAllDay);

            Node endNode = eventAttrMap.getNamedItem("end");//No I18N
            Date endTime = null;
            if (endNode != null) {
                endTime = getDateValue(endNode.getNodeValue(), dateFormat);
            }

            int startDay = -1;
            if (startTime != null) {
                startDay = startTime.getDate();
            }

            int endDay = -1;
            if (endTime != null) {
                endDay = endTime.getDate();
            }

            if (endDay != -1) {

                currentDate.setDate(1);
                currentDate.setMonth(month);
                currentDate.setYear(year);
                currentDate.setMinutes(0);
                currentDate.setHours(0);
                currentDate.setSeconds(0);

                cureentmnthcalendar.setTime(currentDate);

                cureentmnthcalendar.add(cureentmnthcalendar.DAY_OF_MONTH, -6);
                currentDate = cureentmnthcalendar.getTime();

                for (int j = 0; j < 42; j++) {
                    if ((currentDate.getDate() == startTime.getDate()
                            && currentDate.getMonth() == startTime.getMonth()
                            && currentDate.getYear() == startTime.getYear())
                            || (currentDate.after(startTime) && currentDate.before(endTime))
                            || (currentDate.getDate() == endTime.getDate()
                                    && currentDate.getMonth() == endTime.getMonth()
                                    && currentDate.getYear() == endTime.getYear())) {

                        zcView.setEvent(record, currentDate);
                    }
                    cureentmnthcalendar.add(cureentmnthcalendar.DAY_OF_MONTH, 1);
                    currentDate = cureentmnthcalendar.getTime();
                }
                //Collections.sort(eventRecords);
            }

            record.setEventDate(startTime);
        } else {
            // 07/31/2013 08:00:00
            Date endTime = getDateValue(eventAttrMap.getNamedItem("end").getNodeValue(), dateFormat); //No I18N
            record.setStartTime(startTime);
            record.setEndTime(endTime);

            Calendar startCalendar = new GregorianCalendar();
            startCalendar.setTime(startTime);
            startCalendar.set(Calendar.HOUR_OF_DAY, 0);
            startCalendar.set(Calendar.MINUTE, 0);
            startCalendar.set(Calendar.SECOND, 0);
            startCalendar.set(Calendar.MILLISECOND, 0);

            Calendar endCalendar = new GregorianCalendar();
            endCalendar.setTime(endTime);
            endCalendar.set(Calendar.HOUR_OF_DAY, 0);
            endCalendar.set(Calendar.MINUTE, 0);
            endCalendar.set(Calendar.SECOND, 0);
            endCalendar.set(Calendar.MILLISECOND, 0);

            Date eventDate = new Date(startCalendar.getTimeInMillis());
            zcView.setEvent(record, eventDate);
            while ((startCalendar.get(Calendar.YEAR) != endCalendar.get(Calendar.YEAR))
                    || (startCalendar.get(Calendar.MONTH) != endCalendar.get(Calendar.MONTH))
                    || (startCalendar.get(Calendar.DATE) != endCalendar.get(Calendar.DATE))) {
                startCalendar.add(Calendar.DATE, 1);
                eventDate = new Date(startCalendar.getTimeInMillis());
                zcView.setEvent(record, eventDate);
            }
        }
    }

    List<ZCGroup> zcGroups = zcView.getGroups();
    HashMap<Date, List<ZCRecord>> eventsMap = zcView.getEventRecordsMap();
    SortedSet<Date> keys = new TreeSet<Date>(eventsMap.keySet());

    for (Date eventDate : keys) {
        List<ZCRecord> eventRecords = eventsMap.get(eventDate);
        List<String> groupHeaderValues = new ArrayList<String>();
        SimpleDateFormat dateFormat = new SimpleDateFormat(zcView.getDateFormat()); //No I18N
        groupHeaderValues.add(dateFormat.format(eventDate));
        ZCGroup zcGroup = new ZCGroup(groupHeaderValues);
        zcGroups.add(zcGroup);
        for (int i = 0; i < eventRecords.size(); i++) {
            ZCRecord eventRecord = eventRecords.get(i);
            zcGroup.addRecord(eventRecord);
        }
    }
    zcView.sortRecordsForCalendar();

}

From source file:com.fitforbusiness.nafc.dashboard.DashBoardFragment.java

private void loadSessions(String date) {

    Calendar calendar = Calendar.getInstance();
    date = String.format("%d-%02d-%02d", calendar.get(Calendar.YEAR), (calendar.get(Calendar.MONTH) + 1),
            calendar.get(Calendar.DAY_OF_MONTH));
    Date stDate = null;
    Date edDate = null;/*from   w  w  w.j av a  2 s  .  com*/
    try {
        stDate = new SimpleDateFormat("yyyy-MM-dd").parse(date);
        stDate.setTime(stDate.getTime() - 1000);
        edDate = new SimpleDateFormat("yyyy-MM-dd").parse(date);
        edDate.setTime(edDate.getTime() + (24 * 60 * 60 * 1000));
        edDate.setTime(edDate.getTime() - 1000);
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

    ArrayList<HashMap<String, Object>> mapArrayList = new ArrayList<>();
    SQLiteDatabase sqlDB;
    try {
        sqlDB = DatabaseHelper.instance().getReadableDatabase();

        String query = "select  " + Table.Sessions.ID + " , " + Table.Sessions.START_DATE + " , "
                + Table.Sessions.START_TIME + " , " + Table.Sessions.SESSION_STATUS + " , "
                + Table.Sessions.GROUP_ID + " , " + Table.Sessions.IS_NATIVE + " , "
                + Table.Sessions.RECURRENCE_RULE + " , " + Table.Sessions.TITLE + " , "
                + Table.Sessions.SESSION_TYPE + "  " + " from " + Table.Sessions.TABLE_NAME + " where "
                + Table.DELETED + " = 0 " + " and ( " + Table.Sessions.START_DATE + " =  datetime(\'" + date
                + "\') " + " OR  " + Table.Sessions.RECURRENCE_RULE + " IS NOT NULL " + "       OR "
                + Table.Sessions.RECURRENCE_RULE + " != '' ) ";

        Log.d("query is ", query);
        assert sqlDB != null;
        Cursor cursor = sqlDB.rawQuery(query, null);

        Log.d("Calendar", "Month Count = " + cursor.getCount());

        LinkedHashMap<String, Object> row;
        while (cursor.moveToNext()) {

            if (cursor.getString(cursor.getColumnIndex(Table.Sessions.RECURRENCE_RULE)) == null
                    || cursor.getString(cursor.getColumnIndex(Table.Sessions.RECURRENCE_RULE)).equals("")) {

                row = new LinkedHashMap<String, Object>();

                long groupSessionId = cursor.getInt(cursor.getColumnIndex(Table.Sessions.GROUP_ID));
                int session_type = cursor.getInt(cursor.getColumnIndex(Table.Sessions.SESSION_TYPE));
                rowData = getImageName(groupSessionId + "", session_type);

                row.put("_id", cursor.getString(cursor.getColumnIndex(Table.Sessions.ID)));
                row.put("name",
                        Utils.dateConversionForRow(
                                cursor.getString(cursor.getColumnIndex(Table.Sessions.START_DATE))) + " "
                                + Utils.timeFormatAMPM(
                                        cursor.getString(cursor.getColumnIndex(Table.Sessions.START_TIME))));

                row.put("rowId", groupSessionId);
                row.put("type", session_type);

                if (cursor.getInt(cursor.getColumnIndex(Table.Sessions.IS_NATIVE)) == 1) {

                    row.put("secondLabel", cursor.getString(cursor.getColumnIndex(Table.Sessions.TITLE)));
                    row.put("thirdLabel", getActivity().getString(R.string.lblNativeStatus));
                    Log.d("Calendar", "native events");
                } else if (rowData.getImageName() != null && rowData.getImageName().length() > 0) {
                    row.put("photo", rowData.getImageName());
                    row.put("secondLabel", rowData.getPersonName());
                    row.put("thirdLabel",
                            status[cursor.getInt(cursor.getColumnIndex(Table.Sessions.SESSION_STATUS))]);

                    Log.d("Calendar", "app events");
                }
                Log.d("Calendar", (String) row.get("secondLabel"));
                mapArrayList.add(row);
            } else {
                String rule = cursor.getString(cursor.getColumnIndex(Table.Sessions.RECURRENCE_RULE));

                RecurrenceRule recRule = new RecurrenceRule(rule);
                RecurrenceRule.Freq freq = recRule.getFreq();

                Date d = new SimpleDateFormat("dd MMM yyyy").parse(Utils.formatConversionSQLite(
                        cursor.getString(cursor.getColumnIndex(Table.Sessions.START_DATE))));

                switch (freq) {
                case MONTHLY:
                    d.setMonth(stDate.getMonth());
                case YEARLY:
                    d.setYear(stDate.getYear());
                }

                if (freq == RecurrenceRule.Freq.MONTHLY || freq == RecurrenceRule.Freq.YEARLY) {
                    if (!(d.after(stDate) && d.before(edDate)))
                        continue;
                }

                ArrayList<Calendar> dates;
                dates = CalendarMonthViewFragment.ruleOccurONDate(rule, stDate, edDate);

                Log.e("RecurRule", "size = " + dates.size());

                if (dates.size() > 0) {
                    row = new LinkedHashMap<String, Object>();

                    if (freq == RecurrenceRule.Freq.DAILY || freq == RecurrenceRule.Freq.WEEKLY) {
                        if (d.after(dates.get(0).getTime()))
                            continue;
                    }

                    long groupSessionId = cursor.getInt(cursor.getColumnIndex(Table.Sessions.GROUP_ID));
                    int session_type = cursor.getInt(cursor.getColumnIndex(Table.Sessions.SESSION_TYPE));
                    rowData = getImageName(groupSessionId + "", session_type);
                    row.put("_id", cursor.getString(cursor.getColumnIndex(Table.Sessions.ID)));
                    row.put("name", Utils.formatConversionDateOnly(stDate) + " " + Utils.timeFormatAMPM(
                            cursor.getString(cursor.getColumnIndex(Table.Sessions.START_TIME))));

                    row.put("rowId", groupSessionId);
                    row.put("type", session_type);

                    if (cursor.getInt(cursor.getColumnIndex(Table.Sessions.IS_NATIVE)) == 1) {

                        row.put("secondLabel", cursor.getString(cursor.getColumnIndex(Table.Sessions.TITLE)));
                        row.put("thirdLabel", getActivity().getString(R.string.lblNativeStatus));
                        Log.d("Calendar", "native events");
                    } else if (rowData.getImageName() != null && rowData.getImageName().length() > 0) {
                        row.put("photo", rowData.getImageName());
                        row.put("secondLabel", rowData.getPersonName());
                        row.put("thirdLabel",
                                status[cursor.getInt(cursor.getColumnIndex(Table.Sessions.SESSION_STATUS))]);

                        Log.d("Calendar", "app events");
                    }
                    Log.d("Calendar", (String) row.get("secondLabel"));
                    mapArrayList.add(row);
                }
            }
        }
        cursor.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    CustomAsyncTaskListAdapter adapter = new CustomAsyncTaskListAdapter(getActivity(),
            R.layout.calendar_day_view_session_row, R.id.ivRowImage, R.id.tvFirstName, R.id.tvSecondLabel,
            R.id.tvThirdLabel, mapArrayList);
    sessionList.setAdapter(adapter);
}

From source file:com.mimp.controllers.personal.java

@RequestMapping(value = "/logPersonalFiltroHoy", method = RequestMethod.GET)
public ModelAndView logPersonalFiltroHoy_GET(ModelMap map, HttpSession session) {
    Personal usuario = (Personal) session.getAttribute("usuario");
    if (usuario == null) {
        String mensaje = "La sesin ha finalizado. Favor identificarse nuevamente";
        map.addAttribute("mensaje", mensaje);
        return new ModelAndView("login", map);
    }/* w  w  w .j  ava 2  s.c o m*/
    //List<Personal> lista = Servicio.listaPersonal();
    Date diatemp = new Date();
    String dia = String.valueOf(diatemp.getDate()) + "/" + String.valueOf(diatemp.getMonth() + 1) + "/"
            + String.valueOf(diatemp.getYear() + 1900);

    map.put("listaPersonalLog", ServicioPersonal.getLogPersonalPorDia(dia));
    map.put("dia", dia);

    return new ModelAndView("/Personal/registros/usuarios/log_personal", map);

}