Time comparison

i want to parse and trim a log file. the date format log file looks like:
26 Jan 23:19:26 2004

to get the time in a format i can use i did

t1=Time.parse(“26 Jan 23:19:26 2004”) #string expanded for example
t2=Time.now

i’m want to compare the current date/time with the parsed one from the log.
if the line is older than x number of days it will be ignored.

unfortunately i’m still relatively new a ruby and the ‘principle of
least suprise’ hit me about a dozen times…with suprises :confused:
i’m used to perl’s magic. so i’m here for guideance…

···


http://home.cogeco.ca/~tsummerfelt1

t3 = t2 - 24 * 2600 * x # - for Time work on the seconds
if t1 < t3

Do something about it

It is more than x days old

end

Hope this helps,
Guillaume.

···

On Thu, 2004-01-29 at 13:44, tony summerfelt wrote:

i want to parse and trim a log file. the date format log file looks like:
26 Jan 23:19:26 2004

to get the time in a format i can use i did

t1=Time.parse(“26 Jan 23:19:26 2004”) #string expanded for example
t2=Time.now

i’m want to compare the current date/time with the parsed one from the log.
if the line is older than x number of days it will be ignored.

unfortunately i’m still relatively new a ruby and the ‘principle of
least suprise’ hit me about a dozen times…with suprises :confused:
i’m used to perl’s magic. so i’m here for guideance…


http://home.cogeco.ca/~tsummerfelt1

You can do math on t1 and t2 as if they were numbers. The result is in
seconds.

secondsAgo = t2 - t1
daysAgo = secondsAgo /
        60 /    # seconds per minute
        60 /    # minutes per hour
        24      # hours per day

or, just use the result directly:

    daysAgo = secondsAgo / 86_400 # seconds in a day

-Mark

···

On Thu, Jan 29, 2004 at 06:35:54PM +0000, tony summerfelt wrote:

i want to parse and trim a log file. the date format log file looks like:
26 Jan 23:19:26 2004

to get the time in a format i can use i did

t1=Time.parse(“26 Jan 23:19:26 2004”) #string expanded for example
t2=Time.now

With 3600 seconds in an hour, it even works better!

Sorry,
Guillaume.

···

On Thu, 2004-01-29 at 13:51, Guillaume Marcais wrote:

t3 = t2 - 24 * 2600 * x # - for Time work on the seconds
if t1 < t3

Do something about it

It is more than x days old

end

Hope this helps,
Guillaume.

On Thu, 2004-01-29 at 13:44, tony summerfelt wrote:

i want to parse and trim a log file. the date format log file looks like:
26 Jan 23:19:26 2004

to get the time in a format i can use i did

t1=Time.parse(“26 Jan 23:19:26 2004”) #string expanded for example
t2=Time.now

i’m want to compare the current date/time with the parsed one from the log.
if the line is older than x number of days it will be ignored.

unfortunately i’m still relatively new a ruby and the ‘principle of
least suprise’ hit me about a dozen times…with suprises :confused:
i’m used to perl’s magic. so i’m here for guideance…


http://home.cogeco.ca/~tsummerfelt1

  1. There are 3,600 seconds in an hour, not 2600. :slight_smile:

-Mark

···

On Fri, Jan 30, 2004 at 03:51:31AM +0900, Guillaume Marcais wrote:

t3 = t2 - 24 * 2600 * x # - for Time work on the seconds

i had something like that originally but i was getting something about not
being able to convert floats. i was trying for something object oriented…

sometimes you just have to step back from the oo thing and let common sense
trickle in…

i’m almost embarrased i asked the question now…

all the replies were appreciated…

···

On Thu, 29 Jan 2004 at 18:51 GMT, Guillaume Marcais guslist@free.fr wrote:

t3 = t2 - 24 * 2600 * x # - for Time work on the seconds


http://home.cogeco.ca/~tsummerfelt1

Mark J. Reed wrote:

···

On Fri, Jan 30, 2004 at 03:51:31AM +0900, Guillaume Marcais wrote:

t3 = t2 - 24 * 2600 * x # - for Time work on the seconds

  1. There are 3,600 seconds in an hour, not 2600. :slight_smile:

Not in funkadecimal. :slight_smile:

Ha, he must have been reading 2600 recently.

Hal

In Message-Id: TigSb.551$_62.308@read1.cgocable.net
tony summerfelt snowzone5@hotmail.com writes:

i had something like that originally but i was getting something about not
being able to convert floats. i was trying for something object oriented…

sometimes you just have to step back from the oo thing and let common sense
trickle in…

How about the following?

require "date"

t1 = DateTime.parse("26 Jan 23:19:26 2004").next
t2 = DateTime.now

p t2 > t1

regards.

···


kjana@dm4lab.to January 30, 2004
No gains without pains.

If accuracy really matters to you and funkadecimal doesn’t fancy you,
you can always do:

t3 = t2 - x * (Time.mktime(1960, 1, 2) - Time.mktime(1960, 1, 1))

