You are not logged in.
Pages: 1
I get wrong result if dates include time values.
ShowMessage(DateTimeToIso8601Text(Iso8601ToDateTime('1492-10-12T16:00:00')));
// results in '1492-10-13T08:00:00'The fractional time part is always added in Iso8601ToDateTimePUtf8CharVar but should be subtracted if the date is a negative number.
Offline
Values before TDateTime = 0 are just not supported.
In that case you might want to add an assert (or other check/exception) for that ?
(That would be the easiest)
Maybe someone can suggest a patch for TDateTime < 0 if needed and accepted.
Offline
Maybe someone can suggest a patch for TDateTime < 0 if needed and accepted.
The mormot framework is a swiss army knife. Could just be some kind of sharpening.
Date values < 0 are supported as long as they do not have a time part.
Date is integer part and time value is fractional part of a TDateTime. Thus, values between 0.0 and -1.0 are not valid dates.
You can split a TDateTime to date with Int(x) and time with Frac(x). To put date and time together, you can add date and time, but need to subtract time from date, if date is a negative number.
The functions EncodeDateTime and Iso8601ToDateTimePUtf8CharVar in mormot.core.datetime always add the time part. I just would like to see that ObjectToJson and JsonToObject work as expected.
I would suggest to change the last line in Iso8601ToDateTimePUtf8CharVar to
result := result + (1.0 - ((Int64(result) shr 63) shl 1)) *
(h * MilliSecsPerHour +
mi * MilliSecsPerMin +
ss * MilliSecsPerSec + ms) / MilliSecsPerDay;Offline
(1.0 - (Int64(result) shr 63)) is a pretty weird expression - I am not sure Int64(result) works on all compilers and targets.
I suspect a good "if result < 0" could be faster and more explicit, couldn't be?
Offline
(1.0 - (Int64(result) shr 63)) is a pretty weird expression - I am not sure Int64(result) works on all compilers and targets.
I suspect a good "if result < 0" could be faster and more explicit, couldn't be?
Thought, a branchless solution could be more acceptable. But yes indeed, "if result < 0" would be more explicit and cheaper at that point.
Offline
Pages: 1