Validates that an academic year string meets Stanford's format requirements and constraints. Checks both the string format and the logical relationship between start and end years. Also enforces historical data boundaries.
Value
Character string. Returns:
Empty string (
""
) if input isNULL
Original year string if validation passes
Details
The function performs several validation checks:
Format validation:
Must be exactly 8 digits (YYYYYYYY)
Must contain only numeric characters
Logical validation:
End year must be exactly one year after start year
Start year must not be before 1913 (earliest course data)
Special handling:
NULL input returns "" (representing current academic year)
The function provides detailed error messages when validation fails, indicating the specific validation rule that was violated.
Error Messages
The function may throw errors for:
Invalid format (not 8 digits)
Invalid year progression (end year != start year + 1)
Start year before 1913
Each error includes:
Description of the problem
Expected format/rules
Received invalid value
See also
generate_academic_year()
for creating valid academic year stringsfetch_department_courses()
for using validated years in queries
Examples
if (FALSE) { # \dontrun{
validate_academic_year("20232024") # Returns "20232024"
validate_academic_year(NULL) # Returns ""
validate_academic_year("2023") # Error: Invalid format
validate_academic_year("20232025") # Error: Invalid year progression
validate_academic_year("19121913") # Error: Start year too early
} # }