29 lines
1.0 KiB
C#
29 lines
1.0 KiB
C#
namespace MP.MONO.UI.Data
|
|
{
|
|
public class Utils
|
|
{
|
|
#region Public Methods
|
|
|
|
/// <summary> Inizializzazione con periodo e arrotondamento </summary> <param
|
|
/// name="dtRef">DataORa di riferimento</param> <param name="minRound">Arrotondamento
|
|
/// desiderato</param> <param name="roundMode">Parametro arrotondamento: se > 0 per eccesso,
|
|
/// se <= 0 per difetto</param> <returns></returns>
|
|
public static DateTime RoundDatetime(DateTime dtRef, int minRound, int roundMode)
|
|
{
|
|
TimeSpan DayElapsed = dtRef.Subtract(dtRef.Date);
|
|
int minDay = 0;
|
|
if (roundMode > 0)
|
|
{
|
|
minDay = (int)Math.Ceiling((double)(DayElapsed.TotalMinutes / minRound)) * minRound;
|
|
}
|
|
else
|
|
{
|
|
minDay = (int)Math.Floor((double)(DayElapsed.TotalMinutes / minRound)) * minRound;
|
|
}
|
|
DateTime endRounded = dtRef.Date.AddMinutes(minDay);
|
|
return endRounded;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |