OpenTAP 9.25
API Reference
Static Public Member Functions | List of all members
OpenTap.TimeSpanParser Class Reference

A time span parser can parse a text input (which would typically be a user input) for timespan information like "1 hour 2 minutes" or "1 week 250ms" and sum them all up into a TimeSpan. Currently only English units are supported. More...

Static Public Member Functions

static TimeSpan Parse (string input, NumberStyles numberParseStyles=NumberStyles.Any, CultureInfo numberParseCulture=null, bool acceptIndeterminate=false)
 Parses a string for TimeSpan Information like "1 week 2 days" or "2h12m3s". Currently only English units are accepted. Note that "month" is not a valid unit, since it does not correspond to a determined number of days and so is "year" because of leap years. However you can have both units parsed to hardwired values using the <cref name="acceptIndeterminate"> parameter. Note that Microseconds are accepted, but the .NET TimeSpan only resolves milliseconds. Thus only multiples of thousands of Microseconds will affect the result, e.g. "2000µs", when reformatted, will evaluate to "2ms" whereas "200µs" will simply return TimeSpan.Zero. More...
 

Detailed Description

A time span parser can parse a text input (which would typically be a user input) for timespan information like "1 hour 2 minutes" or "1 week 250ms" and sum them all up into a TimeSpan. Currently only English units are supported.

Member Function Documentation

◆ Parse()

static TimeSpan OpenTap.TimeSpanParser.Parse ( string  input,
NumberStyles  numberParseStyles = NumberStyles.Any,
CultureInfo  numberParseCulture = null,
bool  acceptIndeterminate = false 
)
inlinestatic

Parses a string for TimeSpan Information like "1 week 2 days" or "2h12m3s". Currently only English units are accepted. Note that "month" is not a valid unit, since it does not correspond to a determined number of days and so is "year" because of leap years. However you can have both units parsed to hardwired values using the <cref name="acceptIndeterminate"> parameter. Note that Microseconds are accepted, but the .NET TimeSpan only resolves milliseconds. Thus only multiples of thousands of Microseconds will affect the result, e.g. "2000µs", when reformatted, will evaluate to "2ms" whereas "200µs" will simply return TimeSpan.Zero.

Exceptions
ArgumentExceptionThrown when one or more arguments have unsupported or illegal values.
FormatExceptionThrown when a unit is unknown.
Parameters
inputThe input string.
numberParseStylesThe acceptable number styles.
numberParseCultureThe culture for number parsing. If omitted, DefaultThreadCurrentCulture is chosen.
acceptIndeterminatetrue to accept months (as 30 days) and years (as 356 days).
Returns
A TimeSpan.

OpenTAP 9.25 API built Tue Aug 6 2024 07:49:25