Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.kintone.client.model.record.FieldType;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import lombok.Data;

/**
Expand All @@ -13,6 +15,8 @@
@JsonIgnoreProperties(value = "type", allowGetters = true)
public class DateTimeFieldProperty implements FieldProperty {

private final DateTimeFormatter DEFAULT_VALUE_FORMATTER = DateTimeFormatter.ISO_ZONED_DATE_TIME;

/** The field code of the field. */
private String code;

Expand Down Expand Up @@ -55,4 +59,23 @@ public class DateTimeFieldProperty implements FieldProperty {
public FieldType getType() {
return FieldType.DATETIME;
}

// Kintone API returns defaultValue in the format of `yyyy-MM-dd'T'HH:mm`.
// This value is lack of compatibility with the ISO-8601 format, so DateTimeParseException occurs like following.
// java.time.format.DateTimeParseException: Text '2019-03-27T10:15' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {},ISO resolved to 2019-03-27T10:15 of type java.time.format.Parsed
// This is a workaround until the API returns the expected format.
public void setDefaultValue(String defaultValue) {
if (defaultValue.isEmpty()) {
return;
}
try {
this.defaultValue = ZonedDateTime.parse(defaultValue, DEFAULT_VALUE_FORMATTER);
} catch (DateTimeParseException ex) {
if (defaultValue.matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}")) {
this.defaultValue = ZonedDateTime.parse(defaultValue + ":00Z", DEFAULT_VALUE_FORMATTER);
} else {
throw ex;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"noLabel": false,
"required": false,
"unique": false,
"defaultValue": "2020-01-01T01:30:00.000Z",
"defaultValue": "2020-01-01T01:30",
"defaultNowValue": false
}
}