Skip to content

Commit

Permalink
Merge pull request #711 from SSWConsulting/feat_add_a_decimal_point_f…
Browse files Browse the repository at this point in the history
…or_last_seen

XS⚠️ ◾ Add a decimal point for last seen
  • Loading branch information
AttackOnMorty authored Aug 11, 2024
2 parents dd7a47a + 06851da commit 909d52f
Showing 1 changed file with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmployeeBillableItemModel> GetBillableEmployees(
IEnumerable<GetEmployeeModel> employees,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -338,7 +340,7 @@ public static List<ClientsInfoModel> GetClientInfo(DateTime date, List<GetAppoin
var appointment = GetEnumerableAppointmentsByDate(appointments, date);

var clientsInfo = appointment
.Where(a => !_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())
{
Expand Down Expand Up @@ -373,7 +375,7 @@ public static List<ClientsInfoModel> GetClientInfo(DateTime date, List<GetAppoin
public static List<EmployeeProfileClient> GetClientsByDate(DateTime date, List<GetAppointmentModel> 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,
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 909d52f

Please sign in to comment.