Skip to content

Commit 90ae302

Browse files
committed
Refactor ToDateTimePrecision and update copyright
Refactored the `ToDateTimePrecision` method to use a modern C# switch expression, improving readability and reducing boilerplate. Combined multiple cases into single lines for compactness. Updated the copyright header comment to remove unnecessary characters and ensure proper formatting.
1 parent 63a3f19 commit 90ae302

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

Cql/Iso8601/DateTimePrecision.cs

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
2-
/*
2+
/*
33
* Copyright (c) 2023, NCQA and contributors
44
* See the file CONTRIBUTORS for details.
5-
*
5+
*
66
* This file is licensed under the BSD 3-Clause license
77
* available at https://raw.githubusercontent.com/FirelyTeam/firely-cql-sdk/main/LICENSE
88
*/
@@ -11,38 +11,19 @@ namespace Hl7.Cql.Iso8601
1111
{
1212
public static class DateTimePrecisionExtensions
1313
{
14-
public static DateTimePrecision? ToDateTimePrecision(this string? unit)
15-
{
16-
if (unit == null)
17-
return null;
18-
else switch (unit)
19-
{
20-
case "year":
21-
case "years":
22-
return DateTimePrecision.Year;
23-
case "month":
24-
case "months":
25-
return DateTimePrecision.Month;
26-
case "minute":
27-
case "minutes":
28-
return DateTimePrecision.Minute;
29-
case "millisecond":
30-
case "milliseconds":
31-
return DateTimePrecision.Millisecond;
32-
case "day":
33-
case "days":
34-
return DateTimePrecision.Day;
35-
case "hour":
36-
case "hours":
37-
return DateTimePrecision.Hour;
38-
case "second":
39-
case "seconds":
40-
return DateTimePrecision.Second;
41-
default:
42-
break;
43-
}
44-
return DateTimePrecision.Unknown;
45-
}
14+
public static DateTimePrecision? ToDateTimePrecision(this string? unit) =>
15+
unit switch
16+
{
17+
null => null,
18+
"year" or "years" => DateTimePrecision.Year,
19+
"month" or "months" => DateTimePrecision.Month,
20+
"minute" or "minutes" => DateTimePrecision.Minute,
21+
"millisecond" or "milliseconds" => DateTimePrecision.Millisecond,
22+
"day" or "days" => DateTimePrecision.Day,
23+
"hour" or "hours" => DateTimePrecision.Hour,
24+
"second" or "seconds" => DateTimePrecision.Second,
25+
_ => DateTimePrecision.Unknown
26+
};
4627
}
4728

4829
public enum DateTimePrecision

0 commit comments

Comments
 (0)