in reply to Timeleft subroutine

For the interface, I would be thinking about seconds as a return value from timeleft(). Perhaps like something below or maybe not? Your idea has some problems, like what happens at midnight?

In general I would design the subs to work in seconds from the "epoch" date/time and have some conversion routines - Yes, there are exceptions, but I don't know enough about your app.

There are also some Perl modules: Date::Time and Date::Calc that work well.

#!/usr/bin/perl -w use strict; use Time::Local; # a CORE function (no install needed) # $time = timelocal($sec,$min,$hour,$mday,$mon,$year); print "current time is: ".localtime(),"\n"; print "seconds left until 8/30/2012 5:32 AM\n"; print seconds_left(2012,8,30,5,32,0), "\n"; sub seconds_left { my ($year, $month, $dayOfMonth, $hour, $minutes, $seconds) = @_; my $expiration_seconds = timelocal($seconds, $minutes, $hour, $dayOfMonth, $month-1, $year); my $current_seconds = time(); return ($expiration_seconds - $current_seconds); } __END__ current time is: Thu Aug 30 05:31:30 2012 seconds left until 8/30/2012 5:32 AM 30
This whole time/date stuff can get complicated. I mean like what happens when there is a leap year? What happens when there is a time switch from "normal time" to "daylight savings time"? I guess this year (2012) we had a "leap second".

In general, I would advise that your program work with GMT or what is now called UTC time - yes there is slight difference between these terms - but if you know enough to argue, then you already understand it well enough that we don't have to. Use UTC/GMT internally and convert to "local time" as needed.