-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'Invalid Date' returned by format-date
function when given an empty value
#864
Comments
Thanks for filing this @jkuester. I took a look at how this works in JavaRosa, and it appears to return an empty string. I think it would make sense to restore that behavior here. Any objections @MartijnR @alxndrsn @lognaturel? |
I think `"Invalid Date"' is entirely Javascript-specific, and there is no particular reason to use it in this library. The |
Seems fine to me to return '' for empty values. Not sure about invalid date values though. I think it might be helpful to return something like (am actually referring to current PR which also changes behavior for invalid dates though not mentioned above) |
@MartijnR, I agree. It would be nice to still report So, Having |
I checked the JavaRosa behavior for It may cause a lot of churn to change the actual implementation signatures (e.g. to accept/return class ORXEDate extends Date {
constructor(...args) {
super(args);
/** @private */
this.isEmpty = args.length === 1 && args[0] === '';
}
toString() {
return this.isEmpty ? '' : super.toString();
}
} |
Okay, so I have spent a bunch of time thinking about this today and going through the code to see what makes the most sense. Ultimately, I am thinking that our changes related to this issue should be limited to these two things:
This will cause this logic to be aligned with JavaRosa. Anytime the JavaRosa implementation of Just to be clear, here is the current behavior of OpenRosa vs JavaRosa: JavaRosa: assertEquals("", formatDateTime(Double.NaN, "%Y-%m-%d"));
assertEquals("", formatDateTime("", "%Y-%m-%d"));
assertEquals(Double.NaN, toDate(Double.NaN, false));
assertEquals("", toDate("", false)); OpenRosa: assertString("format-date(NaN, '%Y-%m-%d')", 'Invalid Date');
assertString("format-date('', '%Y-%m-%d')", 'Invalid Date');
assertString("date(NaN)", 'Invalid Date');
assertString("date('')", 'Invalid Date'); I am proposing we update OpenRosa so that it behaves like this: assertString("format-date(NaN, '%Y-%m-%d')", '');
assertString("format-date('', '%Y-%m-%d')", '');
assertString("date(NaN)", 'Invalid Date');
assertString("date('')", ''); |
In the
1.x
version of openrosa-xpath-evaluator, theformat-date
function returned an empty string. However, as part of the changes for2.0.0
, this logic shifted (perhaps unintentionally?) to return the string'Invalid Date'
instead.Unfortunately, unless I am missing something, the spec for
format-date
does not mention what should be returned in this case.The problem with this behavior change is that it results in some surprising down-stream effects for logic that is processing formatted date values originating from non-required questions. For example:
With this form, if you do not enter a value for
my_date
, then the note displayed isFormatted Date: Invalid Date
.We are trying to figure how how to handle this behavior change in the CHT as we uplift to use
2.x
of openrosa-xpath-evaluator and would appreciate any thoughts or feedback on this! Does it make sense for this function to return'Invalid Date'
even when the given value is just empty?The text was updated successfully, but these errors were encountered: