RTL2 DateTime.TryParse with iso 8601

Hi,
Can I use TryParse with dates in iso 8601 ? I cant seem to get the format string correct. How would I specify the T and the timezone at the end ?

Cheers,
John

Hi John, ISO 8601 is not fully supported at the moment, will be fixed and available in this weekly build.

Thanks.

2 Likes

Hi Diego,

I tried the latest from github,

Is this format string ok ?

var format := ā€œyyyy-MM-ddTHH:mm:sszzzā€;

with .net core calling DateTime ToString works ok but on Nougat

  var someDate := new DateTime;
  var value := someDate.ToString(format);

value is ā€˜2020-1-30ā€™

Thanks,
John

??

:slight_smile: Whats wrong with that ?

I guess I misunderstood your question, as the title mentioned DateTime.TryParse but the snipped just created a datetime without parsing.

The format string does look correct to me, but looking at the code, I see that ToString just gets passed do the platformā€™s implementation, NSDateFormatter in the case of Cocoa, so Iā€™d expect that to handle that properly. That said, aside from adding the 0 for the month, https://nsdateformatter.com shows the same output for your format string, just the date and not the timeā€¦

It seems it s there ā€œTā€ that shows it off, as this one works ok: ā€œyyyy-MM-dd HH:mm:sszzzā€

It needs to be able to handle the T, thatā€™s iso 8601

https://feedbackassistant.apple.com/welcome

I was testing the changes for tryparse. In my ios apps Iā€™m using a cocoa static library for back and forth between dates and strings. I was testing tostring to see if I could replace that library with rtl2

I guess weā€™d have/could write our own pure-Elements implementation ToString(format) but that seems like a potentially bottomless task to cover fully. Iā€™ll check what the team thinksā€¦

Thanks. Isnā€™t that the opposite of DateParser ?

Iā€™ve been exploring mapped types recently and its interesting to look at the rtl source code, to see how thatā€™s implemented.

Yeah, you could say that.

At this stage, Iā€™m almost tempted to convert DateTime from a mapped/container class into an entirely native implementation. If we have Parse and Format natively, thatā€™s really the most tricky bitsā€¦

I found this

https://developer.apple.com/documentation/foundation/nsiso8601dateformatter?language=objc

It appeared in ios10+

Looking at the RTL source, I would be happy if I had a ToISO8601String or somehow matched up the format and used that class instead of NSDateFormatter.

Iā€™ll have to explore later on