Skip to content
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

clarify what today() and now() return exactly #56

Closed
MartijnR opened this issue Dec 22, 2016 · 6 comments
Closed

clarify what today() and now() return exactly #56

MartijnR opened this issue Dec 22, 2016 · 6 comments

Comments

@MartijnR
Copy link
Contributor

@lognaturel writes:

Would be good to explicitly call out the format and/or say it's DateUtils.roundDate(new Date()), same with now()...

It should be clear what should be returned by these functions at least for datatypes: date, time, datetime, integer, decimal (and string? - that one scares me).

This should be done in a language-agnostic manner (no references to Java or JavaRosa).

@lognaturel
Copy link
Member

Oops, yes, you're right about it needing to be language-agnostic.

@lognaturel
Copy link
Member

XForms equivalents are local-date() and now(), both return strings. But I agree that's not as useful. Were you thinking it could be written as something like "a date object as defined by the implementation language's standard libraries"?

@MartijnR
Copy link
Contributor Author

MartijnR commented Dec 23, 2016

Oh totally didn't realize that it is in XForms.

Your "date object" suggestion makes sense to me. I think XPath has no way of calculating today() + 1 correctly, because it cannot recognize datetime strings as special strings.

So maybe we need to describe in the spec how a datetime string is converted to a "Number" and "String" type (in XPath terminology) internally in the XPath evaluator, so independent from the datatype of the question.

@lognaturel
Copy link
Member

Err, right. XPath. So today() and now() are intended to be custom XPath functions rather than XForms functions. Given their usage, I guess that makes sense. The relationship between XPath and XForms is also something that might merit a sentence or two.

XPath does define a format for date and time. I didn't totally understand what you said about today() + 1. Xpath defines the add-dayTimeDuration-to-dateTime) function for that behavior which backs + for a duration and a dateTime. Do you mean that in the context of this sub-spec, the date-time and duration types aren't defined which is why that can't be supported?

@MartijnR
Copy link
Contributor Author

MartijnR commented Dec 23, 2016

(I'm just thinking out loud, this date/datetime stuff is very confusing to me).

I meant that an XPath 1.0 evaluator doesn't have a built-in date-like type (it only has Number, String, Nodeset and Boolean, and converts string values to one of these depending on the type of function/operator). So if you're sending an expression such as "now() + 1", which I think we support in ODK, to a pure XPath 1.0 evaluator, with XForms 1.0 now() support, you'd get response NaN. Note: the actual datatype (in <bind> of the question this expression belongs to is not relevant.

So I wonder if we could write in our spec:

  • now() as in XForms 1.0
  • today() as now() but without the 'T' and time component.

[And the real ODK customization:]

In addition, it is possible in ODK XForms to perform arithmetic and comparisons with date and datetime strings whereby each is converted to [rounded? tbc] days since the epoch (1970-01-01T00:00:00Z).

Would that correspond to how JavaRosa does things, or have I misunderstood?

Maybe a more realistic example would be the expression ". < today()", where the XPath evaluator has to recognize that "." is a date or datetime. This is a custom thing we do.

P.S. in hindsight, I think we should have obligated users to wrap dates in date() for comparisons and arithmetic.

@getodk getodk deleted a comment from igalchuk Jan 8, 2019
@getodk getodk deleted a comment from igalchuk Jan 8, 2019
@MartijnR MartijnR self-assigned this Jan 9, 2019
@getodk-bot
Copy link
Member

Hello @MartijnR, you claimed this issue to work on it, but this issue and any referenced pull requests haven't been updated for 10 days. Are you still working on this issue?

If so, please update this issue by leaving a comment on this issue to let me know that you're still working on it. Otherwise, I'll automatically remove you from this issue in 5 days.

If you've decided to work on something else, simply comment @opendatakit-bot unclaim so that someone else can claim it and continue from where you left off.

Thank you for your valuable contributions to Open Data Kit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants