in reply to Yesterday Date

A variation on a classic:

my $yesterday_datetime = time; sleep 86_400;
A word spoken in Mind will reach its own level, in the objective world, by its own weight

Replies are listed 'Best First'.
Re^2: Yesterday Date
by Tanktalus (Canon) on Feb 05, 2008 at 00:26 UTC

    This code has some serious problems. First of all, what if the current time is 11:30PM right before the Spring daylight-savings switch? After your sleep, it'll be 12:30AM two days later, not just one.

    Second scenario is that it's 12:30AM the morning of the Autumn switch? After your sleep, it'll be 11:30AM the same day.

    These are serious problems that you need to address.

    How about 12:00:00.1AM (midnight) on a day that has a leap *second* attached? After 86_400 seconds, you end up right before midnight on the same day!

    Serious serious problems with this code.

    :-)

Re^2: Yesterday Date
by Narveson (Chaplain) on Feb 05, 2008 at 15:24 UTC

    Pay attention to the stated requirements.

    How can I get yesterday's date from today's date, but making sure I don't get weekends for yesterday's date.

    my @is_business_day = (0, 1 x 5, 0); SNOOZE: while (sleep 86_400) { my $wday = ( localtime )[6]; last SNOOZE if $business_day[$wday]; } my $prev_business_day_datetime = time; sleep 86_400;

    This code is untested.