Closed DanielCarlos231 closed 1 year ago
Yes, the second parameters indicates the YMD pattern in order to proper parse the string to DATE data type. The first 4th indexes are set to .F. because of the format (YMD).
BTW: you can send pull request and I merge your changes into the main branch, now you are an active colaborator and that's a great new for me and for this project.
The dateTime Format DD/MM/YYYY HH:MM:SS and also the DD-MM-YYYY HH:MM:SS were returning a null DateTime because they were not verifying the date format in the case occurs(':', tcDate) >= 2
&& Method formatDate() on jsonutils Class
do case
case 'T' $ tcDate && JavaScript or ISO 8601 format.
do case
case '+' $ tcDate
tcDate = getwordnum(tcDate, 1, '+')
case at('-', tcDate, 3) > 0
tcDate = substr(tcDate, 1, at('-', tcDate, 3)-1)
otherwise
endcase
try
setDateAct = set('Date')
set date ymd
lDate = ctot('^'+tcDate)
catch
lDate = {//::}
finally
set date &setDateAct
endtry
case occurs(':', tcDate) >= 2 && VFP Date Time Format. 'YYYY-mm-dd HH:mm:ss'
try
setDateAct = set('Date')
set date ymd
lDate = ctot(tcDate)
catch
lDate = {//::}
finally
set date &setDateAct
endtry
otherwise
try
setDateAct = set('Date')
if !tlUseDMY
set date ymd
else
set date dmy
endif
lDate = ctod(tcDate)
catch
lDate = {//}
finally
set date &setDateAct
endtry
endcase
So I added the
&& Also verify if the Date or DateTime is DMY Format
if !tlUseDMY
set date ymd
else
set date dmy
endif
Now it is like this:
&& ======================================================================== &&
&& Function FormatDate
&& return a valid date or datetime date type.
&& ======================================================================== &&
function formatDate as variant
lparameters tcDate as string, tlUseDMY as Boolean
local lDate
lDate = .null.
&& IRODG 20210313 ISSUE # 14
do case
case 'T' $ tcDate && JavaScript or ISO 8601 format.
do case
case '+' $ tcDate
tcDate = getwordnum(tcDate, 1, '+')
case at('-', tcDate, 3) > 0
tcDate = substr(tcDate, 1, at('-', tcDate, 3)-1)
otherwise
endcase
try
setDateAct = set('Date')
set date ymd
lDate = ctot('^'+tcDate)
catch
lDate = {//::}
finally
set date &setDateAct
endtry
case occurs(':', tcDate) >= 2 && VFP Date Time Format. 'YYYY-mm-dd HH:mm:ss' and also 'dd-mm-yyyy hh:mm:ss'
try
setDateAct = set('Date')
* set date ymd
&& Also verify if the Date or DateTime is DMY Format
if !tlUseDMY
set date ymd
else
set date dmy
endif
lDate = ctot(tcDate)
catch
lDate = {//::}
finally
set date &setDateAct
endtry
otherwise
try
setDateAct = set('Date')
if !tlUseDMY
set date ymd
else
set date dmy
endif
lDate = ctod(tcDate)
catch
lDate = {//}
finally
set date &setDateAct
endtry
endcase
return lDate
&& IRODG 20210313 ISSUE # 14
endfunc
I tested again and worked just fine
And many thanks for adding me as an active colaborator πππ Let's improve this tool because it is a really uselfull and well organized tooll
I've sent you an invitation as collaborator. Every change you make remember to change the mayor version or revision in the JSONClass.prg file. Try creating your first pull request with these DATE format changes.
I already did the changes I just did not pull them yet, because I wanna confirm something before I do the pulls you said to change the mayor version in the JsonClass.prg, the version there is 9.12 so it should go to 10.12... that got me confused.. did I understand correctly... because I thought it should go from 9.12 to 9.13
because here in Brazil we call major version the first number on the version in this case is 9...
I changed the version from 9.12 to 9.13 and than I did the pull, if it is not the correct version number you tell me and I'll fix it
If you make a big change (new parsing method, new API method, etc) then you should change the mayor version (in this case from 9 to 10.0) but if you make small changes (fixing bugs, extends the number method, new date format, etc) that should change the revision version or menor version (in this case from 9.10 to 9.11).
Ok got it π
I had a dateTime format in "DD/MM/YYYY" and also "DD/MM/YYYY HH:MM:SS" After analizing the code I could detect that the jsonutils in the this.aPattern did not had a RegEx Pattern for that. So I Add those Patterns and some other date and dateTime formats. heres the code I changed:
I just wanted to tell you about this, and check if you think that adding this dates formats are usefull. Also ask if in the RegEx I added to the version I have, setting the this.aPattern[x,2] as true is the correct approach. I know that it has to do with the date format DMY.