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

Update Program.cs #108

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
58 changes: 48 additions & 10 deletions Tavisca.Bootcamp.LanguageBasics.Exercise2/Program.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,68 @@
using System;
using System;

namespace Tavisca.Bootcamp.LanguageBasics.Exercise1
{
public static class Program
public static class ForumPostEasy
{
static void Main(string[] args)
{
Test(new[] {"12:12:12"}, new [] { "few seconds ago" }, "12:12:12");
Test(new[] { "12:12:12" }, new[] { "few seconds ago" }, "12:12:12");
Test(new[] { "23:23:23", "23:23:23" }, new[] { "59 minutes ago", "59 minutes ago" }, "00:22:23");
Test(new[] { "00:10:10", "00:10:10" }, new[] { "59 minutes ago", "1 hours ago" }, "impossible");
Test(new[] { "11:59:13", "11:13:23", "12:25:15" }, new[] { "few seconds ago", "46 minutes ago", "23 hours ago" }, "11:59:23");
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)
{
return Method(exactPostTime, showPostTime);
}

public static string Method(string[] exactPostTime, string[] showPostTime)
{

int Temp = exactPostTime.Length;

for (int i = 0; i < exactPostTime.Length - 1; i++)
if (exactPostTime[i] == exactPostTime[i + 1] && showPostTime[i] != showPostTime[i + 1]) return "impossible";

string[] ReadingTime = new string[Temp];

for (int i = 0; i < Temp; i++)
{
DateTime TimeConverted = Convert.ToDateTime(exactPostTime[i]);
if (showPostTime[i].Contains("seconds")) ReadingTime[i] = exactPostTime[i];

else if (showPostTime[i].Contains("minutes"))
{
string minutes = showPostTime[i].Split(' ')[0];
DateTime current = TimeConverted.AddMinutes(Int32.Parse(minutes));
string result = current.ToString().Split(' ')[1];
ReadingTime[i] = result;
}

else if (showPostTime[i].Contains("hours"))
{
string hours = showPostTime[i].Split(' ')[0];
DateTime current = TimeConverted.AddHours(Int32.Parse(hours));
string result = current.ToString().Split(' ')[1];
ReadingTime[i] = result;
}
else return "impossible";
}
Array.Sort(ReadingTime);
return ReadingTime[Temp - 1];
}


}

}