Skip to contents

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.

Usage

validate_academic_year(year)

Arguments

year

Character string or NULL. Academic year to validate:

  • If character: Must be in format YYYYYYYY (e.g., "20232024")

  • If NULL: Represents current academic year

Value

Character string. Returns:

  • Empty string ("") if input is NULL

  • Original year string if validation passes

Details

The function performs several validation checks:

  1. Format validation:

    • Must be exactly 8 digits (YYYYYYYY)

    • Must contain only numeric characters

  2. Logical validation:

    • End year must be exactly one year after start year

    • Start year must not be before 1913 (earliest course data)

  3. 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

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
} # }