<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>blog.nicolas.pawlak.fr &#187; PHP</title>
	<atom:link href="http://blog.nicolas.pawlak.fr/categories/programmation/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nicolas.pawlak.fr</link>
	<description>Tux ne sait pas voler, c&#039;est normal : ce n&#039;est pas un pingouin...</description>
	<lastBuildDate>Sun, 31 Jul 2011 14:56:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Déterminer si une année est bissextile ou non</title>
		<link>http://blog.nicolas.pawlak.fr/2010/01/19/determiner-si-une-annee-est-bissextile-ou-non/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/01/19/determiner-si-une-annee-est-bissextile-ou-non/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 13:00:22 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[année]]></category>
		<category><![CDATA[bissextile]]></category>
		<category><![CDATA[calendrier]]></category>
		<category><![CDATA[divisible]]></category>
		<category><![CDATA[grégorien]]></category>
		<category><![CDATA[julien]]></category>
		<category><![CDATA[modulo]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=465</guid>
		<description><![CDATA[&#171;&#160;Une année bissextile est une année divisible par 4. Une année est bissextile une fois sur 4.&#160;&#187; Ces deux affirmations sont bien ancrées dans la croyance populaire. Moi aussi, il y a peu, j&#8217;y croyais. Pourtant&#8230; tout ceci est totalement faux. Le calendrier grégorien, en vigueur en France depuis 1532, indique qu&#8217;une année bissextile doit [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p></p>
<p align="center">&laquo;&nbsp;Une année bissextile est une année divisible par 4. Une année est bissextile une fois sur 4.&nbsp;&raquo;</p>
</blockquote>
<p>Ces deux affirmations sont bien ancrées dans la croyance populaire. Moi aussi, il y a peu, j&#8217;y croyais.</p>
<p>Pourtant&#8230; tout ceci est totalement <strong>faux</strong>. Le <a href="http://fr.wikipedia.org/wiki/Calendrier_gr%C3%A9gorien">calendrier grégorien</a>, en vigueur en France depuis 1532, indique qu&#8217;une année bissextile doit répondre à l&#8217;une de ces deux règles :</p>
<p>• Divisible par 400<br />
• Divisible par 4 et non divisible par 100</p>
<p>Si vous faites le calcul, vous vous apercevrez que <em>quasiment</em> chaque année bissextile obéit à l&#8217;une de ces deux règles. Oui, <em>quasiment</em> : il y a effectivement des années divisibles par 4 qui n&#8217;obéissent à aucune de ces deux règles. Essayez avec 2100 par exemple : cette année est non divisible par 400, divisible par 4&#8230; mais divisible par 100. Il s&#8217;agit bel et bien d&#8217;une année non bissextile, alors que 2096 et 2104 seront des années bissextiles.</p>
<p>Évidemment, ça ne concerne que peu d&#8217;années : il y a en fait 97 années bissextiles en 4 siècles alors que la croyance populaire en compte 100. Mais dans certains domaines comme la généalogie, déterminer avec exactitude si une année est bissextile ou non peut avoir son importance.</p>
<p>Voici donc deux bouts de code en ASP et en PHP vous permettant de déterminer à coup sûr si une année est bissextile.</p>
<p><strong>ASP :</strong></p>
<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">function</span> EstBissextile<span style="color: #006600; font-weight:bold;">&#40;</span>annee<span style="color: #006600; font-weight:bold;">&#41;</span>
    <span style="color: #990099; font-weight: bold;">if</span> annee mod <span style="color: #800000;">4</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #800000;">0</span> <span style="color: #0000ff; font-weight: bold;">and</span> annee mod <span style="color: #800000;">100</span> <span style="color: #006600; font-weight: bold;">&lt;&gt;</span> <span style="color: #800000;">0</span> <span style="color: #0000ff; font-weight: bold;">or</span> annee mod <span style="color: #800000;">400</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #800000;">0</span> <span style="color: #990099; font-weight: bold;">then</span>
        EstBissextile <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">true</span>
    <span style="color: #990099; font-weight: bold;">else</span>
        EstBissextile <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">false</span>
    <span style="color: #990099; font-weight: bold;">end</span> <span style="color: #990099; font-weight: bold;">if</span>
<span style="color: #990099; font-weight: bold;">end</span> <span style="color: #0000ff; font-weight: bold;">function</span></pre></div></div>
<p><strong>PHP :</strong></p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> EstBissextile<span style="color: #009900;">&#40;</span><span style="color: #000088;">$annee</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$annee</span><span style="color: #339933;">%</span><span style="color:#800080;">4</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> and <span style="color: #000088;">$annee</span><span style="color: #339933;">%</span><span style="color:#800080;">100</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span> or <span style="color: #000088;">$annee</span><span style="color: #339933;">%</span><span style="color:#800080;">400</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$bissextile</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$bissextile</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$bissextile</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>
<p>Pour plus d&#8217;informations sur les années bissextiles, je vous recommande vivement la lecture de <a href="http://fr.wikipedia.org/wiki/Ann%C3%A9e_Bissextile">l&#8217;article Wikipédia à ce sujet</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/01/19/determiner-si-une-annee-est-bissextile-ou-non/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

