I'm trying to find a way to parse at-style time formats, or something
similiar.
Specifically, I'm trying to use RRDTOOL's time format in JRobin. The
time specification is available here:
http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/manual/rrdfetch.html#atstyle_
time_specification
I'm really looking to do something like "now - 5 minutes" or
"yesterday".
It doesn't seem like a way to do this is built-into java, and I hope
I'm wrong ;)
Can anyone help?
Heiner K?cker - 17 Feb 2005 14:58 GMT
Jeffrey.Rodriguez
> I'm trying to find a way to parse at-style time formats, or something
> similiar.
[quoted text clipped - 9 lines]
> It doesn't seem like a way to do this is built-into java, and I hope
> I'm wrong ;)
What you need is an expression lib like beanshell or
Java Expression Formula Parser: http://www.heinerkuecker.de/Expression.html
You can modify my lib with keywords like 'now' for solving your problem.
'now' equals to new Date().
5 minutes is to notate as long value in milliseconds.
(long) 5 * 1000 or 5 * 1000L

Signature
Heiner Kuecker
Internet: http://www.heinerkuecker.de http://www.heiner-kuecker.de
JSP WorkFlow PageFlow Page Flow FlowControl Navigation: http://www.control-and-command.de
Domain Specific Languages http://www.heinerkuecker.de/DomainParser.html
Tony Dahlman - 20 Feb 2005 03:01 GMT
> I'm trying to find a way to parse at-style time formats, or something
> similiar.
[quoted text clipped - 11 lines]
>
> Can anyone help?
Hi Jeffrey!
As best I can tell from the link you supplied, at(...) is a Unix-style
utility that returns a difference between two date/time strings, and uses
the current date/time as the basis if you don't specify it. No, I don't
think you will find it in the standard Java library any time soon.
So much for the bad news. Good news is that all the necessary functionality
is included in the Java libraries if you want to write such a program. But
alas, you were hoping "to find" it, not to create it.
If I'm wrong and you are willing to put a program like this together, you
could look at my DateDiff class:
http://pws.prserv.net/ad/programs/Programs.html#DateDiff
The code at this link shows how to compensate for some of the cautions
mentioned at the tool site in your post.
There is also a way to calculate the date of something in the future using
typical business rules, like first Monday in November, etc:
http://pws.prserv.net/ad/programs/Programs.html#RuleCal
But if you do want to take on a challenge like writing Java code for both
parsing and returning accurate results, you will need to do the work and
it won't be easy. Dates and calendars are notoriously hard to work with
but Java provides classes and methods to deal with it, unlike many other
programming languages.
For a relatively merciless criticism of what Java provides, check out:
http://mindprod.com/jgloss/date.html
There you'll learn about (and be spared of) some gotchas. Most of Roedy's
complaints about the Java library's approach to dates and times are really
related to the Java creators' efforts to take what was out there (Unix) and
go one step further in dealing with the inherent difficulties with calculating
dates.
So if you or another lurker is interested in producing code like what you
describe, please let us all know when it is done. Or you could sell it to
some of us. Good luck!
-- Tony Dahlman

Signature
---------------------------------------
nospam, I've had it, thanks.