Stream: hapi
Topic: Date/Time comparison
Grahame Grieve (May 15 2019 at 03:14):
@James Agnew I do not understand the implementation of org.hl7.fhir.r5.model.BaseDateTimeType.equalsUsingFhirPathRules(BaseDateTimeType):
Grahame Grieve (May 15 2019 at 03:14):
BaseDateTimeType me = this; // Per FHIRPath rules, we compare equivalence at the lowest precision of the two values, // so if we need to, we'll clone either side and reduce its precision int lowestPrecision = Math.min(me.getPrecision().ordinal(), theOther.getPrecision().ordinal()); TemporalPrecisionEnum lowestPrecisionEnum = TemporalPrecisionEnum.values()[lowestPrecision]; if (me.getPrecision() != lowestPrecisionEnum) { me = new DateTimeType(me.getValueAsString()); me.setPrecision(lowestPrecisionEnum); } if (theOther.getPrecision() != lowestPrecisionEnum) { theOther = new DateTimeType(theOther.getValueAsString()); theOther.setPrecision(lowestPrecisionEnum); } if (me.hasTimezoneIfRequired() != theOther.hasTimezoneIfRequired()) { if (me.getPrecision() == theOther.getPrecision()) { if (me.getPrecision().ordinal() >= TemporalPrecisionEnum.MINUTE.ordinal() && theOther.getPrecision().ordinal() >= TemporalPrecisionEnum.MINUTE.ordinal()) { boolean couldBeTheSameTime = couldBeTheSameTime(me, theOther) || couldBeTheSameTime(theOther, me); if (!couldBeTheSameTime) { return false; } } } return null; } // Same precision if (me.getPrecision() == theOther.getPrecision()) { if (me.getPrecision().ordinal() >= TemporalPrecisionEnum.MINUTE.ordinal()) { long leftTime = me.getValue().getTime(); long rightTime = theOther.getValue().getTime(); return leftTime == rightTime; } else { String leftTime = me.getValueAsString(); String rightTime = theOther.getValueAsString(); return leftTime.equals(rightTime); } }
Grahame Grieve (May 15 2019 at 03:15):
we start y forcing them to the same precision... and then we compare to see if the precision that we forced them to is indeed the same precision.... uh?
Grahame Grieve (May 15 2019 at 03:19):
and given the comments:
Grahame Grieve (May 15 2019 at 03:19):
* This method returns: * <ul> * <li>true if the given datetimes represent the exact same instant with the same precision (irrespective of the timezone)</li> * <li>true if the given datetimes represent the exact same instant but one includes milliseconds of <code>.[0]+</code> while the other includes only SECONDS precision (irrespecitve of the timezone)</li> * <li>true if the given datetimes represent the exact same year/year-month/year-month-date (if both operands have the same precision)</li> * <li>false if both datetimes have equal precision of MINUTE or greater, one has no timezone specified but the other does, and could not represent the same instant in any timezone</li> * <li>null if both datetimes have equal precision of MINUTE or greater, one has no timezone specified but the other does, and could potentially represent the same instant in any timezone</li> * <li>false if the given datetimes have the same precision but do not represent the same instant (irrespective of timezone)</li> * <li>null otherwise (since these datetimes are not comparable)</li> * </ul>
Grahame Grieve (May 15 2019 at 03:20):
this just outright looks like an error. And, of course, the FHIRPath tests fail. So I think I just need to fix this routine to work as described, and JUnit test it directly...?
Grahame Grieve (May 15 2019 at 03:21):
ah it does have direct tests and they all fail...
James Agnew (May 15 2019 at 13:40):
The logic there is to satisfy the following text in the FhIrPaTh spec: If one operand has less precision than the other, comparison is done at the lowest precision.
The idea being that if the two sides don't have the same precision, we make a copy of whichever one had the higher precision and then reduce the precision of that copy. Then we compare the copy instead of the original.
Grahame Grieve (May 20 2019 at 05:08):
this text has changed in the latest version. And that routine exists to serve the latest version of FHIRPath
Grahame Grieve (May 20 2019 at 06:01):
I checked in a revised version.
James Agnew (May 20 2019 at 13:01):
sounds good
Last updated: Apr 12 2022 at 19:14 UTC