-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Data Dictionary list readability at Last Modified Date
- Loading branch information
Showing
5 changed files
with
119 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using JJMasterData.Commons.Localization; | ||
using Microsoft.Extensions.Localization; | ||
|
||
namespace JJMasterData.Commons.Util; | ||
|
||
public class DateService(IStringLocalizer<MasterDataResources> localizer) | ||
{ | ||
public string GetPhrase(DateTime date) | ||
{ | ||
var timeDifference = DateTime.Now - date; | ||
|
||
if (date == DateTime.MinValue) | ||
{ | ||
return localizer["Never"]; | ||
} | ||
|
||
if (timeDifference.TotalSeconds < 60) | ||
{ | ||
return localizer["Just now"]; | ||
} | ||
|
||
if (timeDifference.TotalMinutes < 60) | ||
{ | ||
int minutes = (int)timeDifference.TotalMinutes; | ||
return minutes == 1 | ||
? localizer["1 minute ago"] | ||
: localizer["{0} minutes ago", minutes]; | ||
} | ||
if (timeDifference.TotalHours < 24) | ||
{ | ||
int hours = (int)timeDifference.TotalHours; | ||
return hours == 1 | ||
? localizer["1 hour ago"] | ||
: localizer["{0} hours ago", hours]; | ||
} | ||
if (timeDifference.TotalDays < 30) | ||
{ | ||
int days = (int)timeDifference.TotalDays; | ||
return days == 1 | ||
? localizer["1 day ago"] | ||
: localizer["{0} days ago", days]; | ||
} | ||
if (timeDifference.TotalDays < 365) | ||
{ | ||
int months = (int)(timeDifference.TotalDays / 30); | ||
int remainingDays = (int)(timeDifference.TotalDays % 30); | ||
if (remainingDays == 1) | ||
{ | ||
return months == 0 | ||
? localizer["1 day ago"] | ||
: localizer["{0} months and 1 day ago", months]; | ||
} | ||
|
||
return months == 0 | ||
? localizer["{0} days ago", remainingDays] | ||
: localizer["{0} months and {1} days ago", months, remainingDays]; | ||
} | ||
int years = (int)(timeDifference.TotalDays / 365); | ||
return years == 1 | ||
? localizer["1 year ago"] | ||
: localizer["{0} years ago", years]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters