language: C# (mono-2.8)
date: 348 days 6 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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;
}
}