timespan

Vote:
 

How do you use the timespan as property on a block, for example showing a store openinghours?

 

E.g. this:

[ContentType(GUID = "714C5D3A-4AB2-43BE-A50C-28DD9C5E46AC", AvailableInEditMode = false)]
public class OpeningHour : BlockData
{
[Display(Name = "Opens")]
[BackingType(typeof(PropertyTimeSpan))]
public virtual TimeSpan Open { get; set; }

[Display(Name = "Closes")]
[BackingType(typeof(PropertyTimeSpan))]
public virtual TimeSpan Close { get; set; }
}

    

gives 

he property 'Open' on content type 'OpeningHour' is of type 'System.TimeSpan' that cannot be backed by PropertyTimeSpan, it only only supports types Int32, Enum.

 


And removing the backing type prop gives : 

The backing type 'EPiServer.SpecializedProperties.PropertyTimeSpan' is not a registered PropertyDefinitionType

 

What am i missing? 

#73963
Aug 15, 2013 15:35
Vote:
 

It's hard to say without seeing PropertyTimeSpan sorce code. Check that PropertyTimeSpan.PropertyValueType property is implemented and returns TimeSpan type.

#74034
Aug 19, 2013 11:31
Vote:
 

Hi, 

thanks for answering, but the PropertyTimeSpan code is from episerver.

 

#74214
Aug 22, 2013 14:09
Vote:
 

Ah, yes. Did you try without BackingType attribute for TimeSpan properties? I think it should be assigned automatically.

[Display(Name = "Closes")]
public virtual TimeSpan Close { get; set; }

    

#74278
Aug 23, 2013 9:57
Vote:
 

Hi Per!

Have you tried to register the EPiServer.SpecializedProperties.PropertyTimeSpan via the GUI in admin mode?

class name EPiServer.SpecializedProperties.PropertyTimeSpan, assembly name EPiServer, base type number.

 

-- 

Tarjei

 

 

#74307
Aug 23, 2013 13:54
Vote:
 

@Dmytro yes I tried without backingtype. 

@Tarjei, thanks. Registered it (don't know why it's not there already). I get a different edit mode dialog, a textbox and a dropdownlist with days, hours, minutes. Not quite what I expected and cannot save the value in edit mode even if I try different backing types (integer, floating point, string... )

 

#74450
Aug 28, 2013 9:30
Vote:
 

Ok, maybe thats the reason why the TimeSpan property is gone from the list of registered property types …

Perhaps it is better to simply use a string property and a validator to get the input parseable as a TimeSpan. That would be easy for editors, a bit more hassle for you when you have to pase the string data, but you can use a UIHint and a display template to get it right every time when rendering. Or you can go all the way and make a block type (AvailableInEditMode=false) with several inputs, drop down lists and what not and force e timespan out of it.

 

 

#74516
Aug 30, 2013 10:31
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.