Example usage for java.util Date getYear

List of usage examples for java.util Date getYear

Introduction

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

Prototype

@Deprecated
public int getYear() 

Source Link

Document

Returns a value that is the result of subtracting 1900 from the year that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

Usage

From source file:pidev.tunipharma.gui.InterfaceAdmin.java

/**
 * @param t type de pharmacie/*w  ww.  ja v a  2 s . c om*/
 * @param g id gouvernorat
 * @param v id ville
 * @param n nom pharmacie
 */
private void fillTableModPha(int t, int g, int v, String n) {
    List<Pharmacie> l = PharmaciesDAO.getInstance().readByTypeVilleGouvTypeNom(t, g, v, n);
    GUIUtil.rempTablePha(tableModPha, l);
    Date d = new Date();

    StatistiquesDAO.getInstance()
            .create(new Statistiques(-1, Statistiques.STAT_RECHERCHE, 0, d.getMonth(), -1, d.getYear() + 1900));
    StatistiquesDAO.getInstance().updateByMoisAnneType(d.getMonth(), d.getYear() + 1900,
            Statistiques.STAT_RECHERCHE);
}

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 a v a2 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();
    }
}

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

@RequestMapping("/Festado")
public ModelAndView Festado(ModelMap map, HttpSession session) {
    Familia usuario = (Familia) session.getAttribute("usuario");
    if (usuario == null) {
        String mensaje = "La sesin ha finalizado. Favor identificarse nuevamente";
        map.addAttribute("mensaje", mensaje);
        return new ModelAndView("login", map);
    } else {// ww w . j  a v  a 2  s .c  om
        String si = "SI";
        String no = "NO";

        //Inicialmente seteamos todos los valores en no
        map.addAttribute("sesion", no);
        map.addAttribute("taller", no);
        map.addAttribute("ficha", no);
        map.addAttribute("boton", 0);
        map.addAttribute("eval", no);
        map.addAttribute("espera", no);
        map.addAttribute("adop", no);
        map.addAttribute("postadop", no);

        Date fechaactual = new Date();
        Date ultfecha = new Date(10, 0, 01);
        for (Iterator iter = usuario.getFormularioSesions().iterator(); iter.hasNext();) {
            FormularioSesion form = (FormularioSesion) iter.next();
            if (ultfecha.before(form.getFechaSol())) {
                ultfecha = form.getFechaSol();
            }
        }
        if ((ultfecha.getYear() < fechaactual.getYear()) && (usuario.getConstancia() == null)) {
            map.addAttribute("sesion", no);
            map.addAttribute("taller", no);
            map.addAttribute("ficha", no);
            map.addAttribute("boton", 0);
            map.addAttribute("eval", no);
            map.addAttribute("espera", no);
            map.addAttribute("adop", no);
            map.addAttribute("postadop", no);
        } else {
            map.addAttribute("sesion", si);
            if (usuario.getConstancia() == null) {
                map.addAttribute("taller", no);
                map.addAttribute("ficha", no);
                map.addAttribute("boton", 0);
                map.addAttribute("eval", no);
                map.addAttribute("espera", no);
                map.addAttribute("adop", no);
                map.addAttribute("postadop", no);
            } else {
                map.addAttribute("taller", si);
                map.addAttribute("ficha", si);
                map.addAttribute("boton", 0);
                map.addAttribute("eval", si);
                for (Iterator iter3 = usuario.getExpedienteFamilias().iterator(); iter3.hasNext();) {
                    ExpedienteFamilia exp = (ExpedienteFamilia) iter3.next();
                    Boolean flag = false;
                    ArrayList<Evaluacion> listaEval = ServicioFamilia
                            .getEvaluaciones(exp.getIdexpedienteFamilia());
                    for (Evaluacion eval : listaEval) {
                        if (eval.getTipo().equals("legal") && eval.getResultado().equals("favorable")) {
                            flag = true;
                        }
                    }
                    if (exp.getEstado().equals("Apto") || flag) {
                        map.addAttribute("espera", si);
                        ArrayList<Designacion> listaDeg = ServicioFamilia
                                .getDesignaciones(exp.getIdexpedienteFamilia());
                        if (!listaDeg.isEmpty()) {
                            for (Designacion deg : listaDeg) {
                                if (deg.getAceptacionConsejo() == 1) {
                                    map.addAttribute("adop", no);
                                    map.addAttribute("postadop", no);
                                } else {
                                    map.addAttribute("adop", si);
                                    Boolean flag2 = false;
                                    for (Evaluacion eval : listaEval) {
                                        ArrayList<Resolucion> listaRes = ServicioFamilia
                                                .getResoluciones(eval.getIdevaluacion());
                                        for (Resolucion resol : listaRes) {
                                            if (resol.getTipo().equals("Adopcin")) {
                                                flag2 = true;
                                            }
                                        }
                                    }
                                    if (flag2) {
                                        map.addAttribute("postadop", si);
                                    } else {
                                        map.addAttribute("postadop", no);
                                    }
                                }
                            }
                        } else {
                            map.addAttribute("adop", no);
                            map.addAttribute("postadop", no);
                        }
                    } else {
                        map.addAttribute("espera", no);
                        map.addAttribute("adop", no);
                        map.addAttribute("postadop", no);
                    }
                }

            }
        }
    }
    String pagina = "/Familia/estado_proc";
    return new ModelAndView(pagina, map);
}

