using System;
public class Test
{
public static void Main( )
{
//5:00 -> RoundDown() -> 5:00
//5:04 -> RoundDown() -> 5:00
//5:09 -> RoundDown() -> 5:00
//5:10 -> RoundDown() -> 5:10
//4:00 -> RoundUp() -> 4:00
//4:50 -> RoundUp() -> 4:50
//4:51 -> RoundUp() -> 5:00
//4:56 -> RoundUp() -> 5:00
Console.WriteLine ( Round( new DateTime( DateTime.Now .Year , DateTime.Now .Month , DateTime.Now .Day , 5 , 0 , 0 ) , 0 ) ) ;
Console.WriteLine ( Round( new DateTime( DateTime.Now .Year , DateTime.Now .Month , DateTime.Now .Day , 5 , 4 , 0 ) , 0 ) ) ;
Console.WriteLine ( Round( new DateTime( DateTime.Now .Year , DateTime.Now .Month , DateTime.Now .Day , 5 , 9 , 0 ) , 0 ) ) ;
Console.WriteLine ( Round( new DateTime( DateTime.Now .Year , DateTime.Now .Month , DateTime.Now .Day , 5 , 10 , 0 ) , 0 ) ) ;
Console.WriteLine ( Round( new DateTime( DateTime.Now .Year , DateTime.Now .Month , DateTime.Now .Day , 4 , 0 , 0 ) , 1 ) ) ;
Console.WriteLine ( Round( new DateTime( DateTime.Now .Year , DateTime.Now .Month , DateTime.Now .Day , 4 , 50 , 0 ) , 1 ) ) ;
Console.WriteLine ( Round( new DateTime( DateTime.Now .Year , DateTime.Now .Month , DateTime.Now .Day , 4 , 51 , 0 ) , 1 ) ) ;
Console.WriteLine ( Round( new DateTime( DateTime.Now .Year , DateTime.Now .Month , DateTime.Now .Day , 4 , 56 , 0 ) , 1 ) ) ;
}
// Define other methods and classes here
public static DateTime Round( DateTime dt, int dir)
{
// dir 1 = up, dir 0 = down
DateTime t;
if ( dir == 1 )
t = dt.AddMinutes ( ( 60 - dt.Minute ) % 10 ) ;
else
t = dt.AddMinutes ( - dt.Minute % 10 ) ;
return t;
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQp7CgkvLzU6MDA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