edu_check_times

one of the documented procedures in this installation of the ACS
Usage:
edu_check_times   start_hour   start_minute   start_ampm   end_hour   end_minute   end_ampm   { equal_p "f" }
What it does:
This checks to make sure that the start time comes befor the end time. If any of the arguments are null or the start time does in fact come before the end time then the procedure returns 1. Otherwise, it returns 0.
Defined in: /web/philip/tcl/education.tcl

Source code:


    if {[empty_string_p $start_hour] || [empty_string_p $start_minute] || [empty_string_p $start_ampm] || [empty_string_p $end_hour] || [empty_string_p $end_minute] || [empty_string_p $end_ampm]} {
	return 1
    }
    
    # if the start time is in the AM and the end time is in the PM then
    # return true (1)
    if {[string compare [string tolower $start_ampm] am] == 0 && [string compare [string tolower $end_ampm] pm] == 0} {
	return 1
    } elseif {[string compare [string tolower $start_ampm] pm] == 0 && [string compare [string tolower $end_ampm] am] == 0} {
	return 0
    }

    # we know that the AM and PM are the same...now we want to check the 
    # hours and minutes
    if {$start_hour == 12} {
	set start_hour 0
    }
    if {$end_hour == 12} {
	set end_hour 0
    }

    # we do regexp's so that we can do math even if we get
    # something like 09 (which TCL thinks is not a valid octal
    # number and yells at)  We do not need to do it for minutes
    # because we are making the assumtion that minutes are
    # 00, 05, or > 10

    if {[string length $start_hour] > 1} {
	regexp {0?(.*)} $start_hour match start_hour
    }
    if {[string length $end_hour] > 1} {
	regexp {0?(.*)} $end_hour match end_hour
    }


    if {[string compare $equal_p f] == 0} {
	# if the start_time is strictly less than the end time, return 1
	if {[expr $start_hour * 60 + $start_minute] >= [expr $end_hour * 60 + $end_minute]} {
	    return 0
	} else {
	    return 1
	}
    } else {
	if {[expr $start_hour * 60 + $start_minute] > [expr $end_hour * 60 + $end_minute]} {
	    return 0
	} else {
	    return 1
	}
    }


philg@mit.edu