Perfect. As always appreciate the great support and quick turnaround!

Best,
Ron

> On Nov 6, 2018, at 3:56 AM, Christian Grün <[email protected]> wrote:
> 
> We are working on a web site, which will facilitate the management of
> new external modules for BaseX. Users are expected to be able to
> upload new modules, search for existing modules and install them in
> local BaseX instances with a few clicks. This module will definitely
> be a good candidate for this web site.
> 
> 
>> On Tue, Nov 6, 2018 at 1:35 AM Ron Katriel <[email protected]> wrote:
>> 
>> Hi Andy,
>> 
>> Thanks for the quick solution! I imported the new module and was able to use 
>> the new function as follows:
>> 
>> xs:date(dates:parseDate($trial/completion_date)//value/text()) <= 
>> fn:current-date()
>> 
>> I verified the correctness for ~300 dates and the logic appears solid (for 
>> the kind of dates discussed below).
>> 
>> Any chance this could find its way into a BaseX release?
>> 
>> Best,
>> Ron
>> 
>> On November 5, 2018 at 10:27:48 AM, Andy Bunce ([email protected]) wrote:
>> 
>> Hi Ron,
>> 
>> I took a quick look at Joe's module and made the following changes:
>> 
>> Change datetime:format-date(..,"yyyy-MM-dd") to 
>> format-date(..,"[YYYY]-[MM]-[DD]")
>> Change xdt:dayTimeDuration("P1D") -> xs:dayTimeDuration
>> Change function in namespace local: to dates:
>> 
>> And saved as a gist [1]. Then in BaseX
>> 
>> import module namespace dates = 
>> "https://urldefense.proofpoint.com/v2/url?u=http-3A__xqdev.com_dateparser&d=DwIFaQ&c=fi2D4-9xMzmjyjREwHYlAw&r=44jDQvzmnB_-ovfO6Iusj0ItciJrcWMOQQwd2peEBBE&m=KSPrAMbuxlxJKbnir6BnBSJRDflEuHmbAsMCnMJLIxQ&s=sYD9W2J5UO3Yxx9kgSMF2kixR8dfnRNA4dr4aG8OCKY&e=";
>>  at 
>> "https://urldefense.proofpoint.com/v2/url?u=https-3A__gist.githubusercontent.com_apb2006_ee0effdd53ca80daf4f1b3e99794ed89_raw_7eedb8343c3cbf0e4ef0063be5af532e8bbfe485_date-2Dparser.xqm&d=DwIFaQ&c=fi2D4-9xMzmjyjREwHYlAw&r=44jDQvzmnB_-ovfO6Iusj0ItciJrcWMOQQwd2peEBBE&m=KSPrAMbuxlxJKbnir6BnBSJRDflEuHmbAsMCnMJLIxQ&s=F3LKDivtSE6HjYFHiydFoDkPc4QwuA9DxY7KGutDgFg&e=";;
>> 
>> dates:parseDate("March 2017")
>> 
>> Returns
>> <date resolution="month">
>>  <range>
>>    <start>2017-03-01</start>
>>    <end>2017-03-31</end>
>>  </range>
>>  <value>2017-03-01</value>
>> </date>
>> 
>> Joe,
>> I think all these changes are compatible with eXist too? [2]
>> 
>> Hope this helps.
>> /Andy
>> 
>> [1] 
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__gist.github.com_apb2006_ee0effdd53ca80daf4f1b3e99794ed89&d=DwIFaQ&c=fi2D4-9xMzmjyjREwHYlAw&r=44jDQvzmnB_-ovfO6Iusj0ItciJrcWMOQQwd2peEBBE&m=KSPrAMbuxlxJKbnir6BnBSJRDflEuHmbAsMCnMJLIxQ&s=lk5it1IL8ohiUwEKO-i34hIoz_J5gErrAYCbIR4oRAE&e=
>> [2] 
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__sourceforge.net_p_exist_mailman_message_34988159_&d=DwIFaQ&c=fi2D4-9xMzmjyjREwHYlAw&r=44jDQvzmnB_-ovfO6Iusj0ItciJrcWMOQQwd2peEBBE&m=KSPrAMbuxlxJKbnir6BnBSJRDflEuHmbAsMCnMJLIxQ&s=3_TI_h72pN_xdioUzLeDu-876lz_H-YlgHDJr2MAIX0&e=
>> 
>>> On Mon, 5 Nov 2018 at 02:03, Ron Katriel <[email protected]> wrote:
>>> 
>>> Hi Joe,
>>> 
>>> Thanks for sharing that. I tried adapting your eXist port to BaseX and ran 
>>> into issues with namespaces. At this point I don’t have the time or 
>>> expertise to complete this but hopefully someone else will take up the 
>>> challenge.
>>> 
>>> Best,
>>> Ron
>>> 
>>> On November 3, 2018 at 12:19:49 AM, Joe Wicentowski ([email protected]) 
>>> wrote:
>>> 
>>> Hi Ron,
>>> 
>>> You might find Ryan Grimm's date-parser library module useful if you have a 
>>> larger range of date formats to handle:
>>> 
>>>  
>>> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_marklogic-2Dcommunity_commons_blob_master_dates_date-2Dparser.xqy&d=DwIFaQ&c=fi2D4-9xMzmjyjREwHYlAw&r=44jDQvzmnB_-ovfO6Iusj0ItciJrcWMOQQwd2peEBBE&m=KSPrAMbuxlxJKbnir6BnBSJRDflEuHmbAsMCnMJLIxQ&s=XB-U5gSL9q8fTpeMVvJHsZcYhEkmxKm5k3z12cmGBjk&e=
>>> 
>>> While it was written with some MarkLogic-specific code, I adapted it for 
>>> use with eXist (but haven't tested it with BaseX):
>>> 
>>>  
>>> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_HistoryAtState_twitter_blob_master_modules_date-2Dparser.xqm&d=DwIFaQ&c=fi2D4-9xMzmjyjREwHYlAw&r=44jDQvzmnB_-ovfO6Iusj0ItciJrcWMOQQwd2peEBBE&m=KSPrAMbuxlxJKbnir6BnBSJRDflEuHmbAsMCnMJLIxQ&s=EFaBAZHvFF1zuS5mpHuVISqqj_tn5jn1Nda_02EH3Yw&e=
>>> 
>>> Best,
>>> Joe
>>> 
>>>> On Fri, Nov 2, 2018 at 6:48 PM Ron Katriel <[email protected]> wrote:
>>>> 
>>>> Hi Christian,
>>>> 
>>>> Much appreciated! I hardened the code (see below) since the dates (from 
>>>> CT.gov) occasionally also have the day of the month (e.g., “March 21, 
>>>> 2014”). Currently the function is dropping the day in such cases but I 
>>>> will look into capturing it in a future iteration.
>>>> 
>>>> Best,
>>>> Ron
>>>> 
>>>> 
>>>> declare function local:to-date($string) {
>>>>  if (fn:matches($string, '[A-Za-z]+ [0-9]+') or fn:matches($string, 
>>>> '[A-Za-z]+ [0-9]+, [0-9]+'))
>>>>  then
>>>>  let $m := index-of($MONTHS, substring-before($string, ' '))
>>>>  let $y := xs:integer(functx:substring-after-last($string, ' '))
>>>>  return xs:date(string-join(
>>>>    (
>>>>      format-number($y, '0000'),
>>>>      format-number($m, '00'),
>>>>      '01'
>>>>    ),
>>>>    '-')
>>>>  )
>>>>  else
>>>>  ()
>>>> };
>>>> 
>>>> On November 2, 2018 at 4:20:41 PM, Christian Grün 
>>>> ([email protected]) wrote:
>>>> 
>>>> Hi Ron,
>>>> 
>>>> If your timestamp is available in IETF format, you can use
>>>> fn:parse-ietf-date [1]. Otherwise, you’ll need to write a simple
>>>> function by yourself:
>>>> 
>>>> declare variable $MONTHS := (
>>>> 'January', 'February', 'March', 'April', 'May', 'June',
>>>> 'July', 'August', 'September', 'October', 'November', 'December'
>>>> );
>>>> 
>>>> declare function local:to-date($string) {
>>>> let $m := index-of($MONTHS, substring-before($string, ' '))
>>>> let $y := xs:integer(substring-after($string, ' '))
>>>> return xs:date(string-join((
>>>> format-number($y, '0000'),
>>>> format-number($m, '00'),
>>>> '01'
>>>> ), '-'))
>>>> };
>>>> local:to-date('March 2017')
>>>> 
>>>> Best,
>>>> Christian
>>>> 
>>>> [1] 
>>>> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.w3.org_TR_xpath-2Dfunctions-2D31_-23func-2Dparse-2Dietf-2Ddate&d=DwIFaQ&c=fi2D4-9xMzmjyjREwHYlAw&r=44jDQvzmnB_-ovfO6Iusj0ItciJrcWMOQQwd2peEBBE&m=Yy9sC1xS_Ix-pGSVDp-Lbmz8BOft0S1WdVpEM-qzRw4&s=uQ3NqCv8FpHulP4q1arjItJX3-gCHwi_06WN4znRz48&e=
>>>> 
>>>> 
>>>> 
>>>>> On Fri, Nov 2, 2018 at 9:09 PM Ron Katriel <[email protected]> wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> Is there a BaseX function for converting a string date in the form of 
>>>>> “March 2017” to xs:date or xs:dateTime?
>>>>> 
>>>>> Thanks,
>>>>> Ron

Reply via email to