Skip to content

Commit accfe28

Browse files
committed
UCUM units not supported on difference between dates https://cql.hl7.org/09-b-cqlreference.html#difference
1 parent 125f413 commit accfe28

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

Cql/Cql.Abstractions/Primitives/CqlDateTimeMath.cs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,18 @@ internal static class CqlDateTimeMath
3333

3434
switch (precision)
3535
{
36-
case UCUMUnits.Year:
37-
throw new NotImplementedException();
36+
// https://cql.hl7.org/09-b-cqlreference.html#difference
37+
// UCUM units not supported here
3838

3939
case "year":
4040
var yearDiff = (secondDto.Year - firstDto.Year);
4141
return yearDiff;
4242

43-
case UCUMUnits.Month:
44-
throw new NotImplementedException();
45-
4643
case "month":
4744
var monthDiff = (12 * (secondDto.Year - firstDto.Year) + secondDto.Month - firstDto.Month);
4845
return monthDiff;
4946

50-
case "week" or UCUMUnits.Week:
47+
case "week":
5148
{
5249
var span = secondDto.Subtract(firstDto);
5350
var weeks = span.TotalDays / 7d;
@@ -59,7 +56,7 @@ internal static class CqlDateTimeMath
5956
else return asInt;
6057
}
6158

62-
case "day" or UCUMUnits.Day:
59+
case "day":
6360
{
6461
var span = secondDto.Subtract(firstDto);
6562
var asInt = (int)span.TotalDays;
@@ -72,7 +69,7 @@ internal static class CqlDateTimeMath
7269
else return asInt;
7370
}
7471

75-
case "hour" or UCUMUnits.Hour:
72+
case "hour":
7673
{
7774
var span = secondDto.Subtract(firstDto);
7875
var asInt = (int)span.TotalHours;
@@ -85,7 +82,7 @@ internal static class CqlDateTimeMath
8582
else return asInt;
8683
}
8784

88-
case "minute" or UCUMUnits.Minute:
85+
case "minute":
8986
{
9087
var span = secondDto.Subtract(firstDto);
9188
var asInt = (int)span.TotalMinutes;
@@ -98,7 +95,7 @@ internal static class CqlDateTimeMath
9895
else return asInt;
9996
}
10097

101-
case "second" or UCUMUnits.Second:
98+
case "second":
10299
{
103100
var span = secondDto.Subtract(firstDto);
104101
var asInt = (int)span.TotalSeconds;
@@ -111,7 +108,7 @@ internal static class CqlDateTimeMath
111108
else return asInt;
112109
}
113110

114-
case "millisecond" or UCUMUnits.Millisecond:
111+
case "millisecond":
115112
{
116113
var span = secondDto.Subtract(firstDto);
117114
var asInt = (int)span.TotalMilliseconds;
@@ -136,8 +133,8 @@ internal static class CqlDateTimeMath
136133
var calendar = new GregorianCalendar();
137134
switch (precision)
138135
{
139-
case UCUMUnits.Year:
140-
throw new NotImplementedException();
136+
// https://cql.hl7.org/09-b-cqlreference.html#difference
137+
// UCUM units not supported here
141138

142139
case "year":
143140
var yearDiff = secondDto.Year - firstDto.Year;
@@ -206,9 +203,6 @@ internal static class CqlDateTimeMath
206203
yearDiff += 1;
207204
return yearDiff;
208205

209-
case UCUMUnits.Month:
210-
throw new NotImplementedException();
211-
212206
case "month":
213207
var monthDiff = (12 * (secondDto.Year - firstDto.Year) + secondDto.Month - firstDto.Month);
214208
if (monthDiff > 0 && secondDto.Day < firstDto.Day)
@@ -217,13 +211,13 @@ internal static class CqlDateTimeMath
217211
monthDiff += 1;
218212
return monthDiff;
219213

220-
case "week" or UCUMUnits.Week: return (int)(secondDto.Subtract(firstDto).TotalDays / DaysPerWeekDouble);
221-
case "day" or UCUMUnits.Day: return (int)secondDto.Subtract(firstDto).TotalDays;
222-
case "hour" or UCUMUnits.Hour: return (int)secondDto.Subtract(firstDto).TotalHours;
223-
case "minute" or UCUMUnits.Minute: return (int)secondDto.Subtract(firstDto).TotalMinutes;
224-
case "second" or UCUMUnits.Second: return (int)secondDto.Subtract(firstDto).TotalSeconds;
225-
case "millisecond" or UCUMUnits.Millisecond: return (int)secondDto.Subtract(firstDto).TotalMilliseconds;
226-
default: throw new ArgumentException($"Unit '{precision}' is not supported.");
214+
case "week": return (int)(secondDto.Subtract(firstDto).TotalDays / DaysPerWeekDouble);
215+
case "day": return (int)secondDto.Subtract(firstDto).TotalDays;
216+
case "hour": return (int)secondDto.Subtract(firstDto).TotalHours;
217+
case "minute": return (int)secondDto.Subtract(firstDto).TotalMinutes;
218+
case "second": return (int)secondDto.Subtract(firstDto).TotalSeconds;
219+
case "millisecond": return (int)secondDto.Subtract(firstDto).TotalMilliseconds;
220+
default: throw new ArgumentException($"Unit '{precision}' is not supported.");
227221
}
228222
}
229223

0 commit comments

Comments
 (0)