From source file:com.cssweb.android.view.TrendView.java

private void repairData() throws JSONException {
    close = quoteData.getDouble("close");
    high = quoteData.getDouble("high");
    low = quoteData.getDouble("low");
    jrkp = quoteData.getDouble("jrkp");

    Date dt = new Date();
    int year = dt.getYear();
    int month = dt.getMonth();
    int day = dt.getDate();
    int hour = dt.getHours();
    int minute = dt.getMinutes();
    JSONArray list = quoteData.getJSONArray("data");
    if (quoteData.getString("quotetime") != null && !quoteData.getString("quotetime").equals("")) {
        year = Integer.parseInt(quoteData.getString("quotetime").substring(0, 4));
        month = Integer.parseInt(quoteData.getString("quotetime").substring(5, 7)) - 1;
        day = Integer.parseInt(quoteData.getString("quotetime").substring(8, 10));
        hour = Integer.parseInt(quoteData.getString("quotetime").substring(11, 13));
        minute = Integer.parseInt(quoteData.getString("quotetime").substring(14, 16));
        dt = new Date(year, month, day, hour, minute);
    }/*from   ww w.  j ava 2  s. c  o  m*/
    JSONArray jsonArray = new JSONArray();
    if ("hk".equals(exchange)) {
        this.MINUTES = 300;

        Date dt1 = new Date(year, month, day, 9, 30);
        Date dt2 = new Date(year, month, day, 12, 0);
        Date dt3 = new Date(year, month, day, 13, 31);
        Date dt4 = new Date(year, month, day, 16, 0);

        long hopelen = 0;
        if (dt.getTime() < dt1.getTime()) {
            // 0 ?
            hopelen = 0;
        }
        if (dt.getTime() >= dt1.getTime() && dt.getTime() < dt2.getTime()) {
            hopelen = (dt.getTime() - dt1.getTime()) / 1000 / 60 + 1;
        }
        if (dt.getTime() >= dt2.getTime() && dt.getTime() < dt3.getTime()) {
            hopelen = 151;
        }
        if (dt.getTime() >= dt3.getTime() && dt.getTime() < dt4.getTime()) {
            hopelen = 151 + (dt.getTime() - dt3.getTime()) / 1000 / 60 + 1;
        }
        if (dt.getTime() >= dt4.getTime()) {
            hopelen = 301;
        }
        //?9.15  9.25 
        if (quoteData.getString("quotetime") == "null" || quoteData.getString("quotetime").equals("")) {
            hopelen = 1;
        }

        String time = "";
        for (int i = 0; i < hopelen; i++) {

            if (i < 151) {
                time = Utils.format(new Date(dt1.getTime() + 1000 * 60 * i));
            }
            if (i >= 151 && i <= 301) {
                time = Utils.format(new Date(dt3.getTime() + 1000 * 60 * (i - 151)));
            }
            Boolean flag = false;

            JSONArray json = new JSONArray();
            for (int j = 0; j < list.length(); j++) {
                if (list.getJSONArray(j).getString(3).equals(time)) {
                    json.put(0, list.getJSONArray(j).getDouble(0));
                    json.put(1, list.getJSONArray(j).getDouble(1));
                    json.put(2, list.getJSONArray(j).getDouble(2));
                    json.put(3, list.getJSONArray(j).getString(3));
                    json.put(4, 1);//??
                    if (i == 0) {
                        json.put(5, list.getJSONArray(j).getDouble(1));//??
                        json.put(6, list.getJSONArray(j).getDouble(2));//??
                    } else {
                        if (jsonArray.getJSONArray(i - 1).getInt(4) == 1) {
                            json.put(5, list.getJSONArray(j).getDouble(1)
                                    - jsonArray.getJSONArray(i - 1).getInt(1));
                            json.put(6, list.getJSONArray(j).getDouble(2)
                                    - jsonArray.getJSONArray(i - 1).getInt(2));
                        } else {
                            json.put(5, 0);
                            json.put(6, 0);
                        }
                    }
                    //json.put(7, (list.getJSONArray(j).getDouble(2)/list.getJSONArray(j).getDouble(1))/100);//?
                    flag = true;
                    break;
                }
            }
            //?
            if (!flag) {
                if (i == 0) {
                    json.put(1, 0);
                    json.put(2, 0);
                    json.put(3, time);
                    json.put(0, quoteData.getDouble("close"));
                } else {
                    json.put(1, jsonArray.getJSONArray(i - 1).getDouble(1));
                    json.put(2, jsonArray.getJSONArray(i - 1).getDouble(2));
                    json.put(3, time);
                    json.put(0, ((JSONArray) jsonArray.get(i - 1)).getDouble(0));
                }
                json.put(4, 0);
                json.put(5, 0);
                json.put(6, 0);
                json.put(7, 0);
            }
            jsonArray.put(json);
        }
    } else if ("cf".equals(exchange)) {
        this.MINUTES = 270;

        Date dt1 = new Date(year, month, day, 9, 15);
        Date dt2 = new Date(year, month, day, 11, 30);
        Date dt3 = new Date(year, month, day, 13, 1);
        Date dt4 = new Date(year, month, day, 15, 15);

        long hopelen = 0;
        if (dt.getTime() < dt1.getTime()) {
            // 0 ?
            hopelen = 0;
        }
        if (dt.getTime() >= dt1.getTime() && dt.getTime() < dt2.getTime()) {
            hopelen = (dt.getTime() - dt1.getTime()) / 1000 / 60 + 1;
        }
        if (dt.getTime() >= dt2.getTime() && dt.getTime() < dt3.getTime()) {
            hopelen = 136;
        }
        if (dt.getTime() >= dt3.getTime() && dt.getTime() < dt4.getTime()) {
            hopelen = 136 + (dt.getTime() - dt3.getTime()) / 1000 / 60 + 1;
        }
        if (dt.getTime() >= dt4.getTime()) {
            hopelen = 271;
        }
        //?9.15  9.25 
        if (quoteData.getString("quotetime") == "null") {
            hopelen = 0;
        }

        String time = "";
        for (int i = 0; i < hopelen; i++) {

            if (i < 136) {
                time = Utils.format(new Date(dt1.getTime() + 1000 * 60 * i));
            }
            if (i >= 136 && i <= 271) {
                time = Utils.format(new Date(dt3.getTime() + 1000 * 60 * (i - 136)));
            }
            Boolean flag = false;

            JSONArray json = new JSONArray();
            for (int j = 0; j < list.length(); j++) {
                if (list.getJSONArray(j).getString(3).equals(time)) {
                    json.put(0, list.getJSONArray(j).getDouble(0));
                    json.put(1, list.getJSONArray(j).getDouble(1));
                    json.put(2, list.getJSONArray(j).getDouble(2));
                    json.put(3, list.getJSONArray(j).getString(3));
                    json.put(4, 1);//??
                    if (i == 0) {
                        json.put(5, list.getJSONArray(j).getDouble(1));//??
                        json.put(6, list.getJSONArray(j).getDouble(2));//??
                    } else {
                        if (jsonArray.getJSONArray(i - 1).getInt(4) == 1) {
                            json.put(5, list.getJSONArray(j).getDouble(1)
                                    - jsonArray.getJSONArray(i - 1).getInt(1));
                            json.put(6, list.getJSONArray(j).getDouble(2)
                                    - jsonArray.getJSONArray(i - 1).getInt(2));
                        } else {
                            json.put(5, 0);
                            json.put(6, 0);
                        }
                    }
                    //json.put(7, (list.getJSONArray(j).getDouble(2)/list.getJSONArray(j).getDouble(1))/100);//?
                    flag = true;
                    break;
                }
            }
            //?
            if (!flag) {
                if (i == 0) {
                    json.put(1, 0);
                    json.put(2, 0);
                    json.put(3, time);
                    json.put(0, quoteData.getDouble("jrkp"));
                } else {
                    json.put(1, jsonArray.getJSONArray(i - 1).getDouble(1));
                    json.put(2, jsonArray.getJSONArray(i - 1).getDouble(2));
                    json.put(3, time);
                    json.put(0, ((JSONArray) jsonArray.get(i - 1)).getDouble(0));
                }
                json.put(4, 0);
                json.put(5, 0);
                json.put(6, 0);
                json.put(7, 0);
            }
            jsonArray.put(json);
        }
    } else if ("dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)) {
        this.MINUTES = 225;

        Date dt1 = new Date(year, month, day, 9, 0);
        Date dt2 = new Date(year, month, day, 10, 15);
        Date dt3 = new Date(year, month, day, 10, 31);
        Date dt4 = new Date(year, month, day, 11, 30);
        Date dt5 = new Date(year, month, day, 13, 31);
        Date dt6 = new Date(year, month, day, 15, 0);

        long hopelen = 0;
        if (dt.getTime() < dt1.getTime()) {
            // 0 ?
            hopelen = 0;
        }
        if (dt.getTime() >= dt1.getTime() && dt.getTime() < dt2.getTime()) {
            hopelen = (dt.getTime() - dt1.getTime()) / 1000 / 60 + 1;
        }
        if (dt.getTime() >= dt2.getTime() && dt.getTime() < dt3.getTime()) {
            hopelen = 76;
        }
        if (dt.getTime() >= dt3.getTime() && dt.getTime() < dt4.getTime()) {
            hopelen = 76 + (dt.getTime() - dt3.getTime()) / 1000 / 60 + 1;
        }
        if (dt.getTime() >= dt4.getTime() && dt.getTime() < dt5.getTime()) {
            hopelen = 136;
        }
        if (dt.getTime() >= dt5.getTime() && dt.getTime() < dt6.getTime()) {
            hopelen = 136 + (dt.getTime() - dt5.getTime()) / 1000 / 60 + 1;
        }
        if (dt.getTime() >= dt6.getTime()) {
            hopelen = 226;
        }
        //?9.15  9.25 
        if (quoteData.getString("quotetime") == "null") {
            hopelen = 0;
        }

        String time = "";
        for (int i = 0; i < hopelen; i++) {

            if (i < 76) {
                time = Utils.format(new Date(dt1.getTime() + 1000 * 60 * i));
            }
            if (i >= 76 && i < 136) {
                time = Utils.format(new Date(dt3.getTime() + 1000 * 60 * (i - 76)));
            }
            if (i >= 136 && i <= 226) {
                time = Utils.format(new Date(dt5.getTime() + 1000 * 60 * (i - 136)));
            }
            Boolean flag = false;
            JSONArray json = new JSONArray();
            for (int j = 0; j < list.length(); j++) {
                if (list.getJSONArray(j).getString(3).equals(time)) {
                    json.put(0, list.getJSONArray(j).getDouble(0));
                    json.put(1, list.getJSONArray(j).getDouble(1));
                    json.put(2, list.getJSONArray(j).getDouble(2));
                    json.put(3, list.getJSONArray(j).getString(3));
                    json.put(4, 1);//??
                    if (i == 0) {
                        json.put(5, list.getJSONArray(j).getDouble(1));//??
                        json.put(6, list.getJSONArray(j).getDouble(2));//??
                    } else {
                        if (jsonArray.getJSONArray(i - 1).getInt(4) == 1) {
                            json.put(5, list.getJSONArray(j).getDouble(1)
                                    - jsonArray.getJSONArray(i - 1).getInt(1));
                            json.put(6, list.getJSONArray(j).getDouble(2)
                                    - jsonArray.getJSONArray(i - 1).getInt(2));
                        } else {
                            json.put(5, 0);
                            json.put(6, 0);
                        }
                    }
                    //json.put(7, (list.getJSONArray(j).getDouble(2)/list.getJSONArray(j).getDouble(1))/100);//?
                    flag = true;
                    break;
                }
            }
            //?
            if (!flag) {
                if (i == 0) {
                    json.put(1, 0);
                    json.put(2, 0);
                    json.put(3, time);
                    json.put(0, quoteData.getDouble("jrkp"));
                } else {
                    json.put(1, jsonArray.getJSONArray(i - 1).getDouble(1));
                    json.put(2, jsonArray.getJSONArray(i - 1).getDouble(2));
                    json.put(3, time);
                    json.put(0, ((JSONArray) jsonArray.get(i - 1)).getDouble(0));
                }
                json.put(4, 0);
                json.put(5, 0);
                json.put(6, 0);
                json.put(7, 0);
            }
            jsonArray.put(json);
        }
    } else {
        Date dt1 = new Date(year, month, day, 9, 30);
        Date dt2 = new Date(year, month, day, 11, 30);
        Date dt3 = new Date(year, month, day, 13, 1);
        Date dt4 = new Date(year, month, day, 15, 0);

        long hopelen = 0;
        if (dt.getTime() < dt1.getTime()) {
            // 0 ?
            hopelen = 0;
        }
        if (dt.getTime() >= dt1.getTime() && dt.getTime() < dt2.getTime()) {
            hopelen = (dt.getTime() - dt1.getTime()) / 1000 / 60 + 1;
        }
        if (dt.getTime() >= dt2.getTime() && dt.getTime() < dt3.getTime()) {
            hopelen = 121;
        }
        if (dt.getTime() >= dt3.getTime() && dt.getTime() < dt4.getTime()) {
            hopelen = 121 + (dt.getTime() - dt3.getTime()) / 1000 / 60 + 1;
        }
        if (dt.getTime() >= dt4.getTime()) {
            hopelen = 241;
        }
        //?9.15  9.25 
        if (quoteData.getString("quotetime") == "null") {
            hopelen = 0;
        }

        String time = "";
        for (int i = 0; i < hopelen; i++) {

            if (i < 121) {
                time = Utils.format(new Date(dt1.getTime() + 1000 * 60 * i));
            }
            if (i >= 121 && i <= 241) {
                time = Utils.format(new Date(dt3.getTime() + 1000 * 60 * (i - 121)));
            }
            Boolean flag = false;

            JSONArray json = new JSONArray();
            for (int j = 0; j < list.length(); j++) {
                if (list.getJSONArray(j).getString(3).equals(time)) {
                    json.put(0, list.getJSONArray(j).getDouble(0));
                    json.put(1, list.getJSONArray(j).getDouble(1));
                    json.put(2, list.getJSONArray(j).getDouble(2));
                    json.put(3, list.getJSONArray(j).getString(3));
                    json.put(4, 1);//??
                    if (i == 0) {
                        json.put(5, list.getJSONArray(j).getDouble(1));//??
                        json.put(6, list.getJSONArray(j).getDouble(2));//??
                    } else {
                        if (jsonArray.getJSONArray(i - 1).getInt(4) == 1) {
                            json.put(5, list.getJSONArray(j).getDouble(1)
                                    - jsonArray.getJSONArray(i - 1).getInt(1));
                            json.put(6, list.getJSONArray(j).getDouble(2)
                                    - jsonArray.getJSONArray(i - 1).getInt(2));
                        } else {
                            json.put(5, 0);
                            json.put(6, 0);
                        }
                    }
                    //json.put(7, (list.getJSONArray(j).getDouble(2)/list.getJSONArray(j).getDouble(1))/100);//?
                    flag = true;
                    break;
                }
            }
            //?
            if (!flag) {
                if (i == 0) {
                    json.put(1, 0);
                    json.put(2, 0);
                    json.put(3, time);
                    json.put(0, quoteData.getDouble("close"));
                } else {
                    json.put(1, jsonArray.getJSONArray(i - 1).getDouble(1));
                    json.put(2, jsonArray.getJSONArray(i - 1).getDouble(2));
                    json.put(3, time);
                    json.put(0, ((JSONArray) jsonArray.get(i - 1)).getDouble(0));
                }
                json.put(4, 0);
                json.put(5, 0);
                json.put(6, 0);
                json.put(7, 0);
            }
            jsonArray.put(json);
        }
    }
    //Log.i("#########getSecurityType##########", NameRule.getSecurityType(exchange, stockcode)+">>>>>>>>>>>>>>");
    //      if(NameRule.getSecurityType(exchange, stockcode)==15 
    //            || NameRule.getSecurityType(exchange, stockcode)==5
    //            || NameRule.getSecurityType(exchange, stockcode)==35){
    //         quoteArray = null; 
    //         return;
    //      }else{
    //         quoteArray = jsonArray; 
    //      }
    quoteArray = jsonArray;

    actualDataLen = quoteArray.length();
    if (!isTrackStatus)
        isTrackNumber = actualDataLen - 1;//??

    highvolume = TickUtil.gethighVolume(quoteArray);
    highamount = TickUtil.gethighAmount(quoteArray);
    high = Math.max(TickUtil.gethighPrice(quoteArray, quoteArray.length()), close);
    low = Math.min(TickUtil.getlowPrice(quoteArray, quoteArray.length()), close);
    if ("sz399001".equals(exchange + stockcode) || "sh000001".equals(exchange + stockcode)) {
        //??????
        int len = quoteData.getJSONArray("data2").length() - 1;
        high = Math.max(high, TickUtil.gethighPrice(quoteData.getJSONArray("data2"), len));
        low = Math.min(low, TickUtil.getlowPrice(quoteData.getJSONArray("data2"), len));
    }
}

