google.protobuf.Timestamp incorrectly interpreted as date
zboralski opened this issue · 2 comments
zboralski commented
Using the swift4 codegen
google.protobuf.Timestamp updated_time = 4;
will incorrectly be interpreted as a date field.
returnedError(Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: ["profiles", _JSONKey(stringValue: "Index 0", intValue: 0), "updated_time"], debugDescription: "Date string does not match format expected by formatter.", underlyingError: nil)))
zboralski commented
ok... I read the doc and I get I need to set the date format correctly
// In JSON format, the Timestamp type is encoded as a string in the
// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
// format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
// where {year} is always expressed using four digits while {month}, {day},
// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
// is required, though only UTC (as indicated by "Z") is presently supported.
//
// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
// 01:30 UTC on January 15, 2017.
zboralski commented
So the configuration is completely ignored for decoding. It is only used for encoding.
I managed to make it work using
let df = DateFormatter.init()
df.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZZ"
CodableHelper.dateformatter = df