Add date-from-components() XPath function


@ln - I was thinking, whilst doing this, a built-in XPath function to accomplish this might be useful addition to ODK's existing suite of date-related functions. A dedicated function that constructs a valid date from day/month/year components is a bit more appealing than hacking together something (hopefully) syntactically correct with a concat(), would better insulate the user from knowing the intricacies of how these data types are represented as strings, and it would take care of this zero-padding messiness... Oh, and it could potentially take care of adding an optional timezone offset, which the XForm spec's date type strictly supports; that is, when @ggalmazor gets around to supporting it... :grin:

[of course, whenever I bring things like this up, somehow I usually manage to get stuck with having to implement it! lol :wink: ]

Date Calculation: how to increment a date by exactly 1 month

FYI the name date-from-components(day,month,year) follows existing

I'm not sure which order of arguments - d,m,y vs y,m,d - is more intuitive. Other than the YYYY-MM-DD order in the resulting string (which we're trying to hide...), there doesnt seems to be a lot of prior art in other date functions wrt ordering.

1 Like

I really like your approach here!

I don't know how broadly-useful this is -- I hadn't come across a need for it before. Maybe we leave this here and wait for one other user to need it? Not that it's complicated but I'm all for keeping our specs lean and mean. (Mean as in "able to slay data collection needs" or something like that) (Not that I am the final authority on any of this)


I'm happy waiting to see if it gains any traction. In the interim, the concat() calculation for zero-padding isnt too terribly horrible...

1 Like

This function sounds great!

I like how Java deals with this in the different types in java.time. It sorts the args from bigger to smaller units so that they all have the same order:

                date(year, month, day)
                time(                  hour, minute, second)
            datetime(year, month, day, hour, minute, second, nanosecond)
datetime with offset(year, month, day, hour, minute, second, nanosecond, timezone)
    time with offset(                  hour, minute, second,             timezone)
1 Like

That's good enuf to constitute 'prior art' to me! :slight_smile:

So (and assuming this gets traction): date-from-components(year,month,day) ?