In my android program, I have a spinner that allows the user to select different times. Each selection is processed with Joda time to subtract the minutes. It works fine for minutes 0 to 59 and 61 and greater. However, when 60 minutes is subtracted, the time is not updated, and the original time is shown.
How do I get Joda time to subtract 60 minutes?
Spinner:
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id1) {
String mins = parent.getItemAtPosition(pos).toString();
int intmins=0;
// process user's selection of alert time
if(mins.equals("5 minutes")){intmins = 5;}
if(mins.equals("10 minutes")){intmins = 10;}
if(mins.equals("20 minutes")){intmins = 20;}
if(mins.equals("30 minutes")){intmins = 30;}
if(mins.equals("40 minutes")){intmins = 40;}
if(mins.equals("50 minutes")){intmins = 50;}
if(mins.equals("60 minutes")){intmins = 60;}
if(mins.equals("120 minutes")){intmins = 120;}
String stringMinutes=""+intmins;
setAlarm(intmins, stringMinutes);
} else {
}
public void onNothingSelected(AdapterView parent) {
mLocationDisplay.setText(" " + location);
}
}
public void setAlarm(int intmins, String mins) {
// based alarm time on start time of event. TODO get info from database.
String currentDate;
SimpleDateFormat myFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date date1 = null;
DateTime dt;
currentDate = eventdate + " " + startTimeMilitary;// startTimeMilitary;
try {
date1 = myFormat.parse(currentDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dt = new DateTime(date1);
long dateInMillis = dt.getMillis();
String sDateInMillis = Long.toString(dateInMillis);
// subtract the selected time from the event's start time
String newAlertTime = subtractTime(dt, intmins);
newAlertTime = subtractTime(dt, intmins);
//......}