Is the following code correct?
[WebMethod]
[ScriptMethod]
public bool DoPost(CommunityNewsPost post)
{
MembershipHelper.ThrowUnlessAtLeast(RoleName.Administrator);
DateTime? start;
DateTime? end;
Utility.TryParse(post.PublishStart, out start);
Utility.TryParse(post.PublishEnd, out end);
if (start != null)
start -= start.Value.TimeOfDay - TimeSpan.MinValue;
if(end!=null)
end += TimeSpan.MaxValue - end.Value.TimeOfDay;
return CommunityNews.Post(post.Title, post.Markdown, post.CategoryId, start, end);
}
And Utility.TryParse:
public static bool TryParse(string s, out DateTime? result)
{
DateTime d;
var success = DateTime.TryParse(s, out d);
if (success)
result = d;
else
result = default(DateTime?);
return success;
}
I want start to be something like 09/11/2011 00:00 and end to be something like 09/11/2011 23:59
No, TimeSpan.Min/MaxValue are very large values. Not that sure what you really want to do but the example you gave is generated by: