File tree Expand file tree Collapse file tree 4 files changed +27
-6
lines changed
Expand file tree Collapse file tree 4 files changed +27
-6
lines changed Original file line number Diff line number Diff line change 11name = " PostgresORM"
22uuid = " 748b5efa-ed57-4836-b183-a38105a77fdd"
33authors = [" Vincent Laugier <vincent.laugier@gmail.com>" ]
4- version = " 0.4 .0"
4+ version = " 0.5 .0"
55
66[deps ]
77DataFrames = " a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Original file line number Diff line number Diff line change @@ -179,10 +179,10 @@ function vector_of_integers2vector_of_enums(
179179end
180180
181181function string2zoneddatetime (str)
182- # eg. "2019-09-03T11:00:00.000Z"
182+
183+ # Attempt 1: eg. "2019-09-03T11:00:00.000Z"
183184 date_match_GMT =
184185 match (r" ^([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}Z)$" , str)
185-
186186 if ! isnothing (date_match_GMT)
187187 # "2019-07-24T00:41:49.732Z" becomes "2019-07-24T00:41:49.732"
188188 date_match_remove_endingZ =
@@ -192,10 +192,28 @@ function string2zoneddatetime(str)
192192 ZonedDateTime (DateTime (date_match_remove_endingZ. match),
193193 TimeZone (" UTC" ))
194194 return utc_zdt
195- else
196- return nothing
197195 end
198196
197+ # Attempt 2: eg. "2022-04-09T18:06:26+02:00"
198+ date_match_with_tz1 =
199+ match (r" ^([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\+ [0-9]{2}:[0-9]{2})$" , str)
200+ if ! isnothing (date_match_with_tz1)
201+ zdt =
202+ ZonedDateTime (date_match_with_tz1. match," yyyy-mm-ddTHH:MM:SSzzzz" )
203+ return zdt
204+ end
205+
206+ # Attempt 3: eg. "2022-04-08T02:30:22.668+02:00"
207+ date_match_with_tz1 =
208+ match (r" ^([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}\+ [0-9]{2}:[0-9]{2})$" , str)
209+ if ! isnothing (date_match_with_tz1)
210+ zdt =
211+ ZonedDateTime (date_match_with_tz1. match," yyyy-mm-ddTHH:MM:SS.ssszzzz" )
212+ return zdt
213+ end
214+
215+ return nothing
216+
199217end
200218
201219function int2enum (enumType:: DataType ,enum_int:: Missing )
Original file line number Diff line number Diff line change 9292end
9393
9494@testset " Test utils.jl - function `string2zoneddatetime`" begin
95- PostgresORMUtil. string2zoneddatetime (" 2019-09-03T11:00:00.000Z" )
95+ PostgresORMUtil. string2zoneddatetime (" 2019-09-03T11:00:00.000Z" ) |> string |> ZonedDateTime
96+ PostgresORMUtil. string2zoneddatetime (" 2022-04-09T18:06:26+01:30" )
97+ PostgresORMUtil. string2zoneddatetime (" 2022-04-08T02:30:22.668+03:00" )
9698end
9799
98100@testset " Test utils.jl - function `postgresql_string_array_2_string_vector`" begin
Original file line number Diff line number Diff line change @@ -13,3 +13,4 @@ using PostgresORM
1313using PostgresORM. PostgresORMUtil
1414using PostgresORM. PostgresORMUtil. Pluralize
1515using PostgresORM. Tool
16+ using TimeZones
You can’t perform that action at this time.
0 commit comments