Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ContextualDateConverter.cs
1using System;
3using System.Globalization;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
9using static System.Runtime.InteropServices.JavaScript.JSType;
10
12{
22 public class ContextualDateConverter : IValueConverter
23 {
24 public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
25 {
26 if (value is DateTime Date)
27 {
28 DateTime Now = DateTime.Now;
29
30 // Check if the date is today.
31 if (Date.Date == Now.Date)
32 {
33 return ServiceRef.Localizer[nameof(AppResources.Today)];
34 }
35 // Check if the date is yesterday.
36 else if (Date.Date == Now.Date.AddDays(-1))
37 {
39 }
40 // If the date is in the current year, show month and day.
41 else if (Date.Year == Now.Year)
42 {
43 return Date.ToString("MMMM dd", culture);
44 }
45 // Otherwise, show the full date.
46 else
47 {
48 return Date.ToString("MM/dd/yyyy", culture);
49 }
50 }
51 return value;
52 }
53
54 public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
55 {
56 throw new NotImplementedException();
57 }
58 }
59}
A strongly-typed resource class, for looking up localized strings, etc.
static string Yesterday
Looks up a localized string similar to Yesterday.
static string Today
Looks up a localized string similar to Today.
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IReportingStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:370
Converts a DateTime value into a contextually formatted date string.