[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Computed dateTime

Subject: Re: Computed dateTime
From: "Markus Flatscher markus.flatscher@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 12 Apr 2024 22:37:04 -0000
Re:  Computed dateTime
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.