Looks like datetimefrom string can not handle Wed, 12 Oct 2022 21:29:52 +0000
What’s that best way to handle this. Do I really need to make a procedure to do so? I can make a month Array and a Day array but I would hope there should be a way of handling multiple standard formats to be parsed into a date variable.
I can’t find a locale for Xojo to use exactly “Wed, 12 Oct 2022 21:29:52 +0000”
You can use datetime from string with “Wed, 12 Oct 2022 at 21:29:52” and create the TimeZone using the +0000, if your string is always the same characters long you may easily create a new string that can be used.
Or maybe you can find a locale that doesn’t use the ‘at hh:mm:ss’ so you will only need to convert the +0000 to GMT or seconds from GMT.
Timothy, from what I can tell there is no way to convert that string to datetime directly with Xojo. Maybe MBS offers a plugin for that or you will need to convert it.
You can open a Feature Request for Xojo to add the option to do FromString and ToString with that format.
Public Function FromIMFTime(IMFTime As String) As DateTime
Const months As String = "Jan?Feb?Mar?Apr?May?Jun?Jul?Aug?Sep?Oct?Nov?Dec?"
Const matchIt = "[a-zA-Z]{3}\s*,\s+(\d\d|\d)\s+([a-zA-Z]{3})\s+(\d{1,4})\s+(\d\d:\d\d:\d\d)\s+\+?(\-?\d\d\d\d)\s*"
Var rex As new RegEx
rex.SearchPattern = matchIt
Var match As RegExMatch = rex.Search(IMFTime ) // day1 mon2 year3 hh:mm:ss4 zone5
If match = Nil Then Return Nil // Invalid
Var day As Integer = match.SubExpressionString(1).Val
Var month As Integer = months.IndexOf(match.SubExpressionString(2))
If month < 0 Then Return Nil
month = month\4+1
Var year As Integer = match.SubExpressionString(3).Val
Var hms() As String = match.SubExpressionString(4).Split(":")
Var n As Integer = match.SubExpressionString(5).Val
Var zone As Integer = n\100
zone = (zone * 60 + n - zone * 100) * 60 // in seconds
Return New DateTime(year, month, day, hms(0).Val, hms(1).Val, hms(2).Val, 0, New TimeZone(zone))
End Function
----------- Example:
Var testDate As DateTime = FromIMFTime(" Wed, 12 Oct 2022 21:29:52 -0300 ")
break