🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators strToTime
This page was created by Stephanie on 2025-01-09. Last edited by Wikiadmin on 2026-07-29.

You use strToTime in an OCL expression when you need to convert a String that represents a duration into a typed CLR TimeSpan value.

What strToTime does

strToTime converts a String to a TimeSpan by using the CLR (Common Language Runtime) TimeSpan.Parse() method.

Use the resulting TimeSpan where an expression needs a duration rather than text. Typical uses include:

  • Time arithmetic.
  • Comparing one duration with another.
  • Passing a typed duration to sumTime.

For example, if a model value stores a duration as text, convert it with strToTime before using that value in a duration calculation. Do not use the original String directly where a TimeSpan is required.

Input and result

Item Description
Input A String containing a value that the CLR TimeSpan.Parse() method can parse.
Result A CLR TimeSpan value representing the parsed duration.
Parsing rules The accepted text representation is determined by the CLR TimeSpan.Parse() method.

Syntax

The supplied operator documentation does not specify the exact OCL invocation syntax for strToTime. Use the operator in the form supported by your MDriven OCL editor, with the String value that contains the duration as its input.

Usage guidance

Convert durations, not dates

Use strToTime for elapsed time or a duration. If the String represents a calendar date or date and time, use strToDate or strToDateTime instead.

Keep the value typed after conversion

Convert the String at the point where you begin duration logic, then use the resulting TimeSpan for arithmetic and comparisons. This keeps duration operations type-correct and avoids treating a duration as text.

Validate source text

Because conversion uses CLR TimeSpan.Parse(), the source String must follow a representation that method accepts. A value that cannot be parsed cannot produce a valid TimeSpan; confirm how your expression context handles a parsing failure before relying on user-entered or external text.

Related conversion operators

Parse is documented separately. Use strToDateTime when the target value is a date and time, and strToDate when you need only the date portion.

See also