Example usage for java.util Date getDay

List of usage examples for java.util Date getDay

Introduction

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

Prototype

@Deprecated
public int getDay() 

Source Link

Document

Returns the day of the week represented by this date.

Usage

From source file:com.krawler.esp.servlets.importProjectPlanCSV.java

public String getActualDuration(Date stdate, Date enddate, int[] NonWorkDays, String[] holidays) {
    int noofdays = 0;
    java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("yyyy-MM-dd");
    try {/*from  w w  w.  j a va 2s . com*/
        Calendar c1 = Calendar.getInstance();
        while (stdate.compareTo(enddate) < 0) {
            if (Arrays.binarySearch(NonWorkDays, stdate.getDay()) < 0
                    && Arrays.binarySearch(holidays, sdf1.format(stdate)) < 0) {
                noofdays++;
            }
            c1.set(stdate.getYear() + 1900, stdate.getMonth(), stdate.getDate());
            c1.add(Calendar.DATE, 1);
            stdate = sdf1.parse(sdf1.format(c1.getTime()));
        }
        if (stdate.compareTo(enddate) == 0) {
            if (Arrays.binarySearch(NonWorkDays, stdate.getDay()) < 0
                    && Arrays.binarySearch(holidays, sdf1.format(stdate)) < 0) {
                noofdays++;
            }
        }
    } catch (ParseException ex) {
        Logger.getLogger(importProjectPlanCSV.class.getName()).log(Level.SEVERE, null, ex);
    }
    return noofdays + "d";
}

From source file:com.krawler.esp.servlets.importProjectPlanCSV.java

/**
 * Adds the task into proj_task and temp table. any exception will return a HashMap contining error description
 *//*from w w w . j  av a 2  s.co  m*/
protected HashMap<Integer, String> storeInDB(Connection conn, JSONObject temp, String projectid,
        String appendchoice, String userid, int totalOldTasks, int recordIndex) throws ServiceException {
    int skipped = 0;
    HashMap<Integer, String> skip = new HashMap<Integer, String>();
    try {
        int nonworkweekArr[] = projdb.getNonWorkWeekDays(conn, projectid);
        String holidayArr[] = projdb.getCompHolidays(conn, projectid, "");
        try {
            String tid = UUID.randomUUID().toString();
            java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
            String startdate = StringUtil.serverHTMLStripper(temp.getString("startdate"));
            java.util.Date SDateVal = sdf.parse(startdate);
            startdate = sdf.format(SDateVal);
            Calendar cal = Calendar.getInstance();
            cal.setTime(SDateVal);
            java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("yyyy-MM-dd");
            boolean flag = true;
            while (flag) {
                if ((Arrays.binarySearch(nonworkweekArr, SDateVal.getDay()) >= 0
                        || Arrays.binarySearch(holidayArr, sdf1.format(SDateVal)) >= 0)) {
                    cal.setTime(SDateVal);
                    cal.add(Calendar.DATE, 1);
                    SDateVal = cal.getTime();
                    flag = true;
                } else {
                    flag = false;
                }
            }
            temp.remove("startdate");
            temp.put("startdate", sdf1.format(SDateVal));
            java.util.Date EDateVal = new Date();
            String acduration = "";
            String enddate = "";
            String dura = temp.getString("duration");
            if (!temp.getString("enddate").equals("")) {
                enddate = StringUtil.serverHTMLStripper(temp.getString("enddate"));
                EDateVal = sdf.parse(enddate);
                acduration = getActualDuration_importCSV(SDateVal, EDateVal, nonworkweekArr, holidayArr, dura);
            } else {
                if (!StringUtil.isNullOrEmpty(dura)) {
                    EDateVal = projdb.calculateEndDate(conn, SDateVal, dura, nonworkweekArr, holidayArr, "");
                    enddate = sdf.format(EDateVal);
                    acduration = dura;
                } else {
                    throw new ParseException("Insufficient Data", 0);
                }
            }

            temp.put("duration", acduration);
            temp.put("actstartdate", startdate);
            temp.put("enddate", enddate);
            temp.put("level", "0");
            temp.put("isparent", "false");
            temp.put("loginid", userid);
            temp.put("links", "");
            projdb.InsertTask(conn, temp, tid, projectid, Integer.toString(totalOldTasks));
            totalOldTasks++;
            DbUtil.executeUpdate(conn, "INSERT INTO tempImportData VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)",
                    new Object[] { recordIndex, tid, temp.getString("taskname"), temp.getString("duration"),
                            temp.getString("startdate"), temp.getString("enddate"),
                            temp.getInt("percentcomplete"), temp.getString("priority"), temp.getString("notes"),
                            temp.getString("resourcename"), temp.getString("predecessor"),
                            temp.getString("parent"), "" });
            String resnames = temp.getString("resourcename");
            String[] res = resnames.split(",");
            for (int c = 0; c < res.length; c++) {
                if (!StringUtil.equal(res[c], ""))
                    resNames.add(res[c]);
            }
        } catch (com.krawler.utils.json.base.JSONException ex) {
            //                skip.put(++skipped, MessageSourceProxy.getMessage(KWLErrorMsgs.importCSVInvFormat, null, locale));
            skip.put(++skipped, KWLErrorMsgs.importCSVInvFormat);
        } catch (ParseException ex) {
            //                skip.put(++skipped, MessageSourceProxy.getMessage(KWLErrorMsgs.importCSVInvDateFormat, null, locale));
            skip.put(++skipped, KWLErrorMsgs.importCSVInvDateFormat);
        } catch (ServiceException ex) {
            //                skip.put(++skipped, MessageSourceProxy.getMessage(KWLErrorMsgs.importCSVTaskFailure, null, locale));
            skip.put(++skipped, KWLErrorMsgs.importCSVTaskFailure);
        }
    } catch (ServiceException ex) {
        KrawlerLog.op.warn("Problem Storing Data In DB [importProjectPlanCSV.storeInDB()]:" + ex.toString());
        throw ServiceException.FAILURE("importProjectPlanCSV.storeInDB error", ex);
    }
    return skip;
}

