From: Sasa M. <sa...@us...> - 2005-02-17 11:21:54
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13439/org/jrobin/core Modified Files: Util.java Log Message: Added two nice, simple methods to obtain timestamp(s) from (un)related at-style time specification(s) Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** Util.java 23 Jan 2005 20:31:25 -0000 1.31 --- Util.java 17 Feb 2005 11:21:45 -0000 1.32 *************** *** 32,35 **** --- 32,37 ---- import org.xml.sax.InputSource; import org.xml.sax.SAXException; + import org.jrobin.core.timespec.TimeSpec; + import org.jrobin.core.timespec.TimeParser; import javax.xml.parsers.ParserConfigurationException; *************** *** 250,253 **** --- 252,288 ---- } + /** + * Parses at-style time specification and returns the corresponding timestamp. For example:<p> + * <pre> + * long t = Util.getTimestamp("now-1d"); + * </pre> + * @param atStyleTimeSpec at-style time specification. For the complete explanation of the syntax + * allowed see RRDTool's <code>rrdfetch</code> man page.<p> + * @return timestamp in seconds since epoch. + * @throws RrdException Thrown if invalid time specification is supplied. + */ + public static long getTimestamp(String atStyleTimeSpec) throws RrdException { + TimeSpec timeSpec = new TimeParser(atStyleTimeSpec).parse(); + return timeSpec.getTimestamp(); + } + + /** + * Parses two related at-style time specifications and returns corresponding timestamps. For example:<p> + * <pre> + * long[] t = Util.getTimestamps("end-1d","now"); + * </pre> + * @param atStyleTimeSpec1 Starting at-style time specification. For the complete explanation of the syntax + * allowed see RRDTool's <code>rrdfetch</code> man page.<p> + * @param atStyleTimeSpec2 Ending at-style time specification. For the complete explanation of the syntax + * allowed see RRDTool's <code>rrdfetch</code> man page.<p> + * @return An array of two longs representing starting and ending timestamp in seconds since epoch. + * @throws RrdException Thrown if any input time specification is invalid. + */ + public static long[] getTimestamps(String atStyleTimeSpec1, String atStyleTimeSpec2) throws RrdException { + TimeSpec timeSpec1 = new TimeParser(atStyleTimeSpec1).parse(); + TimeSpec timeSpec2 = new TimeParser(atStyleTimeSpec2).parse(); + return TimeSpec.getTimestamps(timeSpec1, timeSpec2); + } + /** * Parses input string as a double value. If the value cannot be parsed, Double.NaN |