in reply to Morning or Night?

A quick fix would be:
$ampm = "AM"; if ($central_time_hour%24 > 11) { $ampm = "PM"; }
Though it still looks rather convoluted to me....

Perhaps something like:

$ampm = ($central_time_hour%24 > 11) ? "PM" : "AM";
Might make this one stanza a bit better.

Update: demerphq caught me moving the bug from midnight to noon... changed constants back to 11 to fix it.

-Blake

Replies are listed 'Best First'.
Re: Re: Morning or Night?
by Kanji (Parson) on Jan 12, 2002 at 14:26 UTC

    To expand on blakem's solution, the % 24 is needed to make sure you stay within the confines of a 24 hour clock ... otherwise you end up with a non-existant 25th hour (which is > 12, hence PM :)).

    Unfortunately, setting $ENV{TZ} doesn't appear to be all that portable (works under FreeBSD and prolly the other Unices, but not Windows), otherwise you could simplify all of that code and logic to ...

    use POSIX 'strftime'; my $timezone = 'CST6CDT'; # EST5EDT MST7MDT PST8PDT my $date = do { local $ENV{TZ} = $timezone; strftime( '%y %m %A %I %M %S %p', localtime ); }; my($year,$month,$day,$hour,$mins,$secs,$ampm) = split( ' ', $date );

        --k.