I have a list of objects and each has a date type calendar
. I want to create a filter given two dates that I search for all objects between those dates.
I would also like to create a method that calculates me given today's date which is the previous month or the previous week.
EDIT
is an android application, I have a spinner where I have as option, {today, yesterday, previous week, previous month, yearly} selecting one of these should filter the date according to the ranges and second change a textView saying of which date to which date is being filtered
Calendar actual = GregorianCalendar.getInstance();
//fecha inicio
Calendar c1 = GregorianCalendar.getInstance();
//fecha Fin
public void selectedIntervalo(String intervalo){
switch (intervalo){
case "Ir a Hoy":
datefilter(actual, c1);
break;
case "Vista hayer":
c1.add(Calendar.DATE,-1);
actual.add(Calendar.DATE,-1);
c1.add(Calendar.HOUR,24);
actual.add(Calendar.HOUR,-24);
datefilter(actual, c1);
break;
case "Vista Semana Anterior":
actual.add(Calendar.WEEK_OF_YEAR,-1);
c1.add(Calendar.WEEK_OF_YEAR,-1);
datefilter(actual, c1);
break;
case "Vista Mensual":
actual.add(Calendar.MONTH,-1);
c1.add(Calendar.MONTH,-1);
datefilter(actual,c1);
break;
case "Vista Trimestral":
break;
case "Vista Anual":
break;
case "Personalizar":
break;
default:
fechaActual();
break;
}
}
public String datefilter(Calendar date, Calendar i){
SimpleDateFormat formateador = new SimpleDateFormat("dd/MM");
return "Del: " +formateador.format(date)+" hasta el "+formateador.format(i);
}
I still need to quarterly annual but the dates do not come out as I would like a serious example if I say for the previous month considering that today is 14/01/2015 should I say Del: 01/11/2014 until 31/11 / 2014