Month names, (other names like day of week, but mostly month) have an ambiguity problem for parsing in the XPath date format specs, which were intended originally for printing not parsing. A degenerate case is a pattern like "[MNn,3][D]" (note no separator and implementation dependent widths) So formally the problem is intractable. Pragmatically the issue stems from the ICU library being used which does not provide for a good mapping between W3C format picture and ICU patterns - around V7 time the whole datetime formatting and parsing code was redone and a side effect of much better formatting is the inability to parse names.
I suggest something simple. It would be in the server code if it could be done generically and for all locales but it cant. Roughly ... declare variable $months := ( "Jan" , "Feb" , "Mar" ... ); let $date := "Jan 10, 2013" let $tok := fn:tokenize($date,",? +"), $m := fn:index-of( $months, $tok[1] ) , $d := xs:integer($tok[2]), $y := $tok[3] return ( $y || "-" || (if( $m lt 9 ) then "0" else "") || $m ||"-" || (if( $d lt 10) then "0" else "") || $d ) ---- Or something similar fromthe functx library ----------------------------------------------------------------------------- David Lee Lead Engineer MarkLogic Corporation d...@marklogic.com Phone: +1 812-482-5224 Cell: +1 812-630-7622 www.marklogic.com<http://www.marklogic.com/> From: general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] On Behalf Of Danny Sokolsky Sent: Thursday, May 28, 2015 6:44 PM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] XDMP-PATTERNVALUEMISMATCH: xdmp:parse-dateTime Hi Kari, I also see the different behavior on 7 and the latest 8. There is a bug fix in my code not yet released, which is likely why it is working for me on the latest 8. The problem is with the Month names. There is a note in the documentation saying this does not always parse the month names. The only workaround I can think of is to substitute in the month number for the month name, as that seems to work on 7.0-5. But that might get you past the problem. For example, this works on 7.0-5.1: let $startdateTime := "05 28 2015" return xdmp:parse-dateTime("[M1] [D1] [Y0001]", $startdateTime, "en") => 2015-05-28T00:00:00-07:00 -Danny From: general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com> [mailto:general-boun...@developer.marklogic.com] On Behalf Of Kari Cowan Sent: Thursday, May 28, 2015 2:24 PM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] XDMP-PATTERNVALUEMISMATCH: xdmp:parse-dateTime Hmm, I have 8.02 on my local machine, and it still throws that error so it must be more recent than that version. Either way, we're using v.7 in my dev/stage environments (where I am seeing an error), and v.6 on production. It may be a while I have 8 available to me on our live servers. Any other workaround you might suggest? From: general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com> [mailto:general-boun...@developer.marklogic.com] On Behalf Of Danny Sokolsky Sent: Thursday, May 28, 2015 1:50 PM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] XDMP-PATTERNVALUEMISMATCH: xdmp:parse-dateTime There are a number of bugs that have been fixed on xdmp:parse-dateTime since 6.0-3. This works in a recent 8.0 build: xquery version "1.0-ml"; let $startdateTime:="May 28, 2015" return fn:format-dateTime((xdmp:parse-dateTime("[MNn] [D1], [Y0001]", xs:string( $startdateTime ) )), "[Y0001]-[M01]-[D01]" ) ? 2015-05-28 -Danny From: general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com> [mailto:general-boun...@developer.marklogic.com] On Behalf Of Kari Cowan Sent: Thursday, May 28, 2015 12:38 PM To: general@developer.marklogic.com<mailto:general@developer.marklogic.com> Subject: [MarkLogic Dev General] XDMP-PATTERNVALUEMISMATCH: xdmp:parse-dateTime Ok, so my date input below is "May 28, 2015", but my script below says my pattern doesn't match. I think it should but according to the comment in https://docs.marklogic.com/xdmp:parse-dateTime, as of 6.0-3.1 this function does not round-trip non-numeric values. For example format-dateTime(current-dateTime(), '[MN]') => JUNE but xdmp:parse-dateTime('[MN]', 'JUNE') throws XDMP-PATTERNVALUEMISMATCH. I need to convert a date like "May 28, 2015" to something like 2015-05-28 so that I can use it to compare dates as a part of a query. What am I missing? Here's a scriptlet that illustrates the issue. xquery version "1.0-ml"; declare namespace html = "http://www.w3.org/1999/xhtml"; declare namespace local="this"; declare function local:convert-date($startdateTime as xs:string) as node()*{ fn:format-dateTime((xdmp:parse-dateTime("[MNn] [D1], [Y0001]", xs:string( $startdateTime ) )), "[Y0001]-[M01]-[D01]" ) }; declare variable $startdateTime as xs:string external; let $startdateTime:="May 28, 2015" (: return $startdateTime :) let $this-start-date:= local:convert-date($startdateTime) return $this-start-date ________________________________ Learn more about ALM, visit http://www.alm.com . - ALM, an Integrated Media Company, is a leading provider of news and information for the legal and commercial real estate markets. ALM's market-leading brands include The American Lawyer, Corporate Counsel, GlobeSt.com, Insight Conferences, Law.com, Law Journal Press, LegalTech, The National Law Journal and Real Estate Forum. ________________________________ Learn more about ALM, visit http://www.alm.com . - ALM, an Integrated Media Company, is a leading provider of news and information for the legal and commercial real estate markets. ALM's market-leading brands include The American Lawyer, Corporate Counsel, GlobeSt.com, Insight Conferences, Law.com, Law Journal Press, LegalTech, The National Law Journal and Real Estate Forum.
_______________________________________________ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general