Developer forum

Forum » Development » Template.SetTag(string Name, DateTime Value)

Template.SetTag(string Name, DateTime Value)

Kenneth Radoor
Reply
if the above SetTag method is passed a DateTime.MinValue it will throw an exception.
It would be great if you handle this edge case in the Template Class.

/Kenneth 

Replies

 
Morten Snedker
Reply
 Hi Kenneth,

Any reason for not just casting your DateTime value to at string?

/Snedker
 
Nicolai Høeg Pedersen
Reply
1000 reasons Morten.

Then dates will not be rendered using the regional settings of the website, you would not have all the date extensions and a lot of other stuff!

 
Nicolai Høeg Pedersen
Reply
Thats just 2 reasons -  I know :-)
 
Kenneth Radoor
Reply
Yes, because then its not a date anymore, and i don´t get all the nice date-tags :)

The exeption is thrown in a relative new extention you have made in the SetTag(datetime), .SortableOffset.

If i give that method an input of DateTime.MinValue, then the offset will be an hour before the beginning of time :)

So as I see it there is 2 options.
Either we as developers have to go through all of our code and in every place where there is a possibility that the date will be minvalue, tests for it and then either cast the date to a string or take the DateTimeOffset into account.
or you could in the API test for it with a simple if statement, and just return the MinValue in that case.
 
In my humble opinion stuff like this has to be handled ind the API.

/Kenneth
 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer
I've made a fix in the API.
Votes for this answer: 0
 
Kenneth Radoor
Reply
 Great 

Thanks

/Kenneth

 

You must be logged in to post in the forum