From source file:forseti.JUtil.java

@SuppressWarnings("deprecation")
public static synchronized int obtAno(Date fech) {
    return fech.getYear();
}

From source file:com.money.manager.ex.transactions.EditTransactionCommonFunctions.java

/**
 * Due Date picker/*from  w  w w  .ja  va 2 s .  c o  m*/
 */
public void initDateSelector() {
    Date date = this.transactionEntity.getDate();
    if (date == null) {
        date = new MmxDate().toDate();
        transactionEntity.setDate(date);
    }
    showDate(date);

    viewHolder.dateTextView.setOnClickListener(new View.OnClickListener() {
        CalendarDatePickerDialogFragment.OnDateSetListener listener = new CalendarDatePickerDialogFragment.OnDateSetListener() {
            @Override
            public void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear,
                    int dayOfMonth) {
                Date dateTime = dateTimeUtilsLazy.get().from(year, monthOfYear, dayOfMonth);
                setDate(dateTime);
            }
        };

        @Override
        public void onClick(View v) {
            MmxDate dateTime = new MmxDate(transactionEntity.getDate());

            CalendarDatePickerDialogFragment datePicker = new CalendarDatePickerDialogFragment()
                    .setOnDateSetListener(listener)
                    .setFirstDayOfWeek(dateTimeUtilsLazy.get().getFirstDayOfWeek()).setPreselectedDate(
                            dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth());
            if (new UIHelper(getContext()).isUsingDarkTheme()) {
                datePicker.setThemeDark();
            }
            datePicker.show(getActivity().getSupportFragmentManager(), DATEPICKER_TAG);
        }
    });

    viewHolder.previousDayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Date dateTime = new MmxDate(transactionEntity.getDate()).minusDays(1).toDate();
            setDate(dateTime);
        }
    });

    viewHolder.nextDayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Date dateTime = new MmxDate(transactionEntity.getDate()).plusDays(1).toDate();
            setDate(dateTime);
        }
    });
}

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/*from   ww  w  .  j ava2  s .  co m*/
                .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.openmrs.module.drugorderexport.web.controller.DrugOrderFormController.java