From source file:com.owncloud.android.ui.fragment.contactsbackup.ContactsBackupFragment.java

public void openDate(@Nullable Date savedDate) {
    final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity();

    String backupFolderString = getResources().getString(R.string.contacts_backup_folder)
            + OCFile.PATH_SEPARATOR;//from  w ww.j av  a 2 s .  c  om
    OCFile backupFolder = contactsPreferenceActivity.getStorageManager().getFileByPath(backupFolderString);

    Vector<OCFile> backupFiles = contactsPreferenceActivity.getStorageManager().getFolderContent(backupFolder,
            false);

    Collections.sort(backupFiles, new Comparator<OCFile>() {
        @Override
        public int compare(OCFile o1, OCFile o2) {
            if (o1.getModificationTimestamp() == o2.getModificationTimestamp()) {
                return 0;
            }

            if (o1.getModificationTimestamp() > o2.getModificationTimestamp()) {
                return 1;
            } else {
                return -1;
            }
        }
    });

    Calendar cal = Calendar.getInstance();
    int year;
    int month;
    int day;

    if (savedDate == null) {
        year = cal.get(Calendar.YEAR);
        month = cal.get(Calendar.MONTH) + 1;
        day = cal.get(Calendar.DAY_OF_MONTH);
    } else {
        year = savedDate.getYear();
        month = savedDate.getMonth();
        day = savedDate.getDay();
    }

    if (backupFiles.size() > 0 && backupFiles.lastElement() != null) {
        datePickerDialog = new DatePickerDialog(contactsPreferenceActivity, this, year, month, day);
        datePickerDialog.getDatePicker().setMaxDate(backupFiles.lastElement().getModificationTimestamp());
        datePickerDialog.getDatePicker().setMinDate(backupFiles.firstElement().getModificationTimestamp());

        datePickerDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                selectedDate = null;
            }
        });

        datePickerDialog.show();
    } else {
        Toast.makeText(contactsPreferenceActivity, R.string.contacts_preferences_something_strange_happened,
                Toast.LENGTH_SHORT).show();
    }
}