我有一個例程來確定它是週末還是星期幾,但它無法在星期五正常工作。有問題的日期時間能夠計算除星期五之外的星期幾
我創建了一個測試程序,以瞭解爲什麼在7PM(19:00:00)之前,例程將當天視爲工作日和晚上7點,並將該日視爲週末。
#!/usr/bin/perl
use DateTime;
MONTHCHECK:
my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset,
$dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dcm);
my $mnth = $abbr[$month];
WEEKENDCHECK:
if (DateTime->today->day_of_week >= 6 && day_of_week <= 7) {
print "$dayOfWeek is today \n";
goto HOLIDAY;
} else {
print "going to weekday";
goto WEEKDAY;
}
WEEKDAY:
print "weekday section month is $mnth \n";
goto END;
HOLIDAY:
my $h = "h";
my $mth = join "", $mnth, $h;
print "holiday section month is $mth \n";
goto END;
END:
print "$date is the day and $hour hr \n";
print "$date is the day \n";
exit(0);
18時50分00秒之前,我得到正確的結果:
going to weekday5 is today
weekday section month is Jan
29-01-2016 is the day and 18 hr
It is now Fri Jan 29 18:50:02 2016
19:00:00後,我得到以下結果:
5 is today
holiday section month is Janh
is the day and 19 hr
It is now Fri Jan 29 19:04:21 2016
感謝您的DateTime捕獲。我不明白在哪裏休息是與goto的其他。 – BrianB
我已經結束了日常工作,不明白GOTO是如何造成問題的。有人可以幫助我解決這個問題嗎? – BrianB