|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Operations |
MiniRobotLanguage (MRL)
DTO.ParseTime Command
Parse time string into components
Intention
This command extracts the individual numeric components (Hour, Minute, Second, Fractional Seconds) from a given time string, based on an optional format mask. It's the inverse operation of DTO.FormatTime.
The format mask uses these components:
• HH (2-digit hour), H (1-2 digit hour)
• MM (2-digit minute), M (1-2 digit minute)
• SS (2-digit second), S (1-2 digit second)
• .XXXX (Optional fractional part, up to 4 digits representing 1/10000ths of a second. Separator can be . or ,)
Syntax
DTO.parsetime|TimeString|[FormatMask]|$$HOU|$$MIN|$$SEC|$$MSC
DTO.ptime|...
Parameter Explanation
P1 - TimeString (Required)
The time string (or a variable, e.g., $$TIM) to be parsed.
Example: "14:30:45.123"
P2 - FormatMask (Optional)
The string mask describing the format of P1. Example: "HH:MM:SS.XXXX"
If omitted, the standard mask "HH:MM:SS" (using ":" as separator) is assumed.
P3 - $$HOU (Optional)
A variable (e.g., $$HOU) to store the extracted Hour component (0-23).
P4 - $$MIN (Optional)
A variable (e.g., $$MIN) to store the extracted Minute component (0-59).
P5 - $$SEC (Optional)
A variable (e.g., $$SEC) to store the extracted Second component (0-59).
P6 - $$MSC (Optional)
A variable (e.g., $$MSC) to store the extracted Fractional Second component (0-9999, representing 1/10000ths of a second).
Example
'**********************************************
' DTO.ptime - Sample
'**********************************************
'
' --- Example 1: Parse standard time with milliseconds ---
$$TIM = "14:30:45.123" ' Input time string
$$MSK = "HH:MM:SS.XXXX" ' Format mask including fractional part
DTO.ptime|$$TIM|$$MSK|$$HOU|$$MIN|$$SEC|$$MSC
DBV.Hour: $$HOU ' Result: 14
DBV.Minute: $$MIN ' Result: 30
DBV.Second: $$SEC ' Result: 45
DBV.Fraction: $$MSC ' Result: 1230 ('.123' padded to 4 digits)
'
' --- Example 2: Parse time without mask (default HH:MM:SS) ---
$$TIM = "08:05:10"
DTO.ptime|$$TIM||$$H|$$M|$$S
DBV.Hour: $$H ' Result: 8
DBV.Minute: $$M ' Result: 5
DBV.Second: $$S ' Result: 10
'
' --- Example 3: Parse with different separator ---
$$TIM = "21.15.00"
$$MSK = "HH.MM.SS"
DTO.ptime|$$TIM|$$MSK|$$H|$$M|$$S
DBV.Hour: $$H ' Result: 21
DBV.Minute: $$M ' Result: 15
DBV.Second: $$S ' Result: 0
'
ENR.
Remarks
If the FormatMask is omitted, the command defaults to using ":" as the separator and assumes the order HH:MM:SS.
The fractional second component (`$$MSC`) receives a value between 0 and 9999, representing 1/10000ths of a second. If the input string has fewer than 4 fractional digits, it is padded with zeros on the right (e.g., "12:00:00.1" results in `$$MSC` = 1000).
This command is more robust than the older DTO.splittime as it handles the optional mask correctly and supports fractional seconds.
Limitations
- If the TimeString is invalid or does not match the FormatMask, the output variables will contain 0.
See also
• DTO.Format Time - format time components to string
• DTO.Split Time Mask - (Old parsing command)
• DTO.Reformat Time - reformat time using mask
• DTO.Make Time Mask - create time format mask
• DTO.Get Time Separator - detect time separator char