<?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
    <title>Posteet: benoitbalon: quantieme</title> 
    <link>http://www.posteet.com/</link> 
    <description>Recent posteets posted to Posteet</description>
    <ttl>60</ttl>

    
    <item>
        <title>Quantième jour</title>
        <link>http://www.posteet.com/view/797</link>
        <description>
        <![CDATA[<pre>#!/bin/sh

usage=&quot;Usage : $0 -q `date +'%j'` [-y `date +'%Y'`]&quot;

# gestion de la ligne de commande
if test &quot;$#&quot; -eq 2
then
	if test &quot;$1&quot; != &quot;-q&quot;
	then
		echo $usage
		exit 1
	fi
elif test &quot;$#&quot; -eq 4
then
	if test &quot;$1&quot; != &quot;-q&quot;
	then
		echo $usage
		exit 1
	fi
	if test &quot;$3&quot; != &quot;-y&quot;
	then
		echo $usage
		exit 1
	fi
else
	echo $usage
	exit 1
fi

qte=$2

if test &quot;$4&quot; != &quot;&quot;
then
	annee_act=$4
	val_y=`expr $annee_act + 1 2&gt;&gt; /dev/null`
	if test &quot;$?&quot; != &quot;0&quot;
	then
		echo $usage
		exit 1
	fi
fi

# verification des nombres
val_q=`expr $qte + 1 2&gt;&gt; /dev/null`
if test &quot;$?&quot; != &quot;0&quot;
then
	echo $usage
	exit 1
fi

# depassements de valeurs
if test &quot;$qte&quot; -gt 366
then
	echo $usage
	exit 1
fi

if test &quot;$qte&quot; -lt 1
then
	echo $usage
	exit 1
fi

# comparaison avec le quantieme actuel
if test &quot;$4&quot; = &quot;&quot;
then
	qte_act=`date +'%j'`
	annee_act=`date +'%Y'`

	if test &quot;$qte_act&quot; -gt &quot;$qte&quot;
	then
		continue
	elif test &quot;$qte_act&quot; -lt &quot;$qte&quot;
	then
		# la date recherchee est dans l'annee passee
		annee_act=`expr $annee_act - 1`
	else
		# la date recherchee est celle d'aujourd'hui
		echo `date +'%Y-%m-%d'`
		exit 0
	fi
fi


bis=`expr $annee_act % 4`
if test &quot;$bis&quot; -gt 0
then
	fin_janvier=31
	fin_fevrier=`expr 31 + 28`
	fin_mars=`expr 31 + 28 + 31`
	fin_avril=`expr 31 + 28 + 31 + 30`
	fin_mai=`expr 31 + 28 + 31 + 30 + 31`
	fin_juin=`expr 31 + 28 + 31 + 30 + 31 + 30`
	fin_juillet=`expr 31 + 28 + 31 + 30 + 31 + 30 + 31`
	fin_aout=`expr 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31`
	fin_septembre=`expr 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30`
	fin_octobre=`expr 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31`
	fin_novembre=`expr 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30`
	#fin_decembre=`expr 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31`
else
	fin_janvier=31
	fin_fevrier=`expr 31 + 29`
	fin_mars=`expr 31 + 29 + 31`
	fin_avril=`expr 31 + 29 + 31 + 30`
	fin_mai=`expr 31 + 29 + 31 + 30 + 31`
	fin_juin=`expr 31 + 29 + 31 + 30 + 31 + 30`
	fin_juillet=`expr 31 + 29 + 31 + 30 + 31 + 30 + 31`
	fin_aout=`expr 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31`
	fin_septembre=`expr 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30`
	fin_octobre=`expr 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31`
	fin_novembre=`expr 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30`
	#fin_decembre=`expr 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31`
fi

# annee non bissextile
if test &quot;$qte&quot; -eq 366 &amp;&amp; test &quot;$bis&quot; -gt 0
then
	exit 1
fi

# detection de l'annee bissextile
if test &quot;$qte&quot; -le &quot;$fin_janvier&quot;
then
	mois=&quot;01&quot;
	jour=`expr $qte + 0`
elif test &quot;$qte&quot; -le &quot;$fin_fevrier&quot;
then
	mois=&quot;02&quot;
	jour=`expr $qte - 31`
elif test &quot;$qte&quot; -le &quot;$fin_mars&quot;
then
	mois=&quot;03&quot;
	if test &quot;$bis&quot; -gt 0
	then
		jour=&quot;`expr $qte - 31 - 28`&quot;
	else
		jour=&quot;`expr $qte - 31 - 29`&quot;
	fi
elif test &quot;$qte&quot; -le &quot;$fin_avril&quot;
then
	mois=&quot;04&quot;
	if test &quot;$bis&quot; -gt 0
	then
		jour=&quot;`expr $qte - 31 - 28 - 31`&quot;
	else
		jour=&quot;`expr $qte - 31 - 29 - 31`&quot;
	fi
elif test &quot;$qte&quot; -le &quot;$fin_mai&quot;
then
	mois=&quot;05&quot;
	if test &quot;$bis&quot; -gt 0
	then
		jour=&quot;`expr $qte - 31 - 28 - 31 - 30`&quot;
	else
		jour=&quot;`expr $qte - 31 - 29 - 31 - 30`&quot;
	fi
elif test &quot;$qte&quot; -le &quot;$fin_juin&quot;
then
	mois=&quot;06&quot;
	if test &quot;$bis&quot; -gt 0
	then
		jour=&quot;`expr $qte - 31 - 28 - 31 - 30 - 31`&quot;
	else
		jour=&quot;`expr $qte - 31 - 29 - 31 - 30 - 31`&quot;
	fi
elif test &quot;$qte&quot; -le &quot;$fin_juillet&quot;
then
	mois=&quot;07&quot;
	if test &quot;$bis&quot; -gt 0
	then
		jour=&quot;`expr $qte - 31 - 28 - 31 - 30 - 31 - 30`&quot;
	else
		jour=&quot;`expr $qte - 31 - 29 - 31 - 30 - 31 - 30`&quot;
	fi
elif test &quot;$qte&quot; -le &quot;$fin_aout&quot;
then
	mois=&quot;08&quot;
	if test &quot;$bis&quot; -gt 0
	then
		jour=&quot;`expr $qte - 31 - 28 - 31 - 30 - 31 - 30 - 31`&quot;
	else
		jour=&quot;`expr $qte - 31 - 29 - 31 - 30 - 31 - 30 - 31`&quot;
	fi
elif test &quot;$qte&quot; -le &quot;$fin_septembre&quot;
then
	mois=&quot;09&quot;
	if test &quot;$bis&quot; -gt 0
	then
		jour=&quot;`expr $qte - 31 - 28 - 31 - 30 - 31 - 30 - 31 - 31`&quot;
	else
		jour=&quot;`expr $qte - 31 - 29 - 31 - 30 - 31 - 30 - 31 - 31`&quot;
	fi
elif test &quot;$qte&quot; -le &quot;$fin_octobre&quot;
then
	mois=&quot;10&quot;
	if test &quot;$bis&quot; -gt 0
	then
		jour=&quot;`expr $qte - 31 - 28 - 31 - 30 - 31 - 30 - 31 - 31 - 30`&quot;
	else
		jour=&quot;`expr $qte - 31 - 29 - 31 - 30 - 31 - 30 - 31 - 31 - 30`&quot;
	fi
elif test &quot;$qte&quot; -le &quot;$fin_novembre&quot;
then
	mois=&quot;11&quot;
	if test &quot;$bis&quot; -gt 0
	then
		jour=&quot;`expr $qte - 31 - 28 - 31 - 30 - 31 - 30 - 31 - 31 - 30 - 31`&quot;
	else
		jour=&quot;`expr $qte - 31 - 29 - 31 - 30 - 31 - 30 - 31 - 31 - 30 - 31`&quot;
	fi
else
	mois=&quot;12&quot;
	if test &quot;$bis&quot; -gt 0
	then
		jour=&quot;`expr $qte - 31 - 28 - 31 - 30 - 31 - 30 - 31 - 31 - 30 - 31 - 30`&quot;
	else
		jour=&quot;`expr $qte - 31 - 29 - 31 - 30 - 31 - 30 - 31 - 31 - 30 - 31 - 30`&quot;
	fi
fi

# affichage de la date trouvee
if test &quot;$jour&quot; -lt 10
then
	echo &quot;${annee_act}-${mois}-0${jour}&quot;
else
	echo &quot;${annee_act}-${mois}-${jour}&quot;
fi</pre> <a href="http://www.posteet.com/tags/bash">[bash]</a>  <a href="http://www.posteet.com/tags/date">[date]</a>  <a href="http://www.posteet.com/tags/jour">[jour]</a>  <a href="http://www.posteet.com/tags/numero jour">[numero jour]</a>  <a href="http://www.posteet.com/tags/quantieme">[quantieme]</a>  <a href="http://www.posteet.com/tags/quantieme jour">[quantieme jour]</a>  <a href="http://www.posteet.com/tags/shell">[shell]</a> ]]>        </description>
        <dc:creator>benoitbalon</dc:creator>
        <pubDate>Thu, 28 Feb 2008 12:43:59 +0000</pubDate>

            <category>bash</category>
            <category>date</category>
            <category>jour</category>
            <category>numero jour</category>
            <category>quantieme</category>
            <category>quantieme jour</category>
            <category>shell</category>
    
    </item>


</channel>
</rss>
