Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Calculate Age, days to next and days from last for a given birthday

by ruzam (Curate)
on Apr 28, 2006 at 20:46 UTC ( [id://546403]=note: print w/replies, xml ) Need Help??


in reply to Re: Calculate Age, days to next and days from last for a given birthday
in thread Calculate Age, days to next and days from last for a given birthday

The time period in this case would I guess be midnight as that's when the date would switch over. Wouldn't it be more appropriate to have that happen on local time? Otherwise your birthdate wouldn't flip until gmtime midnight, which wouldn't be correct (unless you happen to be living on the gm time line).
  • Comment on Re^2: Calculate Age, days to next and days from last for a given birthday

Replies are listed 'Best First'.
Re^3: Calculate Age, days to next and days from last for a given birthday
by ikegami (Patriarch) on Apr 28, 2006 at 21:15 UTC
    As you can see in my (newly added) code, I work with *local* dates using timegm+gmtime. The number of days bewteen two dates is the same no matter which time zone you are in.
      OK, I see now how your code works works (took me a while, sorry). But I'm still confused as to the need to convert to seconds.

      my $days = (localtime)[7];
      $days will be correct for the current date regardless of the time or DST no? All other days are calculated as of 0:00:00 which should also be correct for any given date regardless of DST. Or am I missing something about the way localtime/timelocal work?
      (living in a time zone with no DST does have it's disadvantages here).

      I never thought of feb 29 birthdates failing as invalid dates in non-leap years!
        But I'm still confused as to the need to convert to seconds.

        You can't do arithmetic on years+months+days. Just like you can't do arithmetic on degrees+minutes+seconds. You need to convert it into a number.

        I could have converted every date into the number of days since an arbitrary day, but there's no existing function to do that (or the inverse operation). Doing it manually would force me to handle leap seconds, leap days, oddly numbered months, etc.

        On the other hand, there's already a function (timegm) to convert a date into the number of seconds since an arbitrary second (Jan 1st, 1970, 0:00:00), and there's already a function which does the inverse operation (gmtime).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://546403]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found