1010import static com .ibm .fhir .model .path .util .FHIRPathUtil .getTemporalAmount ;
1111
1212import java .time .LocalTime ;
13- import java .time .OffsetTime ;
14- import java .time .ZoneOffset ;
1513import java .time .format .DateTimeFormatter ;
1614import java .time .format .DateTimeFormatterBuilder ;
1715import java .time .temporal .ChronoField ;
1816import java .time .temporal .Temporal ;
19- import java .time .temporal .TemporalAccessor ;
2017import java .time .temporal .TemporalAmount ;
2118import java .util .Collection ;
2219import java .util .Objects ;
2522
2623public class FHIRPathTimeValue extends FHIRPathAbstractNode implements FHIRPathTemporalValue {
2724 private static final DateTimeFormatter TIME_PARSER_FORMATTER = new DateTimeFormatterBuilder ()
28- .appendPattern ("'T'HH:mm:ss" )
25+ .appendLiteral ("T" )
26+ .appendPattern ("HH" )
2927 .optionalStart ()
30- .appendFraction (ChronoField .MICRO_OF_SECOND , 0 , 6 , true )
31- .optionalEnd ()
32- .optionalStart ()
33- .appendPattern ("XXX" )
28+ .appendPattern (":mm" )
29+ .optionalStart ()
30+ .appendPattern (":ss" )
31+ .optionalStart ()
32+ .appendFraction (ChronoField .MICRO_OF_SECOND , 0 , 6 , true )
33+ .optionalEnd ()
34+ .optionalEnd ()
3435 .optionalEnd ()
36+ .parseDefaulting (ChronoField .MINUTE_OF_HOUR , 0 )
37+ .parseDefaulting (ChronoField .SECOND_OF_MINUTE , 0 )
3538 .toFormatter ();
3639
37- private final TemporalAccessor time ;
40+ private final LocalTime time ;
3841 private final Temporal temporal ;
3942
4043 protected FHIRPathTimeValue (Builder builder ) {
@@ -48,18 +51,7 @@ public boolean isTimeValue() {
4851 return true ;
4952 }
5053
51- public boolean hasTimeZone () {
52- return getTimeZone () != null ;
53- }
54-
55- public ZoneOffset getTimeZone () {
56- if (time instanceof OffsetTime ) {
57- return ((OffsetTime ) time ).getOffset ();
58- }
59- return null ;
60- }
61-
62- public TemporalAccessor time () {
54+ public LocalTime time () {
6355 return time ;
6456 }
6557
@@ -69,14 +61,14 @@ public Temporal temporal() {
6961 }
7062
7163 public static FHIRPathTimeValue timeValue (String time ) {
72- return FHIRPathTimeValue .builder (TIME_PARSER_FORMATTER . parseBest (time , OffsetTime :: from , LocalTime :: from )).build ();
64+ return FHIRPathTimeValue .builder (LocalTime . parse (time , TIME_PARSER_FORMATTER )).build ();
7365 }
7466
75- private static FHIRPathTimeValue timeValue (TemporalAccessor time ) {
67+ private static FHIRPathTimeValue timeValue (LocalTime time ) {
7668 return FHIRPathTimeValue .builder (time ).build ();
7769 }
7870
79- public static FHIRPathTimeValue timeValue (String name , TemporalAccessor time ) {
71+ public static FHIRPathTimeValue timeValue (String name , LocalTime time ) {
8072 return FHIRPathTimeValue .builder (time ).name (name ).build ();
8173 }
8274
@@ -85,14 +77,14 @@ public Builder toBuilder() {
8577 return new Builder (type , time );
8678 }
8779
88- public static Builder builder (TemporalAccessor time ) {
80+ public static Builder builder (LocalTime time ) {
8981 return new Builder (FHIRPathType .SYSTEM_TIME , time );
9082 }
9183
9284 public static class Builder extends FHIRPathAbstractNode .Builder {
93- private final TemporalAccessor time ;
85+ private final LocalTime time ;
9486
95- private Builder (FHIRPathType type , TemporalAccessor time ) {
87+ private Builder (FHIRPathType type , LocalTime time ) {
9688 super (type );
9789 this .time = time ;
9890 }
@@ -131,29 +123,19 @@ public FHIRPathTimeValue build() {
131123 public FHIRPathTimeValue add (FHIRPathQuantityValue quantityValue ) {
132124 Temporal temporal = getTemporal (time );
133125 TemporalAmount temporalAmount = getTemporalAmount (quantityValue );
134- return timeValue (temporal .plus (temporalAmount ));
126+ return timeValue (LocalTime . from ( temporal .plus (temporalAmount ) ));
135127 }
136128
137129 public FHIRPathTimeValue subtract (FHIRPathQuantityValue quantityValue ) {
138130 Temporal temporal = getTemporal (time );
139131 TemporalAmount temporalAmount = getTemporalAmount (quantityValue );
140- return timeValue (temporal .minus (temporalAmount ));
132+ return timeValue (LocalTime . from ( temporal .minus (temporalAmount ) ));
141133 }
142134
143135 @ Override
144136 public boolean isComparableTo (FHIRPathNode other ) {
145- if (other instanceof FHIRPathTimeValue ) {
146- return isComparableTo ((FHIRPathTimeValue ) other );
147- }
148- if (other .getValue () instanceof FHIRPathTimeValue ) {
149- return isComparableTo ((FHIRPathTimeValue ) other .getValue ());
150- }
151- return false ;
152- }
153-
154- private boolean isComparableTo (FHIRPathTimeValue timeValue ) {
155- return (time instanceof LocalTime && timeValue .time instanceof LocalTime ) ||
156- (time instanceof OffsetTime && timeValue .time instanceof OffsetTime );
137+ return other instanceof FHIRPathTimeValue ||
138+ other .getValue () instanceof FHIRPathTimeValue ;
157139 }
158140
159141 @ Override
@@ -162,10 +144,7 @@ public int compareTo(FHIRPathNode other) {
162144 throw new IllegalArgumentException ();
163145 }
164146 FHIRPathTimeValue timeValue = (FHIRPathTimeValue ) ((other instanceof FHIRPathTimeValue ) ? other : other .getValue ());
165- if (time instanceof LocalTime ) {
166- return LocalTime .from (time ).compareTo (LocalTime .from (timeValue .time ));
167- }
168- return OffsetTime .from (time ).compareTo (OffsetTime .from (timeValue .time ));
147+ return time .compareTo (timeValue .time ());
169148 }
170149
171150 @ Override
0 commit comments