Hour data for a Spinner

3

I have a Spinner and as data these hours:

final String[] horasInicio = new String[] {
            "09:00",
            "09:30",
            "10:00",
            "10:30",
            "11:00",
            "11:30",
            "12:00",
            "12:30",
            "13:00",
            "13:30",
            "14:00",
            "14:30",
            "15:00",
            "15:30",
            "16:00",
            "16:30",
            "17:00",
            "17:30",
            "18:00",
            "18:30",
            "19:00",
            "19:30",
            "20:00",
            "20:30"
    };

How can I do so that if they are, for example, 11:49, another array or ArrayList is generated that has the spinner data that would be 12:00, 12:30, 13:00, 13:30. .. until 20:30. If it is 13:12, then generate a list with the data 13:30, 14:00, 14:30 ... until 20:30. are the hours of beginning of reservations, so if it is 11:49, the logical thing is that the first hour of reservation is 12:00 and as you can reserve half an hour in half an hour, go 12:00, 12 : 30 ... 20:30.

    
asked by Red 15.06.2016 в 17:37
source

1 answer

0

I would do it in the following way, before saving the hours in string I would have them in int

final int[] horasInicio = new int[] { 900, 930, 1000, 1030, 1100, 1130, 1200, 1230, 1300, 1330, 1400, 1430, 1500, 1530, 1600, 1630, 1700, 1730, 1800, 1830, 1900, 1930, 2000, 2030 };

List<Integer> horasReserva = new ArrayList<>();


int hora = 1149; 

//obtener una lista con las reservas posibles
for (int i=0;i < horasInicio.length;++i) {
    if (hora < horasInicio[i])  horasReserva.add(horasInicio[i]);
}

//mostrar las reservas
for (int i=0;i < horasReserva.size();++i) {
    System.out.println(horasReserva.get(i));
}

Only the part of converting 11:49 to int and int to format 00:00

remains

Another more consistent way would be to convert the hours to total minutes.

    
answered by 16.06.2016 / 11:29
source