Date & Time Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Date and Time Calculation > DTO. - Date Time Operations >

Date & Time Operations

DTO.Reformat Time (reft)

Previous Top Next


MiniRobotLanguage (MRL)

 

DTO.ReformatTime Command

Reformat a time string using masks

 

Intention

 

This command converts a given time string from a specified source format into a new destination format. This is useful for normalizing time data or changing separators.

 

The command uses format "masks" to understand the structure of the input and output strings. The masks define the components of the time:

  HH: 2-digit hour (00-23)

  H: 1 or 2-digit hour (0-23)

  MM: 2-digit minute (00-59)

  M: 1 or 2-digit minute (0-59)

  SS: 2-digit second (00-59)

  S: 1 or 2-digit second (0-59)

  .XXXX: 4-digit fractional part (1/10000th of a second). The separator can be . or ,.

 

The main separator character (e.g., :, .) is detected automatically from the format string.

 

Syntax

 

DTO.reft|SourceFmt|DestinationFmt|TimeString[|$$ResultVar]

DTO.reformattime|SourceFmt|DestFmt|TimeString[|$$ResultVar]

 

Parameter Explanation

 

P1 - SourceFormat

A string mask describing the format of P3 (TimeString).

Example: "HH:MM:SS.XXXX"

 

P2 - DestinationFormat

A string mask describing the desired output format.

Example: "HH.MM.SS"

 

P3 - TimeString

The actual time string (or a variable) that you want to convert.

Example: "14:30:15.5000"

 

P4 - $$ResultVar (Optional)

The variable where the reformatted time string will be stored. If this parameter is omitted, the result is placed on TOS (Top of Stack).

 

 

Example

 

'**********************************************

' DTO.reft - Sample

'**********************************************

'

' --- Example 1: Change separator and remove seconds ---

$$Time1 = "14:30:15"

DTO.reft|"HH:MM:SS"|"HH.MM"|$$Time1|$$Result1

DBV.Result 1: $$Result1 ' Result: "14.30"

'

' --- Example 2: Reorder components and handle fractional ---

$$Time2 = "10:20:30.1234"

DTO.reft|"HH:MM:SS.XXXX"|"SS,MM,HH"|$$Time2|$$Result2

DBV.Result 2: $$Result2 ' Result: "30,20,10"

'

' --- Example 3: Handle partial fractional input ---

$$Time3 = "09:05:01.5"

' .5 is parsed as .5000 (1/10000ths)

DTO.reft|"HH:MM:SS.XXXX"|"HH:MM:SS.XXXX"|$$Time3|$$Result3

DBV.Result 3: $$Result3 ' Result: "09:05:01.5000"

'

' --- Example 4: Add missing components (e.g., seconds) ---

$$Time4 = "22:15"

DTO.reft|"HH:MM"|"HH:MM:SS"|$$Time4|$$Result4

DBV.Result 4: $$Result4 ' Result: "22:15:00"

'

ENR.

 

Remarks

 

This command is effectively a combination of DTO.ParseTime and DTO.FormatTime.

If the TimeString cannot be parsed using the SourceFormat (e.g., "25:70:99"), the command will return an empty string.

The fractional component is parsed as 4 digits (0-9999). If an input string provides fewer digits (e.g., ".5"), it is padded with zeros to the right (e.g., "5000").

 

Limitations

 

The command only reformats the string; it does not perform time calculations.

 

See also

 

    DTO. - Date Time Operations

    DTO.Reformat Date - reformat date using mask

    DTO.Parse Time - parse time into components

    DTO.Format Time - format time components to string

    DTO.Make Time Mask - create time format mask

    DTO.Standard Time Format - convert time to HH:MM:SS

    DTO.Get Time Separator - detect time separator char