@Test public void testExplicitTimeSpec() { m_request.addParameter("start", "123456789"); m_request.addParameter("end", "123456790"); long[] result = m_controller.parseTimes(m_request); assertEquals(123456789, result[0]); assertEquals(123456790, result[1]); }
public long[] parseTimes(HttpServletRequest request) { String startTime = request.getParameter("start"); String endTime = request.getParameter("end"); if(startTime == null || "".equals(startTime)) { startTime = "now - 1day"; } if(endTime == null || "".equals(endTime)) { endTime = "now"; } boolean startIsInteger = false; boolean endIsInteger = false; long start = 0, end = 0; try { start = Long.valueOf(startTime); startIsInteger = true; } catch (NumberFormatException e) { } try { end = Long.valueOf(endTime); endIsInteger = true; } catch (NumberFormatException e) { } if(endIsInteger && startIsInteger) { return new long[] {start, end}; } if(startIsInteger) { startTime = ""+(start/1000); } if(endIsInteger) { endTime = "" +(end/1000); } TimeParser startParser = new TimeParser(startTime); TimeParser endParser = new TimeParser(endTime); try { TimeSpec specStart = startParser.parse(); TimeSpec specEnd = endParser.parse(); long results[] = TimeSpec.getTimestamps(specStart, specEnd); results[0] = results[0]*1000; results[1] = results[1]*1000; return results; } catch (RrdException e) { throw new IllegalArgumentException("Could not parse start '"+ startTime+"' and end '"+endTime+"' as valid time specifications", e); } }
RrdGraphController extends AbstractController { public long[] parseTimes(HttpServletRequest request) { String startTime = request.getParameter("start"); String endTime = request.getParameter("end"); if(startTime == null || "".equals(startTime)) { startTime = "now - 1day"; } if(endTime == null || "".equals(endTime)) { endTime = "now"; } boolean startIsInteger = false; boolean endIsInteger = false; long start = 0, end = 0; try { start = Long.valueOf(startTime); startIsInteger = true; } catch (NumberFormatException e) { } try { end = Long.valueOf(endTime); endIsInteger = true; } catch (NumberFormatException e) { } if(endIsInteger && startIsInteger) { return new long[] {start, end}; } if(startIsInteger) { startTime = ""+(start/1000); } if(endIsInteger) { endTime = "" +(end/1000); } TimeParser startParser = new TimeParser(startTime); TimeParser endParser = new TimeParser(endTime); try { TimeSpec specStart = startParser.parse(); TimeSpec specEnd = endParser.parse(); long results[] = TimeSpec.getTimestamps(specStart, specEnd); results[0] = results[0]*1000; results[1] = results[1]*1000; return results; } catch (RrdException e) { throw new IllegalArgumentException("Could not parse start '"+ startTime+"' and end '"+endTime+"' as valid time specifications", e); } } }
RrdGraphController extends AbstractController { public long[] parseTimes(HttpServletRequest request) { String startTime = request.getParameter("start"); String endTime = request.getParameter("end"); if(startTime == null || "".equals(startTime)) { startTime = "now - 1day"; } if(endTime == null || "".equals(endTime)) { endTime = "now"; } boolean startIsInteger = false; boolean endIsInteger = false; long start = 0, end = 0; try { start = Long.valueOf(startTime); startIsInteger = true; } catch (NumberFormatException e) { } try { end = Long.valueOf(endTime); endIsInteger = true; } catch (NumberFormatException e) { } if(endIsInteger && startIsInteger) { return new long[] {start, end}; } if(startIsInteger) { startTime = ""+(start/1000); } if(endIsInteger) { endTime = "" +(end/1000); } TimeParser startParser = new TimeParser(startTime); TimeParser endParser = new TimeParser(endTime); try { TimeSpec specStart = startParser.parse(); TimeSpec specEnd = endParser.parse(); long results[] = TimeSpec.getTimestamps(specStart, specEnd); results[0] = results[0]*1000; results[1] = results[1]*1000; return results; } catch (RrdException e) { throw new IllegalArgumentException("Could not parse start '"+ startTime+"' and end '"+endTime+"' as valid time specifications", e); } }  }
RrdGraphController extends AbstractController { public long[] parseTimes(HttpServletRequest request) { String startTime = request.getParameter("start"); String endTime = request.getParameter("end"); if(startTime == null || "".equals(startTime)) { startTime = "now - 1day"; } if(endTime == null || "".equals(endTime)) { endTime = "now"; } boolean startIsInteger = false; boolean endIsInteger = false; long start = 0, end = 0; try { start = Long.valueOf(startTime); startIsInteger = true; } catch (NumberFormatException e) { } try { end = Long.valueOf(endTime); endIsInteger = true; } catch (NumberFormatException e) { } if(endIsInteger && startIsInteger) { return new long[] {start, end}; } if(startIsInteger) { startTime = ""+(start/1000); } if(endIsInteger) { endTime = "" +(end/1000); } TimeParser startParser = new TimeParser(startTime); TimeParser endParser = new TimeParser(endTime); try { TimeSpec specStart = startParser.parse(); TimeSpec specEnd = endParser.parse(); long results[] = TimeSpec.getTimestamps(specStart, specEnd); results[0] = results[0]*1000; results[1] = results[1]*1000; return results; } catch (RrdException e) { throw new IllegalArgumentException("Could not parse start '"+ startTime+"' and end '"+endTime+"' as valid time specifications", e); } }  long[] parseTimes(HttpServletRequest request); RrdGraphService getRrdGraphService(); void setRrdGraphService(RrdGraphService rrdGraphService); }
RrdGraphController extends AbstractController { public long[] parseTimes(HttpServletRequest request) { String startTime = request.getParameter("start"); String endTime = request.getParameter("end"); if(startTime == null || "".equals(startTime)) { startTime = "now - 1day"; } if(endTime == null || "".equals(endTime)) { endTime = "now"; } boolean startIsInteger = false; boolean endIsInteger = false; long start = 0, end = 0; try { start = Long.valueOf(startTime); startIsInteger = true; } catch (NumberFormatException e) { } try { end = Long.valueOf(endTime); endIsInteger = true; } catch (NumberFormatException e) { } if(endIsInteger && startIsInteger) { return new long[] {start, end}; } if(startIsInteger) { startTime = ""+(start/1000); } if(endIsInteger) { endTime = "" +(end/1000); } TimeParser startParser = new TimeParser(startTime); TimeParser endParser = new TimeParser(endTime); try { TimeSpec specStart = startParser.parse(); TimeSpec specEnd = endParser.parse(); long results[] = TimeSpec.getTimestamps(specStart, specEnd); results[0] = results[0]*1000; results[1] = results[1]*1000; return results; } catch (RrdException e) { throw new IllegalArgumentException("Could not parse start '"+ startTime+"' and end '"+endTime+"' as valid time specifications", e); } }  long[] parseTimes(HttpServletRequest request); RrdGraphService getRrdGraphService(); void setRrdGraphService(RrdGraphService rrdGraphService);  }