[xsl] Calculate Monthly Recuring dates

Subject: [xsl] Calculate Monthly Recuring dates
From: Adam Retter <adam.retter@xxxxxxxxxxxx>
Date: Tue, 30 Jan 2007 15:34:56 +0000
I do not know if my brain is on a go slow this afternoon or what, but I
am really struggling with this one, so perhaps someone has already tried
or knows how to do this.

(BTW - my XSLT Processor is Saxon 8 and I am already making use of EXSLT
for other date related operations).

Scenario -

An event happens on the Same day of the same Week every month.
So an event on the 4th February 2006, happens on the 1st Saturday of
every month.

I want to take today's date and from that work out the next event
occurrence, the event could be this month if the date has not passed, or
if not then next month.

I have at the moment something like this -

<xsl:variable name="start" value="xs:date('2006-02-04')"/>
<xsl:variable name="startDayInWeek" select="date:day-in-week($start)"/>
<xsl:variable
name="thisDayInWeek"select="date:day-in-week(current-date())"/>
<xsl:variable name="startWeekInMonth"
select="date:week-in-month($start)"/>
<xsl:variable name="thisWeekInMonth"
select="date:week-in-month(current-date())"/>
    
        <xsl:choose>
            <xsl:when test="$thisWeekInMonth &lt; $startWeekInMonth and
$thisDayInWeek &lt;= $startDayInWeek">
                <!-- 1) TODO: event is yet to occur this month,
calculate the date for this month -->
            </xsl:when>
            <xsl:otherwise>
                <!-- 2) TODO: event has already occured this month,
calculate the date for next month -->
	</xsl:otherwise>
</xsl:choose>


Now the parts where I am struggling, I have marked with TODO and what
needs to be done. So for 1) I need a mechanism for working out the date
for the 1st Saturday of this month. and for 2) I need a mechanism for
working out the 1st saturday of next month. How can I acheive this?

Thanks very much

-- 
Adam Retter

Principal Developer
Devon Portal Project
Room 310
County Hall
Topsham Road
Exeter
EX2 4QD

t: 01392 38 3683
f: 01392 38 2966
e: adam.retter@xxxxxxxxxxxx
w: www.devonline.gov.uk

Current Thread