use of org.n52.shetland.util.DateTimeHelper.parseIsoString2DateTime in project arctic-sea by 52North.
the class SweCommonDecoderV20 method parseTimeRange.
private SweTimeRange parseTimeRange(TimeRangeType xbTime) throws DecodingException {
SweTimeRange sosTimeRange = new SweTimeRange();
if (xbTime.isSetValue()) {
List<?> value = xbTime.getValue();
if (value != null && !value.isEmpty()) {
RangeValue<DateTime> range = new RangeValue<>();
Iterator<?> iter = value.iterator();
if (iter.hasNext()) {
range.setRangeStart(DateTimeHelper.parseIsoString2DateTime(iter.next().toString()));
}
if (iter.hasNext()) {
range.setRangeEnd(DateTimeHelper.parseIsoString2DateTime(iter.next().toString()));
}
sosTimeRange.setValue(range);
}
}
if (xbTime.getUom() != null) {
sosTimeRange.setUom(xbTime.getUom().getHref());
}
if (xbTime.isSetConstraint()) {
sosTimeRange.setConstraint(parseConstraint(xbTime.getConstraint()));
}
if (xbTime.getQualityArray() != null) {
sosTimeRange.setQuality(parseQuality(xbTime.getQualityArray()));
}
return sosTimeRange;
}
use of org.n52.shetland.util.DateTimeHelper.parseIsoString2DateTime in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_simpleDatarecord_with_fieldTime.
@Test
public void should_encode_simpleDatarecord_with_fieldTime() throws EncodingException {
final String name = "field-1";
final DateTime value = new DateTime(DateTimeZone.UTC);
final XmlObject encode = sweCommonEncoderv101.encode(new SweSimpleDataRecord().addField(new SweField(name, new SweTime().setValue(value))));
assertThat(encode, instanceOf(SimpleDataRecordType.class));
final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) encode;
final AnyScalarPropertyType field1 = xbSimpleDataRecord.getFieldArray(0);
assertThat(xbSimpleDataRecord.getFieldArray().length, is(1));
assertThat(field1.getName(), is(name));
assertThat(field1.isSetTime(), is(TRUE));
assertThat(DateTimeHelper.parseIsoString2DateTime(field1.getTime().getValue().toString()).toString(), is(value.toString()));
}
use of org.n52.shetland.util.DateTimeHelper.parseIsoString2DateTime in project arctic-sea by 52North.
the class GmlDecoderv321 method parseTimePosition.
private TimeInstant parseTimePosition(TimePositionType xbTimePosition) throws DecodingException {
TimeInstant ti = new TimeInstant();
String timeString = xbTimePosition.getStringValue();
if (timeString != null && !timeString.isEmpty()) {
try {
// TODO better differentiate between ISO8601 and indeterminate
// value
ti.setValue(DateTimeHelper.parseIsoString2DateTime(timeString));
ti.setRequestedTimeLength(DateTimeHelper.getTimeLengthBeforeTimeZone(timeString));
} catch (DateTimeParseException ex) {
ti.setIndeterminateValue(new IndeterminateValue(timeString));
}
}
if (xbTimePosition.isSetIndeterminatePosition()) {
ti.setIndeterminateValue(new IndeterminateValue(xbTimePosition.getIndeterminatePosition().toString()));
}
return ti;
}
Aggregations