in reply to Time::Piece errors?

Hello All,
Thanks for that i know it was something simple.
It just one of those days when you cant see the woods of the trees

I have corrected the code below. But now im getting strange minute times
Time now is:Thu May 1 11:02:12 2003
0 years, 0 months, 0 days since , 0 hours since, 2 min since Thu May 1 10:00:00 2003

anymore ideas you can send my way?

regards
Gareth

#!/usr/bin/perl use Time::Piece; use Time::Seconds; $before = Time::Piece->strptime("2003/05/01 10:00:00", "%Y/%m/%d %H:%M +:%S"); $now = localtime(time); print "Time now is:$now\n"; $diff = $now - $before; $years = int($diff->years); $diff -= $years * ONE_YEAR; $months = int($diff->months); $diff -= $months * ONE_MONTH; $days = int($diff->days); $diff -= $hours * ONE_HOUR; $hours = int($diff->hours); $diff -= $minutes * ONE_MINUTES; $minutes = int($diff->minutes); $diff -= $minutes * ONE_SECONDS; $secounds = int($diff->seconds); print "$years years, $months months, $days days since , $hours hours s +ince, $minutes min since $before\n";

Replies are listed 'Best First'.
Re: Re: Time::Piece errors?
by benn (Vicar) on May 01, 2003 at 10:47 UTC
    This is a problem with daylight-saving. Time::Piece->strptime creates a GMT date, which you're then comparing to localtime()'s representation of time(), so it appears to be an hour out. You'll probably need to use the isdst() function to add ONE_HOUR if necessary. BTW, there's another slight cut'n'paste error - you need to subtract $days * ONE_DAY as well, and then swap the rest of your lines to the bottom of that block.

    Hope this helps
    Ben.
Re: Re: Time::Piece errors?
by spacey (Scribe) on May 01, 2003 at 10:17 UTC
    Opps spotted a typo $diff -= $minutes * ONE_SECONDS;
    should have been $diff -= $seconds * ONE_SECONDS;
    but this has made no difference with my minute problem?

    Regards,
    Gareth