:slight_smile:

Guillaume.

···

On Thu, 2004-01-29 at 15:14, Hal Fulton wrote:

Mark J. Reed wrote:

On Fri, Jan 30, 2004 at 03:51:31AM +0900, Guillaume Marcais wrote:

t3 = t2 - 24 * 2600 * x # - for Time work on the seconds

  1. There are 3,600 seconds in an hour, not 2600. :slight_smile:

Not in funkadecimal. :slight_smile:

Ha, he must have been reading 2600 recently.

Hal

I am curious what others have found with a learning and development curve
with areas of code that are quite similar.

In the design of a small scale project there will be 2 main systems. Inside
of these systems will be a few more smaller subsystems. The systems will
communicate to eachother via network socket interfaces. This is so we can
have the systems to different machines. I was thinking for expandability
purposes that perhaps we made the subsystems work the same way. So that if
for any reason we found one area getting used a ton that we could move it to
it’s own machine with little effort. Since the 2 main systems would need
socket interfaces to communicate with eachother I am curious if coding the
subsystems would provide unneccessary development time. Or if since the same
logic could be applied that was already coded and tested in the 2 main
systems that the development time may not be unneccessary.

In any of your experiences is this the case? Would the development time for
the subsystems go way down since the main 2 systems have been tested and is
good to go? Or since they are different “systems” would the
learning/development curve still be just as steep?

Thanks for any replies!

Zach

Not sure if its inside the topic at all, nor if it will help, posting
the testimony anyway.

All of our internal software, most automation tasks, content management,
in others, used to be coded in Java, few (very few) on Perl.

Platform used to be Win32 and solaris on x86, more recently we have
moved 90% of it to OpenBSD on x86.

Id honestly say, the first reason to move away from Java was the lack of
support on OpenBSD. Then came the Perl phase.

Honestly saying, we are programming in 1/2 days with Ruby, what we used
to take 1/2 weeks in Java.

Specially the simplicity, and the builtin methods for web, ftp, email
and regexp are the obvious reasons for that.

Not sepcialist in Ruby yet, altho the learning curve for doing the same
software has been considerably low, as we did java and perl before.

One thing we notice is slightly harder to track programming errors, it
took a while to get used to it. But overally, its been well worth it, if
we were able to deploy the same code to the Java VM, that would seal it.

Still portable tho, and runs pretty much in everything.

Again not sure if any usefull on the case, but there it is.

Good luck !

Rove Monteux

Zach Dennis wrote:

···

I am curious what others have found with a learning and development curve
with areas of code that are quite similar.

In the design of a small scale project there will be 2 main systems. Inside
of these systems will be a few more smaller subsystems. The systems will
communicate to eachother via network socket interfaces. This is so we can
have the systems to different machines. I was thinking for expandability
purposes that perhaps we made the subsystems work the same way. So that if
for any reason we found one area getting used a ton that we could move it to
it’s own machine with little effort. Since the 2 main systems would need
socket interfaces to communicate with eachother I am curious if coding the
subsystems would provide unneccessary development time. Or if since the same
logic could be applied that was already coded and tested in the 2 main
systems that the development time may not be unneccessary.

In any of your experiences is this the case? Would the development time for
the subsystems go way down since the main 2 systems have been tested and is
good to go? Or since they are different “systems” would the
learning/development curve still be just as steep?

Thanks for any replies!

Zach


Rove Monteux
Systems Administrator

rove.monteux@fluid-rock.com

Zach Dennis wrote:

I am curious what others have found with a learning and development curve
with areas of code that are quite similar.

In the design of a small scale project there will be 2 main systems. Inside
of these systems will be a few more smaller subsystems. The systems will
communicate to eachother via network socket interfaces. This is so we can
have the systems to different machines. I was thinking for expandability
purposes that perhaps we made the subsystems work the same way. So that if
for any reason we found one area getting used a ton that we could move it to
it’s own machine with little effort. Since the 2 main systems would need
socket interfaces to communicate with eachother I am curious if coding the
subsystems would provide unneccessary development time. Or if since the same
logic could be applied that was already coded and tested in the 2 main
systems that the development time may not be unneccessary.

In any of your experiences is this the case? Would the development time for
the subsystems go way down since the main 2 systems have been tested and is
good to go? Or since they are different “systems” would the
learning/development curve still be just as steep?

Thanks for any replies!

Zach

Having two systems talk across a network is not to big a deal but at
what level do they need to communicate. Could the whole socket thing be
replaced by http requests? This would allow you to step back from socket
programming and use things like Webrick.

Just a thought.

Peter Hickman said:

Having two systems talk across a network is not to big a deal but at
what level do they need to communicate. Could the whole socket thing be
replaced by http requests? This would allow you to step back from socket
programming and use things like Webrick.

Or even something like DRuby!

···


– Jim Weirich jim@weirichhouse.org http://onestepback.org

“Beware of bugs in the above code; I have only proved it correct,
not tried it.” – Donald Knuth (in a memo to Peter van Emde Boas)