Skip to main content

Text.parse_time_of_day

parse_time_of_dayformat

Group: Conversions
Aliases: time_of_day from text, to_time_of_day

Documentation

Obtains an instance of Time_Of_Day from a text such as "10:15". This method will return a Time_Error if the provided time cannot be parsed.

Arguments

  • format: The format to use for parsing the input text.

Examples

Get the time 15:05:30.

      import Standard.Base.Data.Text.Extensions

example_parse = "15:05:30".parse_time_of_day

Recover from the parse error.

      import Standard.Base.Data.Text.Extensions
from Standard.Base.Errors.Common import Time_Error

example_parse = "half twelve".parse_time_of_day . catch Time_Error _->
Time_Of_Day.new

Parse "04:30:20" as Time_Of_Day.

      import Standard.Base.Data.Text.Extensions

example_parse = "04:30:20".parse_time_of_day "HH:mm:ss"

Parse "4:30AM" as Time_Of_Day

      import Standard.Base.Data.Text.Extensions

example_parse = "4:30AM".parse_time_of_day "h:mma"

Remarks

Default Time Format

Unless you provide a custom format, the text must represent a valid time and is parsed using the ISO-8601 extended local time format. The format consists of:

  • Two digits for the hour-of-day. This is pre-padded by zero to ensure two digits.
  • A colon
  • Two digits for the minute-of-hour. This is pre-padded by zero to ensure two digits.
  • If the second-of-minute is not available then the format is complete.
  • A colon
  • Two digits for the second-of-minute. This is pre-padded by zero to ensure two digits.
  • If the nano-of-second is zero or not available then the format is complete.
  • A float point
  • One to nine digits for the nano-of-second. As many digits will be output as required.

Pattern Syntax

If the pattern is provided as Text, it is parsed using the format described below. See Date_Time_Formatter for more options.

  • H: 24h hour of day (0-23).
  • h: 12h hour of day (0-12). The a pattern is needed to disambiguate between AM and PM.
  • m: Minute of hour.
  • s: Second of minute.
  • f: Fractional part of the second. The number of pattern letters determines the number of digits. If one letter is used, any number of digits will be accepted.
  • a: AM/PM marker.