@@ -38,6 +38,8 @@ public class QueryBuilderHelper {//implements QueryBuilder {
3838 private static final int EAST = 2 ;
3939 private static final int NORTH = 3 ;
4040 private static final int DEFAULT_LIMIT = 10 ;
41+ // https://github.com/radiantearth/stac-spec/blob/v0.8.0/api-spec/STAC-extensions.yaml#L1144
42+ private static final String OPEN_INTERVAL_SYMBOL = ".." ;
4143
4244 public static BoolQueryBuilder buildQuery (double [] bbox , String time , String query , Integer limit , String next ,
4345 String [] ids , String [] collections , FieldsExtension fields ,
@@ -113,29 +115,30 @@ public static Optional<QueryBuilder> timeBuilder(String time) {
113115
114116 if (time .indexOf ("/" ) > 0 ) {
115117 String [] timeArray = time .split ("/" );
116- startTimeProperty = timeArray [0 ];
117- endTimeProperty = timeArray [1 ];
118-
119- try {
120- // see if the value can be parsed into a period, eg P1Y2M3W4D
121- Period period = Period .parse (endTimeProperty );
122-
123- Instant start = Instant .parse (startTimeProperty );
124- Instant end = start .plus (period );
125-
126- start .plus (period .normalized ());
127-
128- startTimeProperty = start .toString ();
129- endTimeProperty = end .toString ();
130-
131- } catch (DateTimeParseException e ) {
132- // not a period
118+ startTimeProperty = dateStringOrOpenInterval (timeArray [0 ]);
119+ endTimeProperty = dateStringOrOpenInterval (timeArray [1 ]);
120+ if (endTimeProperty != null ) {
121+ // check if end time is not null;
122+ // otherwise, NullPointerException will be thrown during parse
123+ try {
124+ // see if the value can be parsed into a period, eg P1Y2M3W4D
125+ Period period = Period .parse (endTimeProperty );
126+
127+ Instant start = Instant .parse (startTimeProperty );
128+ Instant end = start .plus (period );
129+
130+ start .plus (period .normalized ());
131+
132+ startTimeProperty = start .toString ();
133+ endTimeProperty = end .toString ();
134+ } catch (DateTimeParseException e ) {
135+ // not a period
136+ }
133137 }
134138 } else {
135139 startTimeProperty = time ;
136140 endTimeProperty = time ;
137141 }
138-
139142 RangeQueryBuilder rangeQueryBuilder = QueryBuilders
140143 .rangeQuery (FieldName .DATETIME_FULL )
141144 .from (startTimeProperty )
@@ -144,6 +147,13 @@ public static Optional<QueryBuilder> timeBuilder(String time) {
144147 return Optional .of (rangeQueryBuilder );
145148 }
146149
150+ private static String dateStringOrOpenInterval (String value ) {
151+ if (value .equals (OPEN_INTERVAL_SYMBOL )) {
152+ return null ;
153+ }
154+ return value ;
155+ }
156+
147157 public static Optional <QueryBuilder > intersectsBuilder (Object intersects ) {
148158 if (intersects == null ) {
149159 return Optional .empty ();
0 commit comments