I'm making a report on java
, which passes a period specified by the user. In my%% of% I'm doing the treatment.
Here I pick up the date passed.
String data1 = DateUtil.toString(dto.getDataInicio(), "MM/yyyy");
String data2 = DateUtil.toString(dto.getDataFim(), "MM/yyyy");
Calendar c1 = DateUtil.parseCal (data1);
Calendar c2 = DateUtil.parseCal (data2);
Here I make a treatment to check the past months.
for (Calendar c = (Calendar) c1.clone(); c.compareTo (c2) <= 0; c.add (Calendar.DATE, +1)) {
if (c.get (Calendar.MONTH) == Calendar.JANUARY && c.get (Calendar.DAY_OF_MONTH) == 01){
mesesql += "total_faturado_mensal(cs.id_corp, '"+c1.get(Calendar.YEAR)+"-01-01', '"+c2.get(Calendar.YEAR)+"-01-01', to_char('"+c1.get(Calendar.YEAR)+"-01-01'::date, 'yyyy-mm'), cl.id_convenio) as janeiro, ";
nomesMeses.add("Janeiro");
}
if (c.get (Calendar.MONTH) == Calendar.FEBRUARY && c.get (Calendar.DAY_OF_MONTH) == 01){
mesesql += "total_faturado_mensal(cs.id_corp, '"+c1.get(Calendar.YEAR)+"-02-01', '"+c2.get(Calendar.YEAR)+"-02-01', to_char('"+c1.get(Calendar.YEAR)+"-02-01'::date, 'yyyy-mm'), cl.id_convenio) as fevereiro, ";
nomesMeses.add("Fevereiro");
}
if (c.get (Calendar.MONTH) == Calendar.MARCH && c.get (Calendar.DAY_OF_MONTH) == 01){
mesesql += "total_faturado_mensal(cs.id_corp, '"+c1.get(Calendar.YEAR)+"-03-01', '"+c2.get(Calendar.YEAR)+"-03-01', to_char('"+c1.get(Calendar.YEAR)+"-03-01'::date, 'yyyy-mm'), cl.id_convenio) as marco, ";
nomesMeses.add("Março");
}
if (c.get (Calendar.MONTH) == Calendar.APRIL && c.get (Calendar.DAY_OF_MONTH) == 01){
mesesql += "total_faturado_mensal(cs.id_corp, '"+c1.get(Calendar.YEAR)+"-04-01', '"+c2.get(Calendar.YEAR)+"-04-01', to_char('"+c1.get(Calendar.YEAR)+"-04-01'::date, 'yyyy-mm'), cl.id_convenio) as abril, ";
nomesMeses.add("Abril");
}
if (c.get (Calendar.MONTH) == Calendar.MAY && c.get (Calendar.DAY_OF_MONTH) == 01){
mesesql += "total_faturado_mensal(cs.id_corp, '"+c1.get(Calendar.YEAR)+"-05-01', '"+c2.get(Calendar.YEAR)+"-05-01', to_char('"+c1.get(Calendar.YEAR)+"-05-01'::date, 'yyyy-mm'), cl.id_convenio) as maio, ";
nomesMeses.add("Maio");
}
if (c.get (Calendar.MONTH) == Calendar.JUNE && c.get (Calendar.DAY_OF_MONTH) == 01){
mesesql += "total_faturado_mensal(cs.id_corp, '"+c1.get(Calendar.YEAR)+"-06-01', '"+c2.get(Calendar.YEAR)+"-06-01', to_char('"+c1.get(Calendar.YEAR)+"-06-01'::date, 'yyyy-mm'), cl.id_convenio) as junho, ";
nomesMeses.add("Junho");
}
if (c.get (Calendar.MONTH) == Calendar.JULY && c.get (Calendar.DAY_OF_MONTH) == 01){
mesesql += "total_faturado_mensal(cs.id_corp, '"+c1.get(Calendar.YEAR)+"-07-01', '"+c2.get(Calendar.YEAR)+"-07-01', to_char('"+c1.get(Calendar.YEAR)+"-07-01'::date, 'yyyy-mm'), cl.id_convenio) as julho, ";
nomesMeses.add("Julho");
}
if (c.get (Calendar.MONTH) == Calendar.AUGUST && c.get (Calendar.DAY_OF_MONTH) == 01){
mesesql += "total_faturado_mensal(cs.id_corp, '"+c1.get(Calendar.YEAR)+"-08-01', '"+c2.get(Calendar.YEAR)+"-08-01', to_char('"+c1.get(Calendar.YEAR)+"-08-01'::date, 'yyyy-mm'), cl.id_convenio) as agosto, ";
nomesMeses.add("Agosto");
}
if (c.get (Calendar.MONTH) == Calendar.SEPTEMBER && c.get (Calendar.DAY_OF_MONTH) == 01){
mesesql += "total_faturado_mensal(cs.id_corp, '"+c1.get(Calendar.YEAR)+"-09-01', '"+c2.get(Calendar.YEAR)+"-09-01', to_char('"+c1.get(Calendar.YEAR)+"-09-01'::date, 'yyyy-mm'), cl.id_convenio) as setembro, ";
nomesMeses.add("Setembro");
}
if (c.get (Calendar.MONTH) == Calendar.OCTOBER && c.get (Calendar.DAY_OF_MONTH) == 01){
mesesql += "total_faturado_mensal(cs.id_corp, '"+c1.get(Calendar.YEAR)+"-10-01', '"+c2.get(Calendar.YEAR)+"-10-01', to_char('"+c1.get(Calendar.YEAR)+"-10-01'::date, 'yyyy-mm'), cl.id_convenio) as outubro, ";
nomesMeses.add("Outubro");
}
if (c.get (Calendar.MONTH) == Calendar.NOVEMBER && c.get (Calendar.DAY_OF_MONTH) == 01){
mesesql += "total_faturado_mensal(cs.id_corp, '"+c1.get(Calendar.YEAR)+"-11-01', '"+c2.get(Calendar.YEAR)+"-11-01', to_char('"+c1.get(Calendar.YEAR)+"-11-01'::date, 'yyyy-mm'), cl.id_convenio) as novembro, ";
nomesMeses.add("Novembro");
}
if (c.get (Calendar.MONTH) == Calendar.DECEMBER && c.get (Calendar.DAY_OF_MONTH) == 01){
mesesql += "total_faturado_mensal(cs.id_corp, '"+c1.get(Calendar.YEAR)+"-12-01', '"+c2.get(Calendar.YEAR)+"-12-01', to_char('"+c1.get(Calendar.YEAR)+"-12-01'::date, 'yyyy-mm'), cl.id_convenio) as dezembro, ";
nomesMeses.add("Dezembro");
}
}
It is working, however when reporting a period for example from 01/2016 to 12/2016 it is not entering within DAO
then only from January to November. But if I put only 11/2016 and 12/2016 the December appears.
And to appear the 12 months of 2016, I have to put a month amis for example:
01/2016 á 01/2017 ai yes it brings me the month of December .... and so consequently, with larger dates. I do not understand much how Calendar works, am I doing something wrong?