--002354470c4c9e96a004b6bb1b45
Content-Type: text/plain; charset=UTF-8

On Tue, Jan 17, 2012 at 4:26 PM, Christopher Graves <gravescl / gmail.com>wrote:

> Robert Klemme wrote in post #1041261:
> > On Mon, Jan 16, 2012 at 11:56 PM, Christopher Graves
> > <gravescl / gmail.com> wrote:
> >>
> >> What would be the best way to get the current time formatted per the log
> >> entries and collect a range of times say from current to 15 minutes
> >> previously.
> >
> > I am not sure what you mean by "collect a range".  Parsing can be done
> > like this:
> >
> > require 'time'
> > t  ime.strptime('01/10/2012 14:46:02:86', '%m/%d/%Y %H:%M:%S:%L')
> >
> > Cheers
> >
> > robert
>
> Thanks Robert,
>
> By collect range, how would I say subtract 15 minutes from the current
> time so that I can collect all matches from 14:31:02 through 14:46:02?
>

1.9.3p0 :006 > Time.now.to_s
 "2012-01-17 16:36:06 +0100"
1.9.3p0 :007 > (Time.now - (15*60)).to_s
 "2012-01-17 16:21:09 +0100"

Do you want to use string comparison on the lines (and not compare "Time"
entries) ? In that case ... be careful with your date format that has
mm/dd/yyyy ... When your filter goes over a midnight boundary, you may
get incorrect results.

For this kind of "technical" reading of log times, I would certainly advise
a
format YYYY/MM/DD ... so that you can sort and filter on the string
representations
(assuming that was your intention from the original posting). This is
actually
the default (ISO I think ?) format that is returned by Time#to_s.

HTH,

Peter

--002354470c4c9e96a004b6bb1b45--