Fix problem with different date formats
authorSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Mon, 2 Dec 2013 14:49:35 +0000 (14:49 +0000)
committerSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Mon, 2 Dec 2013 14:49:35 +0000 (14:49 +0000)
server/compbio/controllers/DailyStatisticsController.java

index 22df505..edfe876 100644 (file)
@@ -62,19 +62,28 @@ public class DailyStatisticsController {
        public String findJobsInOneDay(@RequestParam("date") String date, Map<String, Object> model) throws ParseException {
                final long startTime = System.currentTimeMillis();
 
+               String realdate;
                final SimpleDateFormat formaterDDMMYY = new SimpleDateFormat("dd/MM/yyyy");
                final SimpleDateFormat formaterYYMMDD = new SimpleDateFormat("yyyy/MM/dd");
-               String date1 = formaterYYMMDD.format(new Date(formaterDDMMYY.parse(date).getTime()));
-       
+               try {
+                       long thetime = formaterYYMMDD.parse(date).getTime();
+                       if (thetime < 0) {
+                               realdate = date;
+                       } else {
+                               realdate = formaterDDMMYY.format(new Date(thetime));
+                       }
+               } catch (ParseException e) {
+                       realdate = date;
+               }
+
                CassandraRequester cr = new CassandraRequester();
-               //List<DataBase> r1 = cr.countJobs(date1, date1);
-               List<DataBase> r = cr.readJobByDay(date);
+               // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
+               List<DataBase> r = cr.readJobByDay(realdate);
                model.put("results", r);
                model.put("njobs", r.size());
-               model.put("date", date1);
+               model.put("date", realdate);
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
-               System.out.println("Request for date = " + date1 + ": " + r.size() + " jobs found");
                return "/reportJobStatisticsOneDay";
        }
 }