Re: [xsl] Computed dateTime

Subject: Re: [xsl] Computed dateTime
From: "Markus Flatscher markus.flatscher@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 12 Apr 2024 22:37:04 -0000
Martin already gave you the gist of it. Just adding to his response:

If you'd like to work with day-of-the-week strings instead of ints and your
own lookup table, there's also functx:day-of-week-name-en().

I ran the following functx tests (under MarkLogic, with the functx library
that ships with it), and the values come back correct. (Caveat: for some
reason (probably an implementation detail of this functx function), it does
not seem to work for dates prior to 1901-01-06, but it does seem to work
reliably into the future.)

```
xquery version "1.0-ml";

import module namespace functx = "http://www.functx.com"; at
"/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";

declare variable $dates := ("1901-01-05", "1901-01-06", "1955-03-07",
"1972-10-10", "2000-01-01", "2024-04-12", "2200-03-04", "3200-12-31",
"9999-12-31");

let $day-of-week-names := for $date in $dates return
(functx:day-of-week-name-en(xs:date($date)), "EMPTY-PRIOR-TO-1901-01-06")[1]
return $day-of-week-names => string-join(", ")

>>>

EMPTY-PRIOR-TO-1901-01-06, Sunday, Monday, Tuesday, Saturday, Friday,
Tuesday, Sunday, Friday
```

By the way: if you have lots of rules such as, quote "third Tuesday of the
month" or "5th of the month provided it is not a Friday", you might have a
nice use case for good old Schematron <https://www.schematron.com/>,
depending on performance requirements.

On Fri, Apr 12, 2024 at 3:16b/PM Martin Honnen martin.honnen@xxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

>
> On 12/04/2024 22:04, Peter Flynn peter@xxxxxxxxxxx wrote:
> > I need to do a number of calendar-based computations involving events
> > determined by formulas such as "third Tuesday of the month" or "5th of
> > the month provided it is not a Friday". It would be convenient to do
> > them in the XSLT, although they could be done in a shell script
> > pre-processor.
> >
> > Before I go reinventing any wheels, is there a function I have missed
> > like weekdayinMonth($date as gYearMonth)[1] to return the date of the
> > first Sunday in the specified month and year?
> >
> >
>
> functx has http://www.xsltfunctions.com/xsl/functx_day-of-week.html
> giving you a number for the day of the week, once you call that on on
> the first of Jan of a certain year you are interested in or the first
> day of a certain month in a certain year you should be able to add the
> number of days as a duration to get a certain other day.

Current Thread