2 <xsl:stylesheet version="1.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
5 xmlns:dt="http://xsltsl.org/date-time"
6 xmlns:str="http://xsltsl.org/string"
7 extension-element-prefixes="doc str">
9 <doc:reference xmlns="">
11 <releaseinfo role="meta">
12 $Id: date-time.xsl 3991 2004-11-10 06:51:55Z balls $
15 <surname>Diamond</surname>
16 <firstname>Jason</firstname>
20 <holder>Steve Ball</holder>
24 <holder>Jason Diamond</holder>
28 <title>Date/Time Processing</title>
32 <title>Introduction</title>
34 <para>This module provides templates for formatting and parsing date/time strings.</para>
36 <para>See <ulink url="http://www.tondering.dk/claus/calendar.html">http://www.tondering.dk/claus/calendar.html</ulink> for more information on calendars and the calculations this library performs.</para>
43 <doc:template name="dt:format-date-time" xmlns="">
44 <refpurpose>Returns a string with a formatted date/time.</refpurpose>
47 <para>The formatted date/time is determined by the format parameter. The default format is %Y-%m-%dT%H:%M:%S%z, the W3C format.</para>
54 <term>xsd-date-time</term>
56 <para>The date-time value in XML Schemas (WXS) format.</para>
57 <para>If this value is specified, it takes priority over other parameters.</para>
64 <para>Year, in either 2 or 4+ digit format..</para>
65 <para>If the year is given as a two digit value, it will be converted to a four digit value using the fixed window method. Values between 00 and 49 will be prepended by "20". Values between 50 and 99 will be prepended by "19".</para>
72 <para>Month (1 - 12; January = 1)</para>
79 <para>Day of month (1 - 31)</para>
86 <para>Hours since midnight (0 - 23)</para>
93 <para>Minutes after hour (0 - 59)</para>
100 <para>Seconds after minute (0 - 59)</para>
105 <term>time-zone</term>
107 <para>Time zone string (e.g., 'Z' or '-08:00')</para>
114 <para>The format specification.</para>
120 <para>Abbreviated weekday name</para>
127 <para>Full weekday name</para>
134 <para>Abbreviated month name</para>
141 <para>Full month name</para>
148 <para>Date and time representation appropriate for locale</para>
155 <para>Day of month as decimal number (01 - 31)</para>
162 <para>Day of month as decimal number (1 - 31)</para>
169 <para>Hour in 24-hour format (00 - 23)</para>
176 <para>Hour in 12-hour format (01 - 12)</para>
183 <para>Hour in 12-hour format (1 - 12)</para>
190 <para>Day of year as decimal number (001 - 366)</para>
197 <para>Month as decimal number (01 - 12)</para>
204 <para>Month as decimal number (1 - 12)</para>
211 <para>Minute as decimal number (00 - 59)</para>
218 <para>Current locale's A.M./P.M. indicator for 12-hour clock, uppercase</para>
225 <para>Current locale's A.M./P.M. indicator for 12-hour clock, uppercase with periods</para>
232 <para>Current locale's A.M./P.M. indicator for 12-hour clock, lowercase</para>
239 <para>Current locale's A.M./P.M. indicator for 12-hour clock, lowercase with periods</para>
246 <para>Second as decimal number (00 - 59)</para>
253 <para>Week of year as decimal number, with Sunday as first day of week (00 - 53)</para>
260 <para>Weekday as decimal number (0 - 6; Sunday is 0)</para>
267 <para>Week of year as decimal number, with Monday as first day of week (00 - 53)</para>
274 <para>Date representation for current locale </para>
281 <para>Time representation for current locale</para>
288 <para>Year without century, as decimal number (00 - 99)</para>
295 <para>Year with century, as decimal number</para>
302 <para>Time-zone name or abbreviation; no characters if time zone is unknown</para>
309 <para>Percent sign</para>
321 <para>Returns a formatted date/time string.</para>
326 <xsl:template name="dt:format-date-time">
327 <xsl:param name='xsd-date-time'/>
328 <xsl:param name="year"/>
329 <xsl:param name="month"/>
330 <xsl:param name="day"/>
331 <xsl:param name="hour"/>
332 <xsl:param name="minute"/>
333 <xsl:param name="second"/>
334 <xsl:param name="time-zone"/>
335 <xsl:param name="format" select="'%Y-%m-%dT%H:%M:%S%z'"/>
337 <xsl:value-of select="substring-before($format, '%')"/>
339 <xsl:variable name="code" select="substring(substring-after($format, '%'), 1, 1)"/>
343 <xsl:when test='$xsd-date-time'>
344 <xsl:call-template name='dt:format-date-time'>
345 <xsl:with-param name='year'>
346 <xsl:call-template name='dt:get-xsd-datetime-year'>
347 <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
350 <xsl:with-param name='month'>
351 <xsl:call-template name='dt:get-xsd-datetime-month'>
352 <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
355 <xsl:with-param name='day'>
356 <xsl:call-template name='dt:get-xsd-datetime-day'>
357 <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
360 <xsl:with-param name='hour'>
361 <xsl:call-template name='dt:get-xsd-datetime-hour'>
362 <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
365 <xsl:with-param name='minute'>
366 <xsl:call-template name='dt:get-xsd-datetime-minute'>
367 <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
370 <xsl:with-param name='second'>
371 <xsl:call-template name='dt:get-xsd-datetime-second'>
372 <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
375 <xsl:with-param name='time-zone'>
376 <xsl:call-template name='dt:get-xsd-datetime-timezone'>
377 <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
380 <xsl:with-param name='format'>
382 <xsl:when test='contains($format, "%")'>
383 <xsl:text>%</xsl:text>
384 <xsl:value-of select='substring-after($format, "%")'/>
387 <xsl:value-of select='$format'/>
394 <!-- Abbreviated weekday name -->
395 <xsl:when test="$code='a'">
396 <xsl:variable name="day-of-the-week">
397 <xsl:call-template name="dt:calculate-day-of-the-week">
398 <xsl:with-param name="year" select="$year"/>
399 <xsl:with-param name="month" select="$month"/>
400 <xsl:with-param name="day" select="$day"/>
403 <xsl:call-template name="dt:get-day-of-the-week-abbreviation">
404 <xsl:with-param name="day-of-the-week" select="$day-of-the-week"/>
408 <!-- Full weekday name -->
409 <xsl:when test="$code='A'">
410 <xsl:variable name="day-of-the-week">
411 <xsl:call-template name="dt:calculate-day-of-the-week">
412 <xsl:with-param name="year" select="$year"/>
413 <xsl:with-param name="month" select="$month"/>
414 <xsl:with-param name="day" select="$day"/>
417 <xsl:call-template name="dt:get-day-of-the-week-name">
418 <xsl:with-param name="day-of-the-week" select="$day-of-the-week"/>
422 <!-- Abbreviated month name -->
423 <xsl:when test="$code='b'">
424 <xsl:call-template name="dt:get-month-abbreviation">
425 <xsl:with-param name="month" select="$month"/>
429 <!-- Full month name -->
430 <xsl:when test="$code='B'">
431 <xsl:call-template name="dt:get-month-name">
432 <xsl:with-param name="month" select="$month"/>
436 <!-- Date and time representation appropriate for locale -->
437 <xsl:when test="$code='c'">
438 <xsl:text>[not implemented]</xsl:text>
441 <!-- Day of month as decimal number (01 - 31) -->
442 <xsl:when test="$code='d'">
443 <xsl:if test="$day < 10">0</xsl:if>
444 <xsl:value-of select="number($day)"/>
446 <!-- Day of month as decimal number (1 - 31) -->
447 <xsl:when test="$code='e'">
448 <xsl:value-of select="number($day)"/>
451 <!-- Hour in 24-hour format (00 - 23) -->
452 <xsl:when test="$code='H'">
453 <xsl:if test="$hour < 10">0</xsl:if>
454 <xsl:value-of select="number($hour)"/>
457 <!-- Hour in 12-hour format (01 - 12) -->
458 <xsl:when test="$code='I'">
460 <xsl:when test="$hour = 0">12</xsl:when>
461 <xsl:when test="$hour < 10">0<xsl:value-of select="$hour - 0"/></xsl:when>
462 <xsl:when test="$hour < 13"><xsl:value-of select="$hour - 0"/></xsl:when>
463 <xsl:when test="$hour < 22">0<xsl:value-of select="$hour - 12"/></xsl:when>
464 <xsl:otherwise><xsl:value-of select="$hour - 12"/></xsl:otherwise>
467 <!-- Hour in 12-hour format (1 - 12) -->
468 <xsl:when test="$code='i'">
470 <xsl:when test="$hour = 0">12</xsl:when>
471 <xsl:when test="$hour < 10"><xsl:value-of select="$hour - 0"/></xsl:when>
472 <xsl:when test="$hour < 13"><xsl:value-of select="$hour - 0"/></xsl:when>
473 <xsl:when test="$hour < 22"><xsl:value-of select="$hour - 12"/></xsl:when>
474 <xsl:otherwise><xsl:value-of select="$hour - 12"/></xsl:otherwise>
478 <!-- Day of year as decimal number (001 - 366) -->
479 <xsl:when test="$code='j'">
480 <xsl:text>[not implemented]</xsl:text>
483 <!-- Month as decimal number (01 - 12) -->
484 <xsl:when test="$code='m'">
485 <xsl:if test="$month < 10">0</xsl:if>
486 <xsl:value-of select="number($month)"/>
488 <!-- Month as decimal number (1 - 12) -->
489 <xsl:when test="$code='n'">
490 <xsl:value-of select="number($month)"/>
493 <!-- Minute as decimal number (00 - 59) -->
494 <xsl:when test="$code='M'">
495 <xsl:if test="$minute < 10">0</xsl:if>
496 <xsl:value-of select="number($minute)"/>
499 <!-- Current locale's A.M./P.M. indicator for 12-hour clock -->
500 <xsl:when test="$code='p'">
502 <xsl:when test="$hour < 12">am</xsl:when>
503 <xsl:otherwise>pm</xsl:otherwise>
506 <!-- Current locale's A.M./P.M. indicator for 12-hour clock with periods -->
507 <xsl:when test="$code='q'">
509 <xsl:when test="$hour < 12">am</xsl:when>
510 <xsl:otherwise>p.m.</xsl:otherwise>
513 <!-- Current locale's A.M./P.M. indicator for 12-hour clock -->
514 <xsl:when test="$code='P'">
516 <xsl:when test="$hour < 12">AM</xsl:when>
517 <xsl:otherwise>PM</xsl:otherwise>
520 <!-- Current locale's A.M./P.M. indicator for 12-hour clock with periods -->
521 <xsl:when test="$code='Q'">
523 <xsl:when test="$hour < 12">AM</xsl:when>
524 <xsl:otherwise>P.M.</xsl:otherwise>
528 <!-- Second as decimal number (00 - 59) -->
529 <xsl:when test="$code='S'">
530 <xsl:if test="$second < 10">0</xsl:if>
531 <xsl:value-of select="number($second)"/>
534 <!-- Week of year as decimal number, with Sunday as first day of week (00 - 53) -->
535 <xsl:when test="$code='U'">
536 <!-- add 1 to day -->
537 <xsl:call-template name="dt:calculate-week-number">
538 <xsl:with-param name="year" select="$year"/>
539 <xsl:with-param name="month" select="$month"/>
540 <xsl:with-param name="day" select="$day + 1"/>
544 <!-- Weekday as decimal number (0 - 6; Sunday is 0) -->
545 <xsl:when test="$code='w'">
546 <xsl:call-template name="dt:calculate-day-of-the-week">
547 <xsl:with-param name="year" select="$year"/>
548 <xsl:with-param name="month" select="$month"/>
549 <xsl:with-param name="day" select="$day"/>
553 <!-- Week of year as decimal number, with Monday as first day of week (00 - 53) -->
554 <xsl:when test="$code='W'">
555 <xsl:call-template name="dt:calculate-week-number">
556 <xsl:with-param name="year" select="$year"/>
557 <xsl:with-param name="month" select="$month"/>
558 <xsl:with-param name="day" select="$day"/>
562 <!-- Date representation for current locale -->
563 <xsl:when test="$code='x'">
564 <xsl:text>[not implemented]</xsl:text>
567 <!-- Time representation for current locale -->
568 <xsl:when test="$code='X'">
569 <xsl:text>[not implemented]</xsl:text>
572 <!-- Year without century, as decimal number (00 - 99) -->
573 <xsl:when test="$code='y'">
575 <xsl:when test='not(number($year))'>invalid year value</xsl:when>
577 <!-- workaround MSXML bug -->
578 <xsl:when test='number($year) mod 100 = 0'>00</xsl:when>
581 <xsl:number format='01' value='number($year) mod 100'/>
586 <!-- Year with century, as decimal number -->
587 <xsl:when test="$code='Y'">
589 <xsl:when test='not(number($year))'>invalid year value</xsl:when>
590 <xsl:when test='string-length($year) = 2'>
591 <xsl:call-template name='dt:format-two-digit-year'>
592 <xsl:with-param name='year' select='$year'/>
595 <xsl:when test='string-length($year) >= 4'>
596 <xsl:value-of select='$year'/>
598 <xsl:otherwise>invalid year value</xsl:otherwise>
602 <!-- Time-zone name or abbreviation; no characters if time zone is unknown -->
603 <xsl:when test="$code='z'">
604 <xsl:value-of select="$time-zone"/>
607 <!-- Percent sign -->
608 <xsl:when test="$code='%'">
609 <xsl:text>%</xsl:text>
614 <xsl:variable name="remainder" select="substring(substring-after($format, '%'), 2)"/>
616 <xsl:if test="not($xsd-date-time) and $remainder">
617 <xsl:call-template name="dt:format-date-time">
618 <xsl:with-param name="year" select="$year"/>
619 <xsl:with-param name="month" select="$month"/>
620 <xsl:with-param name="day" select="$day"/>
621 <xsl:with-param name="hour" select="$hour"/>
622 <xsl:with-param name="minute" select="$minute"/>
623 <xsl:with-param name="second" select="$second"/>
624 <xsl:with-param name="time-zone" select="$time-zone"/>
625 <xsl:with-param name="format" select="$remainder"/>
631 <doc:template name="dt:calculate-day-of-the-week" xmlns="">
632 <refpurpose>Calculates the day of the week.</refpurpose>
635 <para>Given any Gregorian date, this calculates the day of the week.</para>
649 <para>Month (1 - 12; January = 1)</para>
655 <para>Day of month (1 - 31)</para>
662 <para>Returns the day of the week (0 - 6; Sunday = 0).</para>
667 <xsl:template name="dt:calculate-day-of-the-week">
668 <xsl:param name="year"/>
669 <xsl:param name="month"/>
670 <xsl:param name="day"/>
672 <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
673 <xsl:variable name="y" select="$year - $a"/>
674 <xsl:variable name="m" select="$month + 12 * $a - 2"/>
676 <xsl:value-of select="($day + $y + floor($y div 4) - floor($y div 100) + floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>
680 <doc:template name="dt:calculate-last-day-of-month" xmlns="">
681 <refpurpose>Calculates the number of days for a specified month.</refpurpose>
684 <para>Given any Gregorian month, this calculates the last day of the month.</para>
698 <para>Month (1 - 12; January = 1)</para>
705 <para>Returns the number of days in given month as a decimal number.</para>
709 <xsl:template name="dt:calculate-last-day-of-month">
710 <xsl:param name="year"/>
711 <xsl:param name="month"/>
714 <xsl:when test="$month = 2">
716 <xsl:when test="($year mod 4) = 0 and (($year mod 400) = 0
717 or ($year mod 100) != 0)">29</xsl:when>
718 <xsl:otherwise>28</xsl:otherwise>
721 <xsl:when test="$month < 8">
723 <xsl:when test="$month mod 2 = 0">30</xsl:when>
724 <xsl:otherwise>31</xsl:otherwise>
729 <xsl:when test="$month mod 2 = 1">30</xsl:when>
730 <xsl:otherwise>31</xsl:otherwise>
736 <doc:template name="dt:get-day-of-the-week-name" xmlns="">
737 <refpurpose>Gets the day of the week's full name.</refpurpose>
740 <para>Converts a numeric day of the week value into a string representing the day's full name.</para>
746 <term>day-of-the-week</term>
748 <para>Day of the week (0 - 6; Sunday = 0)</para>
755 <para>Returns a string.</para>
760 <xsl:template name="dt:get-day-of-the-week-name">
761 <xsl:param name="day-of-the-week"/>
764 <xsl:when test="$day-of-the-week = 0">Sunday</xsl:when>
765 <xsl:when test="$day-of-the-week = 1">Monday</xsl:when>
766 <xsl:when test="$day-of-the-week = 2">Tuesday</xsl:when>
767 <xsl:when test="$day-of-the-week = 3">Wednesday</xsl:when>
768 <xsl:when test="$day-of-the-week = 4">Thursday</xsl:when>
769 <xsl:when test="$day-of-the-week = 5">Friday</xsl:when>
770 <xsl:when test="$day-of-the-week = 6">Saturday</xsl:when>
771 <xsl:otherwise>error: <xsl:value-of select="$day-of-the-week"/></xsl:otherwise>
776 <doc:template name="dt:get-day-of-the-week-abbreviation" xmlns="">
777 <refpurpose>Gets the day of the week's abbreviation.</refpurpose>
780 <para>Converts a numeric day of the week value into a string representing the day's abbreviation.</para>
786 <term>day-of-the-week</term>
788 <para>Day of the week (0 - 6; Sunday = 0)</para>
795 <para>Returns a string.</para>
800 <xsl:template name="dt:get-day-of-the-week-abbreviation">
801 <xsl:param name="day-of-the-week"/>
804 <xsl:when test="$day-of-the-week = 0">Sun</xsl:when>
805 <xsl:when test="$day-of-the-week = 1">Mon</xsl:when>
806 <xsl:when test="$day-of-the-week = 2">Tue</xsl:when>
807 <xsl:when test="$day-of-the-week = 3">Wed</xsl:when>
808 <xsl:when test="$day-of-the-week = 4">Thu</xsl:when>
809 <xsl:when test="$day-of-the-week = 5">Fri</xsl:when>
810 <xsl:when test="$day-of-the-week = 6">Sat</xsl:when>
811 <xsl:otherwise>error: <xsl:value-of select="$day-of-the-week"/></xsl:otherwise>
816 <doc:template name="dt:get-month-name" xmlns="">
817 <refpurpose>Gets the month's full name.</refpurpose>
820 <para>Converts a numeric month value into a string representing the month's full name.</para>
828 <para>Month (1 - 12; Januaray = 1)</para>
835 <para>Returns a string.</para>
840 <xsl:template name="dt:get-month-name">
841 <xsl:param name="month"/>
844 <xsl:when test="$month = 1">January</xsl:when>
845 <xsl:when test="$month = 2">February</xsl:when>
846 <xsl:when test="$month = 3">March</xsl:when>
847 <xsl:when test="$month = 4">April</xsl:when>
848 <xsl:when test="$month = 5">May</xsl:when>
849 <xsl:when test="$month = 6">June</xsl:when>
850 <xsl:when test="$month = 7">July</xsl:when>
851 <xsl:when test="$month = 8">August</xsl:when>
852 <xsl:when test="$month = 9">September</xsl:when>
853 <xsl:when test="$month = 10">October</xsl:when>
854 <xsl:when test="$month = 11">November</xsl:when>
855 <xsl:when test="$month = 12">December</xsl:when>
856 <xsl:otherwise>error: <xsl:value-of select="$month"/></xsl:otherwise>
861 <doc:template name="dt:get-month-abbreviation" xmlns="">
862 <refpurpose>Gets the month's abbreviation.</refpurpose>
865 <para>Converts a numeric month value into a string representing the month's abbreviation.</para>
873 <para>Month (1 - 12; Januaray = 1)</para>
880 <para>Returns a string.</para>
885 <xsl:template name="dt:get-month-abbreviation">
886 <xsl:param name="month"/>
889 <xsl:when test="$month = 1">Jan</xsl:when>
890 <xsl:when test="$month = 2">Feb</xsl:when>
891 <xsl:when test="$month = 3">Mar</xsl:when>
892 <xsl:when test="$month = 4">Apr</xsl:when>
893 <xsl:when test="$month = 5">May</xsl:when>
894 <xsl:when test="$month = 6">Jun</xsl:when>
895 <xsl:when test="$month = 7">Jul</xsl:when>
896 <xsl:when test="$month = 8">Aug</xsl:when>
897 <xsl:when test="$month = 9">Sep</xsl:when>
898 <xsl:when test="$month = 10">Oct</xsl:when>
899 <xsl:when test="$month = 11">Nov</xsl:when>
900 <xsl:when test="$month = 12">Dec</xsl:when>
901 <xsl:otherwise>error: <xsl:value-of select="$month"/></xsl:otherwise>
906 <doc:template name="dt:calculate-julian-day" xmlns="">
907 <refpurpose>Calculates the Julian Day for a specified date.</refpurpose>
910 <para>Given any Gregorian date, this calculates the Julian Day.</para>
924 <para>Month (1 - 12; January = 1)</para>
930 <para>Day of month (1 - 31)</para>
937 <para>Returns the Julian Day as a decimal number.</para>
942 <xsl:template name="dt:calculate-julian-day">
943 <xsl:param name="year"/>
944 <xsl:param name="month"/>
945 <xsl:param name="day"/>
947 <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
948 <xsl:variable name="y" select="$year + 4800 - $a"/>
949 <xsl:variable name="m" select="$month + 12 * $a - 3"/>
951 <xsl:value-of select="$day + floor((153 * $m + 2) div 5) + $y * 365 + floor($y div 4) - floor($y div 100) + floor($y div 400) - 32045"/>
955 <doc:template name="dt:format-julian-day" xmlns="">
956 <refpurpose>Returns a string with a formatted date for a specified Julian Day.</refpurpose>
959 <para>Given any Julian Day, this returns a string according to the format specification.</para>
965 <term>julian-day</term>
967 <para>A Julian Day</para>
973 <para>The format specification. See dt:format-date-time for more details.</para>
980 <para>A string.</para>
985 <xsl:template name="dt:format-julian-day">
986 <xsl:param name="julian-day"/>
987 <xsl:param name="format" select="'%Y-%m-%d'"/>
989 <xsl:variable name="a" select="$julian-day + 32044"/>
990 <xsl:variable name="b" select="floor((4 * $a + 3) div 146097)"/>
991 <xsl:variable name="c" select="$a - floor(($b * 146097) div 4)"/>
993 <xsl:variable name="d" select="floor((4 * $c + 3) div 1461)"/>
994 <xsl:variable name="e" select="$c - floor((1461 * $d) div 4)"/>
995 <xsl:variable name="m" select="floor((5 * $e + 2) div 153)"/>
997 <xsl:variable name="day" select="$e - floor((153 * $m + 2) div 5) + 1"/>
998 <xsl:variable name="month" select="$m + 3 - 12 * floor($m div 10)"/>
999 <xsl:variable name="year" select="$b * 100 + $d - 4800 + floor($m div 10)"/>
1001 <xsl:call-template name="dt:format-date-time">
1002 <xsl:with-param name="year" select="$year"/>
1003 <xsl:with-param name="month" select="$month"/>
1004 <xsl:with-param name="day" select="$day"/>
1005 <xsl:with-param name="format" select="$format"/>
1006 </xsl:call-template>
1010 <doc:template name="dt:calculate-week-number" xmlns="">
1011 <refpurpose>Calculates the week number for a specified date.</refpurpose>
1014 <para>Assumes Monday is the first day of the week.</para>
1028 <para>Month (1 - 12; January = 1)</para>
1034 <para>Day of month (1 - 31)</para>
1041 <para>Returns the week number as a decimal number.</para>
1046 <xsl:template name="dt:calculate-week-number">
1047 <xsl:param name="year"/>
1048 <xsl:param name="month"/>
1049 <xsl:param name="day"/>
1051 <xsl:variable name="J">
1052 <xsl:call-template name="dt:calculate-julian-day">
1053 <xsl:with-param name="year" select="$year"/>
1054 <xsl:with-param name="month" select="$month"/>
1055 <xsl:with-param name="day" select="$day"/>
1056 </xsl:call-template>
1059 <xsl:variable name="d4" select="($J + 31741 - ($J mod 7)) mod 146097 mod 36524 mod 1461"/>
1060 <xsl:variable name="L" select="floor($d4 div 1460)"/>
1061 <xsl:variable name="d1" select="(($d4 - $L) mod 365) + $L"/>
1063 <xsl:value-of select="floor($d1 div 7) + 1"/>
1067 <doc:template name="dt:get-month-number" xmlns="">
1068 <refpurpose>Take a month by name and return a number which can be used as input to the templates. </refpurpose>
1079 <para>Month as described either by full name or abbreviation.</para>
1086 <para>Return a month as a decimal number. (Jan = 1)</para>
1090 <xsl:template name='dt:get-month-number'>
1091 <xsl:param name='month'/>
1093 <xsl:variable name='monToUpper'>
1094 <xsl:call-template name='str:to-upper'>
1095 <xsl:with-param name='text' select='$month'/>
1096 </xsl:call-template>
1100 <xsl:when test='starts-with($monToUpper,"JAN")'>
1101 <xsl:value-of select='"1"'/>
1103 <xsl:when test='starts-with($monToUpper,"FEB")'>
1104 <xsl:value-of select='2'/>
1106 <xsl:when test='starts-with($monToUpper,"MAR")'>
1107 <xsl:value-of select='3'/>
1109 <xsl:when test='starts-with($monToUpper,"APR")'>
1110 <xsl:value-of select='4'/>
1112 <xsl:when test='starts-with($monToUpper,"MAY")'>
1113 <xsl:value-of select='5'/>
1115 <xsl:when test='starts-with($monToUpper,"JUN")'>
1116 <xsl:value-of select='6'/>
1118 <xsl:when test='starts-with($monToUpper,"JUL")'>
1119 <xsl:value-of select='7'/>
1121 <xsl:when test='starts-with($monToUpper,"AUG")'>
1122 <xsl:value-of select='8'/>
1124 <xsl:when test='starts-with($monToUpper,"SEP")'>
1125 <xsl:value-of select='9'/>
1127 <xsl:when test='starts-with($monToUpper,"OCT")'>
1128 <xsl:value-of select='10'/>
1130 <xsl:when test='starts-with($monToUpper,"NOV")'>
1131 <xsl:value-of select='11'/>
1133 <xsl:when test='starts-with($monToUpper,"DEC")'>
1134 <xsl:value-of select='"12"'/>
1139 <doc:template name="dt:get-xsd-datetime-year" xmlns="">
1140 <refpurpose>Return year component of XSD DateTime value.</refpurpose>
1143 <para>Extract component of XML Schemas DateTime value.</para>
1149 <term>xsd-date-time</term>
1151 <para>A value in XSD DateTime format.</para>
1158 <para>Returns year component.</para>
1162 <xsl:template name='dt:get-xsd-datetime-year'>
1163 <xsl:param name='xsd-date-time'/>
1166 <xsl:when test='contains($xsd-date-time, "T")'>
1167 <xsl:call-template name='dt:get-xsd-datetime-year'>
1168 <xsl:with-param name='xsd-date-time' select='substring-before($xsd-date-time, "T")'/>
1169 </xsl:call-template>
1172 <!-- Check for time -->
1173 <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'/>
1176 <!-- This is a date -->
1177 <xsl:value-of select='substring-before($xsd-date-time, "-")'/>
1182 <doc:template name="dt:get-xsd-datetime-month" xmlns="">
1183 <refpurpose>Return month component of XSD DateTime value.</refpurpose>
1186 <para>Extract component of XML Schemas DateTime value.</para>
1192 <term>xsd-date-time</term>
1194 <para>A value in XSD DateTime format.</para>
1201 <para>Returns month component.</para>
1205 <xsl:template name='dt:get-xsd-datetime-month'>
1206 <xsl:param name='xsd-date-time'/>
1209 <xsl:when test='contains($xsd-date-time, "T")'>
1210 <xsl:call-template name='dt:get-xsd-datetime-month'>
1211 <xsl:with-param name='xsd-date-time' select='substring-before($xsd-date-time, "T")'/>
1212 </xsl:call-template>
1215 <!-- Check for time -->
1216 <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'/>
1219 <!-- This is a date -->
1220 <xsl:value-of select='substring(substring-after($xsd-date-time, "-"), 1, 2)'/>
1225 <doc:template name="dt:get-xsd-datetime-day" xmlns="">
1226 <refpurpose>Return day component of XSD DateTime value.</refpurpose>
1229 <para>Extract component of XML Schemas DateTime value.</para>
1235 <term>xsd-date-time</term>
1237 <para>A value in XSD DateTime format.</para>
1244 <para>Returns day component.</para>
1248 <xsl:template name='dt:get-xsd-datetime-day'>
1249 <xsl:param name='xsd-date-time'/>
1252 <xsl:when test='contains($xsd-date-time, "T")'>
1253 <xsl:call-template name='dt:get-xsd-datetime-day'>
1254 <xsl:with-param name='xsd-date-time' select='substring-before($xsd-date-time, "T")'/>
1255 </xsl:call-template>
1258 <!-- Check for time -->
1259 <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'/>
1262 <!-- This is a date -->
1263 <xsl:value-of select='substring(substring-after($xsd-date-time, "-"), 4, 2)'/>
1268 <doc:template name="dt:get-xsd-datetime-hour" xmlns="">
1269 <refpurpose>Return hour component of XSD DateTime value.</refpurpose>
1272 <para>Extract component of XML Schemas DateTime value.</para>
1278 <term>xsd-date-time</term>
1280 <para>A value in XSD DateTime format.</para>
1287 <para>Returns hour component.</para>
1291 <xsl:template name='dt:get-xsd-datetime-hour'>
1292 <xsl:param name='xsd-date-time'/>
1295 <xsl:when test='contains($xsd-date-time, "T")'>
1296 <xsl:call-template name='dt:get-xsd-datetime-hour'>
1297 <xsl:with-param name='xsd-date-time' select='substring-after($xsd-date-time, "T")'/>
1298 </xsl:call-template>
1301 <!-- Check for time -->
1302 <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'>
1303 <xsl:value-of select='substring($xsd-date-time, 1, 2)'/>
1307 <!-- This is a date -->
1312 <doc:template name="dt:get-xsd-datetime-minute" xmlns="">
1313 <refpurpose>Return minute component of XSD DateTime value.</refpurpose>
1316 <para>Extract component of XML Schemas DateTime value.</para>
1322 <term>xsd-date-time</term>
1324 <para>A value in XSD DateTime format.</para>
1331 <para>Returns minute component.</para>
1335 <xsl:template name='dt:get-xsd-datetime-minute'>
1336 <xsl:param name='xsd-date-time'/>
1339 <xsl:when test='contains($xsd-date-time, "T")'>
1340 <xsl:call-template name='dt:get-xsd-datetime-minute'>
1341 <xsl:with-param name='xsd-date-time' select='substring-after($xsd-date-time, "T")'/>
1342 </xsl:call-template>
1345 <!-- Check for time -->
1346 <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'>
1347 <xsl:value-of select='substring($xsd-date-time, 4, 2)'/>
1351 <!-- This is a date -->
1356 <doc:template name="dt:get-xsd-datetime-second" xmlns="">
1357 <refpurpose>Return second component of XSD DateTime value.</refpurpose>
1360 <para>Extract component of XML Schemas DateTime value.</para>
1366 <term>xsd-date-time</term>
1368 <para>A value in XSD DateTime format.</para>
1375 <para>Returns second component.</para>
1379 <xsl:template name='dt:get-xsd-datetime-second'>
1380 <xsl:param name='xsd-date-time'/>
1383 <xsl:when test='contains($xsd-date-time, "T")'>
1384 <xsl:call-template name='dt:get-xsd-datetime-second'>
1385 <xsl:with-param name='xsd-date-time' select='substring-after($xsd-date-time, "T")'/>
1386 </xsl:call-template>
1389 <!-- Check for time -->
1390 <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'>
1391 <xsl:variable name='part' select='substring($xsd-date-time, 7)'/>
1393 <xsl:when test='contains($part, "Z")'>
1394 <xsl:value-of select='substring-before($part, "Z")'/>
1396 <xsl:when test='contains($part, "+")'>
1397 <xsl:value-of select='substring-before($part, "+")'/>
1399 <xsl:when test='contains($part, "-")'>
1400 <xsl:value-of select='substring-before($part, "-")'/>
1403 <xsl:value-of select='$part'/>
1409 <!-- This is a date -->
1414 <doc:template name="dt:get-xsd-datetime-timezone" xmlns="">
1415 <refpurpose>Return timezone component of XSD DateTime value.</refpurpose>
1418 <para>Extract component of XML Schemas DateTime value.</para>
1424 <term>xsd-date-time</term>
1426 <para>A value in XSD DateTime format.</para>
1433 <para>Returns timezone component.</para>
1437 <xsl:template name='dt:get-xsd-datetime-timezone'>
1438 <xsl:param name='xsd-date-time'/>
1441 <xsl:when test='contains($xsd-date-time, "Z")'>Z</xsl:when>
1442 <xsl:when test='contains($xsd-date-time, "T")'>
1443 <xsl:call-template name='dt:get-xsd-datetime-timezone'>
1444 <xsl:with-param name='xsd-date-time' select='substring-after($xsd-date-time, "T")'/>
1445 </xsl:call-template>
1448 <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'>
1449 <!-- This is a time -->
1451 <xsl:when test='contains($xsd-date-time, "+")'>
1452 <xsl:text>+</xsl:text>
1453 <xsl:value-of select='substring-after($xsd-date-time, "+")'/>
1455 <xsl:when test='contains($xsd-date-time, "-")'>
1456 <xsl:text>-</xsl:text>
1457 <xsl:value-of select='substring-after($xsd-date-time, "-")'/>
1462 <!-- This is a date -->
1463 <xsl:value-of select='substring(substring-after($xsd-date-time, "-"), 6)'/>
1468 <doc:template name="dt:format-two-digit-year" xmlns="">
1469 <refpurpose>Return two digit year as four digit year value.</refpurpose>
1472 <para>Prepend century to two digit year value.</para>
1473 <para>Century value is calculated according to suggested solutions in RFC2626 (section 5).</para>
1474 <para>Fixed window solution: 20 is prepended to year if the year is less than 50, otherwise 19 is prepended to year.</para>
1475 <para>Sliding window solution: The year is considered in the future if the year is less than the current 2 digit year plus 'n' years (where 'n' is a param), otherwise it is considered in the past.</para>
1483 <para>A year value in 2 digit format.</para>
1489 <para>RFC2626 suggested solution ('fixed' or 'sliding'). Default is 'fixed'.</para>
1495 <para>No. of years. Used in sliding windows solution.</para>
1502 <para>Returns four digit year value.</para>
1506 <xsl:template name="dt:format-two-digit-year">
1507 <xsl:param name="year" />
1508 <xsl:param name="method" select="'fixed'"/>
1511 <xsl:when test="string-length($year) != 2">invalid year value</xsl:when>
1512 <xsl:when test="$method = 'fixed'">
1514 <xsl:when test="$year < 50">20</xsl:when>
1515 <xsl:otherwise>19</xsl:otherwise>
1517 <xsl:value-of select="$year" />
1519 <xsl:when test="$method = 'window'">not yet implemented</xsl:when>
1520 <xsl:otherwise>invalid method</xsl:otherwise>