using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlTypes;
namespace dasBlog.Storage.SqlServer{
static class DateTimeTools
{
public static DateTime SqlMin = new DateTime(1900,1,1);
public static DateTime SqlMax = new DateTime(2500,1,1);
public static DateTime ToSqlRange(this DateTime dateTime)
{
if (dateTime < SqlMin)
return (DateTime)SqlMin;
if (dateTime > SqlMax)
return (DateTime)SqlMax;
return dateTime;
}
public static DateTime ToSqlRangeOrMax(this DateTime? dateTime)
{
if (!dateTime.HasValue)
return (DateTime)SqlMax;
if (dateTime.Value < SqlMin)
return (DateTime)SqlMin;
if (dateTime.Value > SqlMax)
return (DateTime)SqlMax;
return dateTime.Value;
}
public static DateTime ToSqlRangeOrMin(this DateTime? dateTime)
{
if (!dateTime.HasValue)
return (DateTime)SqlMin;
if (dateTime.Value < SqlMin)
return (DateTime)SqlMin;
if (dateTime.Value > SqlMax)
return (DateTime)SqlMax;
return dateTime.Value;
}
}
}
|