diff --git a/bots/employee-finder/src/SSW.SophieBot.HttpClientComponents.PersonQuery/EmployeesHelper.cs b/bots/employee-finder/src/SSW.SophieBot.HttpClientComponents.PersonQuery/EmployeesHelper.cs index 3361d9d4..c71212d3 100644 --- a/bots/employee-finder/src/SSW.SophieBot.HttpClientComponents.PersonQuery/EmployeesHelper.cs +++ b/bots/employee-finder/src/SSW.SophieBot.HttpClientComponents.PersonQuery/EmployeesHelper.cs @@ -10,11 +10,12 @@ namespace SSW.SophieBot.HttpClientComponents.PersonQuery { public static class EmployeesHelper { - private static readonly string[] _internalCompanyNames = new[] + private static readonly string[] InternalCompanyNames = new[] { "ssw", "ssw test" }; + private const double Tolerance = 0.0001; public static List GetBillableEmployees( IEnumerable employees, @@ -229,39 +230,40 @@ public static string GetLastSeen(GetEmployeeModel model) return string.Empty; } - static int GetInteger(double value) - { - return Math.Max(1, (int)Math.Floor(value)); - } - var now = DateTimeOffset.UtcNow; var timeOffset = now - lastSeenDateTime.Value; if (timeOffset.TotalMinutes < 1) { - var seconds = GetInteger(timeOffset.TotalSeconds); - return $"{seconds}{(seconds == 1 ? "s" : "s")} ago"; + var seconds = GetTime(timeOffset.TotalSeconds); + return $"{seconds}{("s")} ago"; } - else if (timeOffset.TotalHours < 1) - { - var minutes = GetInteger(timeOffset.TotalMinutes); - return $"{minutes}{(minutes == 1 ? "m" : "m")} ago"; - } - else if (timeOffset.TotalDays < 1) + + if (timeOffset.TotalHours < 1) { - var hours = GetInteger(timeOffset.TotalHours); - return $"{hours}{(hours == 1 ? "h" : "h")} ago"; + var minutes = GetTime(timeOffset.TotalMinutes); + return $"{minutes}{("m")} ago"; } - else if (timeOffset.TotalDays < 30) + + if (timeOffset.TotalDays < 1) { - var days = GetInteger(timeOffset.TotalDays); - return $"{days}{(days == 1 ? "d" : "d")} ago"; + var hours = GetTime(timeOffset.TotalHours); + return $"{hours}{("h")} ago"; } - else + + if (timeOffset.TotalDays < 30) { - var months = GetInteger(timeOffset.TotalDays / 30); - return $"{months} {(months == 1 ? "month" : "months")} ago"; + var days = GetTime(timeOffset.TotalDays); + return $"{days}{("d")} ago"; } + + var months = GetTime(timeOffset.TotalDays / 30); + return $"{months} {(Math.Abs(months - 1) < Tolerance ? "month" : "months")} ago"; + } + + private static double GetTime(double value) + { + return Math.Round(value, 1); } public static string GetLastSeenPhoneDevice(GetEmployeeModel employee) @@ -338,7 +340,7 @@ public static List GetClientInfo(DateTime date, List !_internalCompanyNames.Contains(a.Regarding?.ToLower()) && !string.IsNullOrWhiteSpace(a.Regarding) && a.End.UtcTicks >= date.Ticks) + .Where(a => !InternalCompanyNames.Contains(a.Regarding?.ToLower()) && !string.IsNullOrWhiteSpace(a.Regarding) && a.End.UtcTicks >= date.Ticks) .Select(a => { if(a.Client != null && a.Client.Any()) { @@ -373,7 +375,7 @@ public static List GetClientInfo(DateTime date, List GetClientsByDate(DateTime date, List appointments) { return GetEnumerableAppointmentsByDate(appointments, date) - .Where(appointment => !_internalCompanyNames.Contains(appointment.Regarding?.ToLower())) + .Where(appointment => !InternalCompanyNames.Contains(appointment.Regarding?.ToLower())) .Select(appointment => new EmployeeProfileClient { Name = appointment.Regarding, @@ -589,12 +591,12 @@ static string GetDayString(int days) private static bool IsOnClientWorkFunc(GetAppointmentModel appointment) { - return !_internalCompanyNames.Contains(appointment.Regarding?.ToLower()); + return !InternalCompanyNames.Contains(appointment.Regarding?.ToLower()); } private static bool IsOnInternalWorkFunc(GetAppointmentModel appointment) { - return _internalCompanyNames.Contains(appointment.Regarding?.ToLower()) + return InternalCompanyNames.Contains(appointment.Regarding?.ToLower()) && !IsOnLeaveFunc(appointment); }