HumanReadableTimeSpanHelper.Parse(String) Method

Converts the specified string to a TimeSpan value.

Namespace: DevExpress.XtraScheduler.Native

Assembly: DevExpress.XtraScheduler.v20.1.Core.dll

Declaration

public static TimeSpan Parse(
    string str
)
Public Shared Function Parse(
    str As String
) As TimeSpan

Parameters

Name Type Description
str String

A String to convert.

Returns

Type Description
TimeSpan

A TimeSpan value. If the specified string cannot be converted to a TimeSpan, the MinValue is returned.

Remarks

Use the Parse method to convert a string to a TimeSpan value. To implement a custom conversion procedure, handle the HumanReadableTimeSpanHelper.ParseString event.

Examples

This example demonstrates how to use the HumanReadableTimeSpanHelper instance to implement the custom conversion of a TimeSpan value to a string and vice versa. To do this handle the HumanReadableTimeSpanHelper.ParseString and HumanReadableTimeSpanHelper.ConvertToString events and use the members of the corresponding TimeSpanStringConvertEventArgs object.

using DevExpress.XtraScheduler.Native;
// ...

// Handle the ParseString and ConvertToString events of the HumanReadableTimeSpanHelper.
HumanReadableTimeSpanHelper.ParseString += new TimeSpanStringConvertEventHandler(OnParse);
HumanReadableTimeSpanHelper.ConvertToString += new TimeSpanStringConvertEventHandler(OnToString);

// Custom parsing of a string to a TimeSpan value.
void OnParse(object sender, TimeSpanStringConvertEventArgs e) {
   double val;
   try {
         string number = e.StringValue.Substring(0, e.StringValue.IndexOf(" milliseconds"));
         val = Convert.ToDouble(number);
   }
   catch {
         val = 0;
   }

   e.TimeSpanValue = TimeSpan.FromMilliseconds(val);
   e.Handled = true;
}

// Custom conversion of a TimeSpan value to a string.
void OnToString(object sender, TimeSpanStringConvertEventArgs e) {
   e.StringValue = e.TimeSpanValue.TotalMilliseconds.ToString() + " milliseconds";
   e.Handled = true;
}
See Also