Class: Lutaml::Xsd::Validation::BaseTypes::TimeValidator
- Inherits:
-
BaseTypeValidator
- Object
- BaseTypeValidator
- Lutaml::Xsd::Validation::BaseTypes::TimeValidator
- Defined in:
- lib/lutaml/xsd/validation/base_types/time_validator.rb
Overview
Validates XSD time type
The time type represents a time of day in the format: HH:MM:SS with optional fractional seconds and timezone.
Constant Summary collapse
- TIME_PATTERN =
ISO 8601 time pattern
/^ \d{2}:\d{2}:\d{2} # Time part: HH:MM:SS (\.\d+)? # Optional fractional seconds (Z|[+-]\d{2}:\d{2})? # Optional timezone $/x
Instance Method Summary collapse
-
#error_message(value) ⇒ String
Generate error message for invalid time.
-
#valid?(value) ⇒ Boolean
Validate value is a valid time.
Methods inherited from BaseTypeValidator
Instance Method Details
#error_message(value) ⇒ String
Generate error message for invalid time
61 62 63 64 |
# File 'lib/lutaml/xsd/validation/base_types/time_validator.rb', line 61 def (value) "Value '#{value}' is not a valid time. " \ "Expected format: HH:MM:SS[.sss][Z|(+|-)HH:MM]" end |
#valid?(value) ⇒ Boolean
Validate value is a valid time
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/lutaml/xsd/validation/base_types/time_validator.rb', line 35 def valid?(value) return false if value.nil? str = to_string(value).strip return false unless str.match?(TIME_PATTERN) # Extract time part (before timezone and fractional seconds) time_part = str.split(/[Z+.-]/)[0] parts = time_part.split(":") # Validate ranges hour = parts[0].to_i minute = parts[1].to_i second = parts[2].to_i hour.between?(0, 23) && minute >= 0 && minute <= 59 && second >= 0 && second <= 59 rescue StandardError false end |