Durations and TimeSpans - WilStead/VueCoreFramework GitHub Wiki

TimeSpans

Although VueCoreFramework recognizes and can handle TimeSpan properties, Entity Framework maps these to the T-SQL time type, which cannot store values >= 24 hours. Unless you intend for your property to only store values smaller than this, and you set an appropriate Range to ensure this, the TimeSpan type is probably not right for what you're trying to accomplish.

VueCoreFramework has implemented a better solution. Any long property decorated with the DataTypeAttribute with its DataType set to DataType.Duration will be interpreted as a number of Ticks. Entity Framework will map the long with no trouble, and VueCoreFramework will automatically translate the Ticks amount into a duration similar to a TimeSpan when viewing and editing the value.

Note that if you do use a long property marked as a Duration, you should specify its range (using the RangeAttribute) with TimeSpan units (using the version of the Attribute's constructor which allows you to specify the data type, and using string representations of the minimum and maximum), not with long values in the form of a minimum and maximum Ticks.

Controlling Displayed Units

In order to display a duration (or a TimeSpan) in a useful and intuitive manner on data forms, VueCoreFramework utilizes a set of numeric text fields for each component of the duration (day, hour, etc). It would be unwieldy and non-user-friendly, however, to display the whole possible set of such fields if you only need some of them.

Imagine, for instance, a case when you want your users to be able to specify a duration in hours and minutes. You wouldn't want to show them an input with year, month, and day fields as well.

To solve this you may apply the DisplayFormatAttribute to a duration-type property and set the DataFormatString to a string in the format "y:M:d:h:m:s" representing years, months, days, hours, minutes, seconds (the seconds field respects your specified Step, with a default of 0.001 for milliseconds). You can omit any number of the indicators from the beginning or end of this string in order to specify which fields should be displayed. For example, "d:h:m" indicates that days, hours, and minutes will be shown, but not years, months, or seconds. However if you omit any values in the middle (e.g. "y:d:h", which omits months from between years and days), VueCoreFramework will ignore you, since overflow from lower units must be shown and editable with the in-between units in order to avoid loss of data.