Skip to content

Commit

Permalink
add support for week-date in TimePosition
Browse files Browse the repository at this point in the history
  • Loading branch information
clausnagel committed Mar 9, 2024
1 parent 07b4d26 commit c019807
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/main/java/org/xmlobjects/gml/model/temporal/TimePosition.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import org.xmlobjects.gml.model.GMLObject;
import org.xmlobjects.xml.TextContent;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

public class TimePosition extends GMLObject {
private TimePositionValue<?> value;
private String frame;
Expand Down Expand Up @@ -49,20 +53,27 @@ public void setValue(TimePositionValue<?> value) {

public void setValue(String value) {
TextContent content = TextContent.of(value);
if (content.isDateTime())
if (content.isDateTime()) {
this.value = new DateAndTime(content.getAsDateTime());
else if (content.isTime())
this.value = new ClockTime(content.getAsTime().toOffsetTime());
else if (content.isDate())
} else if (content.isTime()) {
System.out.println(content.getAsTime());
this.value = new ClockTime(content.getAsTime().toLocalTime());
} else if (content.isDate()) {
this.value = new CalendarDate(content.getAsDate(), CalenderDateType.DATE);
else if (content.isGYear())
} else if (content.isGYear()) {
this.value = new CalendarDate(content.getAsGYear(), CalenderDateType.YEAR);
else if (content.isGYearMonth())
} else if (content.isGYearMonth()) {
this.value = new CalendarDate(content.getAsGYearMonth(), CalenderDateType.YEAR_MONTH);
else if (content.isDouble())
} else if (content.isDouble()) {
this.value = new TimeCoordinate(content.getAsDouble());
else
this.value = new OrdinalPosition(value);
} else {
try {
LocalDate date = LocalDate.parse(value, DateTimeFormatter.ISO_WEEK_DATE);
this.value = new CalendarDate(TextContent.of(date.toString()).getAsDate(), CalenderDateType.DATE);
} catch (DateTimeParseException e) {
this.value = new OrdinalPosition(value);
}
}
}

public String getFrame() {
Expand Down

0 comments on commit c019807

Please sign in to comment.