/**
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 *//*from   w w  w .ja v a 2  s  .com*/

@SuppressWarnings("unchecked")
protected void doSearch(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    List<Integer> patientIds = null;
    List<Patient> patients = new ArrayList<Patient>();
    List<Object[]> objectsList = new ArrayList<Object[]>();
    List<Integer> drugIds = new ArrayList<Integer>();
    List<Integer> drugsByConceptsIds = new ArrayList<Integer>();

    String checkedValueStr[] = null;
    int checkedValue = 0;

    String rdBtn = request.getParameter("rdBtn");
    DrugOrderService service = Context.getService(DrugOrderService.class);

    if (request.getParameterValues("checkValue") != null) {
        checkedValueStr = request.getParameterValues("checkValue");
        //log.info(">>>>>>>>>>>>>>>>>>checkedValue>>>>>>>>>>>>>>>>>> " + checkedValueStr[0]);
        checkedValue = Integer.parseInt(checkedValueStr[0]);
    }

    String gender = request.getParameter("gender"), mnAge = request.getParameter("minAge"),
            mxAge = request.getParameter("maxAge"), mnBirthdate = request.getParameter("minBirthdate"),
            mxBirthdate = request.getParameter("maxBirthdate"), anyOrAll = request.getParameter("anyOrAll"),
            startD = request.getParameter("startdate"), endD = request.getParameter("enddate");

    String[] drugs = request.getParameterValues("drugList");
    String[] drugsByConcepts = request.getParameterValues("drugConceptsList");

    /**********************************************************************************/
    // get drug by id
    if (drugs != null) {
        for (String drug : drugs) {
            drugIds.add(Integer.parseInt(drug));
        }
    } else {
        for (Drug d : service.getArvDrugs()) {
            drugIds.add(d.getDrugId());
        }
    }
    /**********************************************************************************/
    // get drug by concept id
    if (drugsByConcepts != null) {
        for (String conceptStr : drugsByConcepts) {
            drugsByConceptsIds.add(Integer.parseInt(conceptStr));
        }
    } else {
        for (Object obj[] : service.getArvDrugsByConcepts()) {
            drugsByConceptsIds.add((Integer) obj[0]);
        }
    }

    Date minBirthdate = null;
    Date maxBirthdate = null;
    Date minAge = null;
    Date maxAge = null;
    Date startDate = null;
    Date endDate = null;

    DrugOrderControllerMessage message = new DrugOrderControllerMessage();
    String arvConceptIds = DrugOrderExportUtil.gpGetARVConceptIds();
    String arvDrugIds = DrugOrderExportUtil.gpGetARVDrugsIds();
    /*
     * Data validation
     */
    SimpleDateFormat df = OpenmrsUtil.getDateFormat();
    if (startD != null && startD.length() != 0) {
        startDate = df.parse(startD);
    }
    if (endD != null && endD.length() != 0) {
        endDate = df.parse(endD);
    }

    if (mnBirthdate != null && mnBirthdate.length() != 0) {
        minBirthdate = df.parse(mnBirthdate);
    }
    if (mxBirthdate != null && mxBirthdate.length() != 0) {
        maxBirthdate = df.parse(mxBirthdate);
    }

    if (mxAge != null && mxAge.length() != 0) {
        maxAge = service.getDateObjectFormAge(Integer.parseInt(mxAge));
    }
    if (mnAge != null && mnAge.length() != 0) {
        minAge = service.getDateObjectFormAge(Integer.parseInt(mnAge));
    }

    if (rdBtn.equals("drugs")) {
        patientIds = service.searchDrugOrderByDrug(anyOrAll, startDate, endDate,
                service.getListOfDrugsByIds(drugIds), gender, minAge, maxAge, minBirthdate, maxBirthdate);

        if (checkedValue == 1) {
            List<Integer> allPatients = service.searchDrugOrderByDrug(anyOrAll, startDate, endDate,
                    service.getListOfDrugsByIds(drugIds), gender, minAge, maxAge, minBirthdate, maxBirthdate);

            patientIds = service.getActiveOnDrugsPatients(allPatients, arvDrugIds, endDate);

        }
    } else if (rdBtn.equals("concepts")) {
        patientIds = service.searchDrugOrderByDrugsConcepts(anyOrAll, startDate, endDate,
                service.getListOfDrugsByConceptsIds(drugsByConceptsIds), gender, minAge, maxAge, minBirthdate,
                maxBirthdate);

        if (checkedValue == 1)
            patientIds = service.searchDrugOrderByDrugActive(anyOrAll, startDate, endDate,
                    service.getListOfDrugsByConceptsIds(drugsByConceptsIds), gender, minAge, maxAge,
                    minBirthdate, maxBirthdate);

    }

    for (Integer patientId : patientIds) {
        Patient patient = new Patient();

        patient = Context.getPatientService().getPatient(patientId);

        if (!patient.getVoided())
            patients.add(patient);

        Date startTreatmentDate = null;
        Date lastEncounterDate = null;
        Date lastVisitDate = null;
        String startTreatmentDateStr = "";
        String lastEncounterDateStr = "";
        String lastVisitDateStr = "";

        if (service.getPatientLastVisitDate(patientId) != null) {
            lastVisitDate = service.getPatientLastVisitDate(patientId);
            lastVisitDateStr = lastVisitDate.toString();
        }
        if (service.getWhenPatStartedXRegimen(patientId, DrugOrderExportUtil.gpGetARVDrugsIds()) != null) {
            startTreatmentDate = service.getWhenPatientStarted(patient);
            startTreatmentDateStr = startTreatmentDate.toString();
        }
        if (service.getPatientLastEncounterDate(patientId) != null) {
            lastEncounterDate = service.getPatientLastEncounterDate(patientId);
            lastEncounterDateStr = lastEncounterDate.toString();
        }

        List<String> programs = new ArrayList<String>();
        String progAndDate = "";
        Collection<PatientProgram> patientPrograms = Context.getProgramWorkflowService()
                .getPatientPrograms(patient, null, null, null, null, null, false);
        Date date = null;
        if (endDate == null)
            endDate = new Date();
        for (PatientProgram pg : patientPrograms) {
            date = pg.getDateCompleted();
            if (date == null)
                progAndDate += pg.getProgram().getName() + "(Still Enrolled),";
            else if (date != null && date.getTime() <= endDate.getTime())
                progAndDate += pg.getProgram().getName() + " (Completed on " + df.format(pg.getDateCompleted())
                        + "),";
        }
        objectsList.add(new Object[] { Context.getPersonService().getPerson(patientId), startTreatmentDateStr,
                lastEncounterDateStr, lastVisitDateStr, progAndDate });
    }

    Date now = new Date();

    List<String> drugNames = new ArrayList<String>();
    String anyARVs = " ARVs";

    if (rdBtn.equals("drugs")) {
        for (Integer id : drugIds) {
            drugNames.add(Context.getConceptService().getDrug(id).getName());
        }
    }

    if (rdBtn.equals("concepts")) {

        for (Integer conceptId : drugsByConceptsIds) {
            //               if(Context.getConceptService().getDrug(conceptId)!=null)
            drugNames.add(Context.getConceptService().getConcept(conceptId).getName().toString());
        }
    }

    model.put("anyOrAll", anyOrAll);
    if (drugNames != null && drugNames.size() != 0) {
        model.put("drugList", drugNames.toString().substring(1, drugNames.toString().indexOf(']')));
        message.setDrugIds(drugNames.toString().substring(1, drugNames.toString().indexOf(']')));
    } else {
        model.put("drugList", anyARVs);
        message.setDrugIds(anyARVs);
    }

    if (startDate != null) {
        model.put("startdate", df.format(startDate));
        message.setStartDate(df.format(startDate) + "");
    }

    if (endDate != null) {
        model.put("enddate", df.format(endDate));
        message.setEndDate(df.format(endDate) + "");
    }

    if (gender.equals("f")) {
        model.put("gender", "Female");
        message.setGender("Female");
    } else if (gender.equals("")) {
        model.put("gender", "Any");
        message.setGender("Any");
    } else if (!gender.equals("m")) {
        model.put("gender", "Male");
        message.setGender("Male");
    }
    if (minAge != null) {
        model.put("minAge", now.getYear() - minAge.getYear());
        message.setMinAge(now.getYear() - minAge.getYear() + "");
    }
    if (maxAge != null) {
        model.put("maxAge", now.getYear() - maxAge.getYear());
        message.setMaxAge(now.getYear() - maxAge.getYear() + "");
    }
    if (minBirthdate != null) {
        model.put("minBirthdate", df.format(minBirthdate));
        message.setMinBirthdate(df.format(minBirthdate) + "");
    }
    if (maxBirthdate != null) {
        model.put("maxBirthdate", df.format(maxBirthdate));
        message.setMaxBirthdate(df.format(maxBirthdate) + "");
    }

    // for data exportation
    if (request.getParameter("export") != null && !request.getParameter("export").equals("")) {
        if (Context.getAuthenticatedUser().hasPrivilege("Export Collective Patient Data")) {
            if (request.getParameter("export").equals("excel"))
                DrugOrderExportUtil.exportData(request, response, patients);
            if (request.getParameter("export").equals("pdf"))
                DrugOrderExportUtil.exportToPDF(request, response, patients);
        } else {
            model.put("msg", "Required Privilege: [Export Collective Patient Data]");
        }
    }

    model.put("objectsList", objectsList);
    model.put("drugIdback", drugIds);
    model.put("conceptIdsback", drugsByConceptsIds);
    model.put("listSize", objectsList.size());
    model.put("checkedValueExport", checkedValue);
    model.put("rdBtn", rdBtn);

}

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 w w  . j  a 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   w  ww.  ja  v a2 s . 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);
}