mirror of https://github.com/ogoun/Zero.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
576 B
18 lines
576 B
using System;
|
|
|
|
namespace ZeroLevel
|
|
{
|
|
public static class DateTimeExtensions
|
|
{
|
|
/// <summary>
|
|
/// Rounds the date to the specified scale.
|
|
/// Example: sqlserver - Datetime values are rounded to increments of .000, .003, or .007 seconds
|
|
/// </summary>
|
|
public static DateTime Truncate(this DateTime dateTime, TimeSpan timeSpan)
|
|
{
|
|
if (timeSpan == TimeSpan.Zero) return dateTime; // Or could throw an ArgumentException
|
|
return dateTime.AddTicks(-(dateTime.Ticks % timeSpan.Ticks));
|
|
}
|
|
}
|
|
}
|