• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / EntityChange / 13417967502

19 Feb 2025 04:51PM UTC coverage: 45.43% (+5.7%) from 39.697%
13417967502

push

github

pwelter34
fix failing test

287 of 726 branches covered (39.53%)

Branch coverage included in aggregate %.

563 of 1145 relevant lines covered (49.17%)

73.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

12.0
/src/EntityChange/StringFormatter.cs
1
using System.Text;
2

3
namespace EntityChange;
4

5
/// <summary>
6
/// Standard string format options
7
/// </summary>
8
public static class StringFormatter
9
{
10
    /// <summary>
11
    /// Format the specified <paramref name="value"/> as a Currency.
12
    /// </summary>
13
    /// <param name="value">The value to format.</param>
14
    /// <returns></returns>
15
    public static string? Currency(object? value)
16
    {
17
        if (value is null)
3!
18
            return null;
×
19

20
        if (value is not IConvertible)
3!
21
            return value.ToString();
×
22

23
        var d = Convert.ToDecimal(value);
3✔
24
        return d.ToString("C");
3✔
25
    }
26

27
    /// <summary>
28
    /// Format the specified <paramref name="value"/> as a Number.
29
    /// </summary>
30
    /// <param name="value">The value to format.</param>
31
    /// <returns></returns>
32
    public static string? Number(object? value)
33
    {
34
        if (value is null)
3!
35
            return null;
×
36

37
        if (value is not IConvertible)
3!
38
            return value.ToString();
×
39

40
        var d = Convert.ToDecimal(value);
3✔
41
        return d.ToString("N2");
3✔
42
    }
43

44

45
    /// <summary>
46
    /// Format the specified <paramref name="value"/> as a Short Date pattern.
47
    /// </summary>
48
    /// <param name="value">The value to format.</param>
49
    /// <returns></returns>
50
    public static string? ShortDate(object? value)
51
    {
52
        if (value is null)
×
53
            return null;
×
54

55
        if (value is not IConvertible)
×
56
            return value.ToString();
×
57

58
        var d = Convert.ToDateTime(value);
×
59
        return d.ToString("d");
×
60
    }
61

62
    /// <summary>
63
    /// Format the specified <paramref name="value"/> as a Long Date pattern.
64
    /// </summary>
65
    /// <param name="value">The value to format.</param>
66
    /// <returns></returns>
67
    public static string? LongDate(object? value)
68
    {
69
        if (value is null)
×
70
            return null;
×
71

72
        if (value is not IConvertible)
×
73
            return value.ToString();
×
74

75
        var d = Convert.ToDateTime(value);
×
76
        return d.ToString("D");
×
77
    }
78

79
    /// <summary>
80
    /// Format the specified <paramref name="value"/> as a Full Date Short Time pattern.
81
    /// </summary>
82
    /// <param name="value">The value to format.</param>
83
    /// <returns></returns>
84
    public static string? FullDateShortTime(object? value)
85
    {
86
        if (value is null)
×
87
            return null;
×
88

89
        if (value is not IConvertible)
×
90
            return value.ToString();
×
91

92
        var d = Convert.ToDateTime(value);
×
93
        return d.ToString("f");
×
94
    }
95

96
    /// <summary>
97
    /// Format the specified <paramref name="value"/> as a Full Date Long Time pattern.
98
    /// </summary>
99
    /// <param name="value">The value to format.</param>
100
    /// <returns></returns>
101
    public static string? FullDateLongTime(object? value)
102
    {
103
        if (value is null)
×
104
            return null;
×
105

106
        if (value is not IConvertible)
×
107
            return value.ToString();
×
108

109
        var d = Convert.ToDateTime(value);
×
110
        return d.ToString("F");
×
111
    }
112

113
    /// <summary>
114
    /// Format the specified <paramref name="value"/> as a General Date Short Time pattern.
115
    /// </summary>
116
    /// <param name="value">The value to format.</param>
117
    /// <returns></returns>
118
    public static string? GeneralDateShortTime(object? value)
119
    {
120
        if (value is null)
×
121
            return null;
×
122

123
        if (value is not IConvertible)
×
124
            return value.ToString();
×
125

126
        var d = Convert.ToDateTime(value);
×
127
        return d.ToString("g");
×
128
    }
129

130
    /// <summary>
131
    /// Format the specified <paramref name="value"/> as a General Date Long Time pattern.
132
    /// </summary>
133
    /// <param name="value">The value to format.</param>
134
    /// <returns></returns>
135
    public static string? GeneralDateLongTime(object? value)
136
    {
137
        if (value is null)
×
138
            return null;
×
139

140
        if (value is not IConvertible)
×
141
            return value.ToString();
×
142

143
        var d = Convert.ToDateTime(value);
×
144
        return d.ToString("G");
×
145
    }
146

147
    /// <summary>
148
    /// Format the specified <paramref name="value"/> as a Short Time pattern.
149
    /// </summary>
150
    /// <param name="value">The value to format.</param>
151
    /// <returns></returns>
152
    public static string? ShortTime(object? value)
153
    {
154
        if (value is null)
×
155
            return null;
×
156

157
        if (value is not IConvertible)
×
158
            return value.ToString();
×
159

160
        var d = Convert.ToDateTime(value);
×
161
        return d.ToString("t");
×
162
    }
163

164
    /// <summary>
165
    /// Format the specified <paramref name="value"/> as a Long Time pattern.
166
    /// </summary>
167
    /// <param name="value">The value to format.</param>
168
    /// <returns></returns>
169
    public static string? LongTime(object? value)
170
    {
171
        if (value is null)
×
172
            return null;
×
173

174
        if (value is not IConvertible)
×
175
            return value.ToString();
×
176

177
        var d = Convert.ToDateTime(value);
×
178
        return d.ToString("T");
×
179
    }
180
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc