Skip to content

Commit

Permalink
feat: add a decimal point for hour (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
AttackOnMorty authored Aug 12, 2024
1 parent b4941e1 commit 0a5a63c
Showing 1 changed file with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,39 +229,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";
return $"{seconds}{("s")} ago";
}
else if (timeOffset.TotalHours < 1)

if (timeOffset.TotalHours < 1)
{
var minutes = GetInteger(timeOffset.TotalMinutes);
return $"{minutes}{(minutes == 1 ? "m" : "m")} ago";
return $"{minutes}{("m")} ago";
}
else if (timeOffset.TotalDays < 1)

if (timeOffset.TotalDays < 1)
{
var hours = GetInteger(timeOffset.TotalHours);
return $"{hours}{(hours == 1 ? "h" : "h")} ago";
var hours = Math.Round(timeOffset.TotalHours, 1);
return $"{hours}{("h")} ago";
}
else if (timeOffset.TotalDays < 30)

if (timeOffset.TotalDays < 30)
{
var days = GetInteger(timeOffset.TotalDays);
return $"{days}{(days == 1 ? "d" : "d")} ago";
}
else
{
var months = GetInteger(timeOffset.TotalDays / 30);
return $"{months} {(months == 1 ? "month" : "months")} ago";
return $"{days}{("d")} ago";
}

var months = GetInteger(timeOffset.TotalDays / 30);
return $"{months} {(months == 1 ? "month" : "months")} ago";
}

private static int GetInteger(double value)
{
return Math.Max(1, (int)Math.Floor(value));
}

public static string GetLastSeenPhoneDevice(GetEmployeeModel employee)
Expand Down

0 comments on commit 0a5a63c

Please sign in to comment.