Comment detail

除算・余剰を使わずに閏年 (Nested Flatten)

This comment is reply for 5368 matyr: 組み込み「メソッド」は使ってもいいのかな...(除算・余剰を使わずに閏年). Go to thread root.

その手がありましたか!って、もはや悪のりでしかありませんね(^_^;)。

1
2
3
4
5
6
7
8
| 閏年か? |

閏年か? := [:int | int asYear daysInYear = 366].

閏年か? value: 1900.   "=> false "
閏年か? value: 2000.   "=> true "
閏年か? value: 2008.   "=> true "
閏年か? value: 2100.   "=> false "
そうか、その手が。。。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:fn="http://www.w3.org/2005/xpath-functions"
  >

  <xsl:output method="text" />

  <xsl:template match="/" >
    <xsl:for-each select="1900 to 2100">
      <xsl:variable name="thisYear" as="xs:date"
        select="xs:date(fn:concat(xs:string(.), '-01-01'))" />
      <xsl:variable name="nextYear" as="xs:date"
        select="xs:date(fn:concat(xs:string(1+.), '-01-01'))" />
      <xsl:if test="fn:days-from-duration($nextYear - $thisYear)=366">
        <xsl:value-of select="." />
        <xsl:text> 年は閏年♪&#xA;</xsl:text>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

Index

Feed

Other

Link

Pathtraq

loading...