Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added implementation of GetCurrentTime #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 57 additions & 7 deletions Tavisca.Bootcamp.LanguageBasics.Exercise2/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;

namespace Tavisca.Bootcamp.LanguageBasics.Exercise1
{
Expand All @@ -13,18 +14,67 @@ static void Main(string[] args)
Console.ReadKey(true);
}

private static void Test(string[] postTimes, string[] showTimes, string expected)
{
private static void Test(string[] postTimes, string[] showTimes, string expected)
{
var result = GetCurrentTime(postTimes, showTimes).Equals(expected) ? "PASS" : "FAIL";
var postTimesCsv = string.Join(", ", postTimes);
var showTimesCsv = string.Join(", ", showTimes);
Console.WriteLine($"[{postTimesCsv}], [{showTimesCsv}] => {result}");
Console.WriteLine($"[{postTimesCsv}], [{showTimesCsv}] => {result}");
}

public static string GetCurrentTime(string[] exactPostTime, string[] showPostTime)
{
// Add your code here.
throw new NotImplementedException();
public static string GetCurrentTime(string[] exactPostTime, string[] showPostTime)
{

var currentTime = new List<TimeSpan>();

for(int i=0; i< exactPostTime.Length; i++){

for (int j = 0; j < exactPostTime.Length; j++)
{
if(exactPostTime[i] == exactPostTime[j]){
if(showPostTime[i] != showPostTime[j]) return "impossible";
}
}

TimeSpan timeSpan = TimeSpan.Parse(exactPostTime[i]);
/* Console.WriteLine(timeSpan);

TimeSpan time = new TimeSpan(timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
Console.WriteLine(timeSpan.Hours);
Console.WriteLine(TimeSpan.FromHours(timeSpan.Hours));
Console.WriteLine(timeSpan.Minutes);
Console.WriteLine(TimeSpan.FromMinutes(timeSpan.Minutes));
Console.WriteLine(timeSpan.Seconds);
Console.WriteLine(TimeSpan.FromSeconds(timeSpan.Seconds)); */

if(showPostTime[i].Contains("seconds")){
TimeSpan time = new TimeSpan(timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
currentTime.Add(time);
}
else if(showPostTime[i].Contains("minutes")){

string minute = showPostTime[i].Split(' ')[0];
timeSpan = timeSpan.Add(TimeSpan.FromMinutes(double.Parse(minute)));
System.Console.WriteLine(timeSpan);
TimeSpan time = new TimeSpan(timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);

System.Console.WriteLine(time);

currentTime.Add(time);
}
else if(showPostTime[i].Contains("hours")){
string hours = showPostTime[i].Split(' ')[0];
timeSpan = timeSpan.Add(TimeSpan.FromHours(double.Parse(hours)));
System.Console.WriteLine(timeSpan);
TimeSpan time = new TimeSpan(timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);

System.Console.WriteLine(time);

currentTime.Add(time);
}
}
currentTime.Sort();
return currentTime[currentTime.Count-1].ToString();
}
}
}