年月日から曜日を求める/閏年判定などいろいろ

@GetsuN   = ('31','28','31','30','31','30','31','31',
            '30','31','30','31');
@keyYoubi = ('Sunday','Monday','Tuesday','Wednesday',
            'Thursday','Friday','Saturday');
@keyMonth = ('Jan','Feb','Mar','Apr','May','Jun','Jul',
            'Aug','Sep','Oct','Nov','Dec');

#年月日から曜日を求める
# 引数:年、月、日
# 戻値:曜日(0="日",1="月",2="火",3="水",4="木",5="金",6="土")
sub getYoubi{
    local($year, $mon, $day) = @_;
    local($Xsec, $Xmin, $Xhour, $Xday, $Xmon, 
          $Xyear, $Xwday, $Xyday, $Xisdst);
    $time = &getT($year,$mon,$day);
    ($Xsec, $Xmin, $Xhour, $Xday, $Xmon, $Xyear, 
                   $Xwday, $Xyday, $Xisdst) = gmtime($time);
    return($Xwday);
}

#localtime、gmtimeの引数にできる数字を求める
# 引数:年、月、日
# 戻値:localtimeやgmtimeの引数にできる数字
sub getT{
    local($year, $mon, $day) = @_;
    local($dayY, $time, $i);
    $dayY = 0;
    $mon = $mon - 1;
    $dayY += ($year - 1) * 365 + int(($year - 1) / 4) - 
             int(($year - 1) / 100) + int(($year - 1) / 400);
    for($i = 0; $i < $mon; $i++){
        $dayY += $GetsuN[$i];
        if($i == 1 && &Ururu($year)){$dayY++;}
    }
    $dayY += $day;
    $time = ($dayY- 719163) * 24 * 60 * 60;
    return ($time);
}

#閏年判定
# 引数:年
# 戻値:1 -> 閏年 / 0 -> 閏年以外
sub Ururu{
    local($year) = shift;
    if(($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0){
        return 1;
    }else{
        return 0;
    }
}

#日付かどうかのチェック
# 引数:年、月、日
# 戻値:1 -> 日付 / 0 -> 日付以外
sub chkDate{
    my($year, $month, $day) = @_;
    my($flg) = 0;
    my(@tmp) = @GetsuN;
    if ($month < 1 || 12 < $month) {return 0;}
    if ($month == 2) {
        $flg = &Ururu($year);
        if($flg){$tmp[1] ++;}
    }
    if ($day < 1 || $tmp[$month-1] < $day) {return 0;}
    return 1;
}