Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DurationToStringConverter.cs
1using System;
2using System.Globalization;
3using Microsoft.Maui.Controls;
6using Waher.Content;
8
10{
14 public class DurationToStringConverter : IValueConverter
15 {
16 private static readonly DurationParameterValueRenderer renderer = new DurationParameterValueRenderer();
18 public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
19 {
21
22 if (value is Duration Direct)
23 {
24 Duration = Direct;
25 }
26 else if (value is string Str && Duration.TryParse(Str, out Duration Parsed))
27 {
28 Duration = Parsed;
29 }
30 else
31 {
32 return string.Empty;
33 }
34
35 string Language = culture?.Name ?? CultureInfo.CurrentUICulture.Name;
37
38 try
39 {
40 return renderer.ToString(Duration, Language, MarkdownSettings).GetAwaiter().GetResult();
41 }
42 catch
43 {
44 return Duration.ToString();
45 }
46 }
47
49 public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
50 {
51 if (value is string Str && Duration.TryParse(Str, out Duration Parsed))
52 return Parsed;
53
54 return Duration.Zero;
55 }
56 }
57}
Converts Duration values to localized strings using DurationParameterValueRenderer.
object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
Converts a Duration parameter value to a localized human-readable string.
Settings used for Markdown generation of human-readable text.
Represents a duration value, as defined by the xsd:duration data type: http://www....
Definition: Duration.cs:14
override string ToString()
Definition: Duration.cs:516
static bool TryParse(string s, out Duration Result)
Tries to parse a duration value.
Definition: Duration.cs:86
static readonly Duration Zero
Zero value
Definition: Duration.cs:577