forked from mazhewitt/DotNetBerlinClock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeConverter.cs
60 lines (50 loc) · 1.65 KB
/
TimeConverter.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BerlinClock
{
public class TimeConverter : ITimeConverter
{
public string convertTime(string aTime)
{
StringBuilder str = new StringBuilder();
string[] clocktime = aTime.Split(':');
var val = Convert.ToInt32(aTime);
int hrstime = Convert.ToInt32(clocktime[0]) / 5; /// No of Red lamps
for (int i = 1; i <= hrstime; i++)
{
str.Append("R");
}
// Console.WriteLine(str);
int RmtoprowHrsRed = Convert.ToInt32(clocktime[0]) % 1;
for (int i = 0; i <= RmtoprowHrsRed; i++)
{
str.Append("R");
}
// Console.WriteLine(str);
int Mintime = Convert.ToInt32(clocktime[1]) / 5; /// No of Yellow and Red(3,6,9) lamps
int RemTime = Convert.ToInt32(clocktime[1]) % 5;
for (int i = 1; i <= RemTime; i++)
{
str.Append("R");
}
for (int i = 1; i <= Mintime; i++)
{
if (i % 3 == 0)
{
str.Append("R");
}
else
{
str.Append("Y");
}
}
// Console.WriteLine(str);
int Sectime = Convert.ToInt32(clocktime[2]); /// No of Yellow and Red(3,6,9) lamps
str.Append("R");
Console.WriteLine(str);
return str.ToString();
}
}
}