Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimeSpan of days in configuration?

Tags:

It appears that ConfigurationElement of TimeSpan can't handle values larger than 23:59:59. Are there any workarounds? Is subclassing TimeSpan, and making a new TimeSpanValidatorAttribute even going to work? I need to handle timespans from a few minutes to a few days.

I'm using the following configuration section

[ConfigurationProperty("SequenceRolloverDOSCompare", IsRequired = true)] [TimeSpanValidator(MinValueString = "0:0:00", MaxValueString = 10675199.02:48:05.4775807", ExcludeRange = false)] public TimeSpan SequenceRolloverDOSCompare {     get     {         return (TimeSpan)base["SequenceRolloverDOSCompare"];     } } 

with config looking like this:

<SequenceRolloverPolling SequenceRolloverDOSCompare="2:00:00:00"  /> 

gives ConfigurationErrorsException : The value of the property 'SequenceRolloverDOSCompare' cannot be parsed. The error is: 2:00:00:00 is not a valid value for TimeSpan.

or this:

<SequenceRolloverPolling SequenceRolloverDOSCompare="48:00:00"  /> 

gives OverflowException : The TimeSpan could not be parsed because at least one of the hours, minutes, or seconds components is outside its valid range

like image 355
BozoJoe Avatar asked Jun 30 '10 00:06

BozoJoe


People also ask

What is TimeSpan time?

A TimeSpan object represents a time interval (duration of time or elapsed time) that is measured as a positive or negative number of days, hours, minutes, seconds, and fractions of a second. The TimeSpan structure can also be used to represent the time of day, but only if the time is unrelated to a particular date.

What is TimeSpan type in C#?

C# TimeSpan struct represents a time interval that is difference between two times measured in number of days, hours, minutes, and seconds. C# TimeSpan is used to compare two C# DateTime objects to find the difference between two dates.

Is TimeSpan a data type?

TimeSpan (amount of time) is a new data type that can be used to store information about an elapsed time period or a time span. For example, the value in the picture (148:05:36.254) consists of 148 hours, 5 minutes, 36 seconds, and 254 milliseconds.


1 Answers

Use the . separator between days and hours:

<SequenceRolloverPolling     SequenceRolloverDOSCompare="2.00:00:00" /> 

The TimeSpan format is defined as:

... [-]d.hh:mm:ss.ff, where the optional minus sign indicates a negative time interval, the d component is days, hh is hours as measured on a 24-hour clock, mm is minutes, ss is seconds, and ff is fractions of a second.

like image 65
Rex M Avatar answered Sep 24 '22 01:09

Rex M