0

For an exampple i want to test if the time (customized variable here) is between 1345:59 - 1400:00 Hrs I am not sure if this is the right way of doing this.

Is there a way i can apply a range for the test condition. Like its true if the current time is between this range otherwise not.

Please let me know if there is any functionality in XSLT 1.0

<xsl:when test="(($curHour = '13' and $curMin &gt;= '45' and $curMin &lt;= '59' ) or ($curHour = '14' and $curMin &gt;= '00' and $curMin &lt;= '30' ))">

Thanks!

Cris3k
  • 30
  • 7
  • Could you show us **exactly** what the given **time** looks like? – michael.hor257k Feb 19 '15 at 15:11
  • GIven time is actually system current time broken into 24hrs, 60min and 60sec. What is the difference between 'or' and 'and' condition in XSLT? – Cris3k Feb 19 '15 at 15:27
  • "*GIven time is actually system current time broken into 24hrs, 60min and 60sec.*" Doesn't really answer my question. -- "*What is the difference between 'or' and 'and' condition in XSLT?*" Uhm, the same as it is in any other language? And in logic in general? – michael.hor257k Feb 19 '15 at 15:30

2 Answers2

0

If what you're given is already broken into hour and minute, you could do:

<xsl:variable name="minutes" select="60 * $curHour + $curMin" />
<xsl:choose>
    <xsl:when test="826 &lt;= $minutes and $minutes &lt; 840">
...

This returns true when the time given by the two variables is between 13:46 (inclusive) and 14:00 (exclusive).


Edit:

If not, then you could streamline the process by calculating the $minutes variable directly from the $curTime parameter as:

<xsl:variable name="minutes" select="60 * substring($curTime,12,2) + substring($curTime,15,2)" />

(based on what you showed in the comments).

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
0

The easiest way would be to treat the whole HHmmss time value as a single number, e.g.

<xsl:variable name="timeNum" select="number(concat(substring($curTime, 12, 2),
         substring($curTime, 15, 2), substring($curTime, 18, 2))" />

(offsets taken from your comment, which are consistent with an ISO8601 timestamp format YYYY-MM-DDTHH:mm:ssZ). This number can then be directly compared with the target times

<xsl:when test="$timeNum &gt; 134559 and $timeNum &lt;= 140000">
Ian Roberts
  • 120,891
  • 16
  • 170
  • 183