From 13b19f407f03dbcbd310c0e2f7118dcc352493f5 Mon Sep 17 00:00:00 2001 From: Sasha Sherstnev Date: Mon, 2 Dec 2013 14:49:35 +0000 Subject: [PATCH] Fix problem with different date formats --- .../controllers/DailyStatisticsController.java | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/server/compbio/controllers/DailyStatisticsController.java b/server/compbio/controllers/DailyStatisticsController.java index 22df505..edfe876 100644 --- a/server/compbio/controllers/DailyStatisticsController.java +++ b/server/compbio/controllers/DailyStatisticsController.java @@ -62,19 +62,28 @@ public class DailyStatisticsController { public String findJobsInOneDay(@RequestParam("date") String date, Map 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 r1 = cr.countJobs(date1, date1); - List r = cr.readJobByDay(date); + // IMPORTANT: input should be suppied in the format: DD/MM/YYYY + List 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"; } } -- 1.7.10.2