Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DateTimeToLastUpdated.cs
1
2using System.Globalization;
5
7{
8 public class DateTimeToLastUpdatedConverter : IValueConverter
9 {
10 public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
11 {
12 if (value is not DateTime DtNullable)
13 return ServiceRef.Localizer[nameof(AppResources.Never)].Value.ToLower(culture);
14
15 DateTime Dt = DtNullable.ToLocalTime(); // ensure local time
16 DateTime Now = DateTime.Now;
17 TimeSpan Span = Now - Dt;
18
19 string TimeString;
20
21 /*
22 if (Span.TotalMinutes < 1)
23 TimeString = ServiceRef.Localizer[nameof(AppResources.Now)].Value.ToLower(culture);
24 else if (Span.TotalHours < 1)
25 TimeString = ServiceRef.Localizer[nameof(AppResources.MinutesAgoFormat), false, (int)Span.TotalMinutes];
26 else if (Span.TotalDays < 1)
27 TimeString = ServiceRef.Localizer[nameof(AppResources.HoursAgoFormat), false, (int)Span.TotalHours];
28 */
29 if (Span.TotalDays < 1)
30 TimeString = Dt.ToString("t", culture); // "t" = short time, respects locale
31 else
32 TimeString = Dt.ToString("d", culture); // "d" = short date, respects locale
33 return ServiceRef.Localizer[nameof(AppResources.LastUpdatedFormat), false, TimeString];
34 }
35
36 public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
37 => throw new NotImplementedException();
38 }
39
40}
A strongly-typed resource class, for looking up localized strings, etc.
static string LastUpdatedFormat
Looks up a localized string similar to Last updated: {0}.
static string Never
Looks up a localized string similar to Never.
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IReportingStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:370