1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
unit u_Paques;
interface
type
t_Date = record
s, j, m, a: word;
end;
{ s = jour de la semaine = 1..7
j = jour du mois = 1..31
m = mois = 1..12
a = année = 1900..2199 }
function f_Paques(a: word): t_Date;
function f_RelativePaques(a: word; d: integer): t_Date;
function f_Chaine(d: t_Date): string;
implementation
const
DIMANCHE = 1;
LUNDI = 2;
MARDI = 3;
MERCREDI = 4;
JEUDI = 5;
VENDREDI = 6;
SAMEDI = 7;
NOMSDESJOURS: array[DIMANCHE..SAMEDI]of string = ('dimanche', 'lundi', 'mardi', 'mercredi',
'jeudi', 'vendredi', 'samedi');
JANVIER = 1;
FEVRIER = 2;
MARS = 3;
AVRIL = 4;
MAI = 5;
JUIN = 6;
JUILLET = 7;
AOUT = 8;
SEPTEMBRE = 9;
OCTOBRE = 10;
NOVEMBRE = 11;
DECEMBRE = 12;
NOMSDESMOIS: array[JANVIER..DECEMBRE]of string = ('janvier', 'février', 'mars', 'avril', 'mai',
'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre');
PAQUES: array[0..299]of word = (
{ Date du dimanche de Pâques de 1900 à 2199 }
46,38,30,43,34,54,46,31,50,42,
27,47,38,23,43,35,54,39,31,51,
35,27,47,32,51,43,35,48,39,31,
51,36,27,47,32,52,43,28,48,40,
24,44,36,56,40,32,52,37,28,48,
40,25,44,36,49,41,32,52,37,29,
48,33,53,45,29,49,41,26,45,37,
29,42,33,53,45,30,49,41,26,46,
37,50,42,34,53,38,30,50,34,26,
46,31,50,42,34,47,38,30,43,35,
54,46,31,51,42,27,47,39,23,43,
35,55,39,31,51,36,27,47,32,52,
43,35,48,40,31,51,36,28,47,32,
52,44,28,48,40,25,44,36,56,41,
32,52,37,29,48,40,25,45,36,49,
41,33,52,37,29,49,33,53,45,30,
49,41,26,46,37,29,42,34,53,45,
30,50,41,26,46,38,50,42,34,54,
38,30,50,35,26,46,31,51,42,34,
47,39,30,43,35,55,46,31,51,43,
28,48,40,25,44,36,49,41,32,52,
37,29,48,33,53,45,29,49,41,26,
45,37,29,42,33,53,45,30,49,41,
26,46,37,50,42,34,53,38,30,50,
34,26,46,31,50,42,34,47,38,30,
43,35,54,46,31,51,42,27,47,39,
23,43,35,55,39,31,51,36,27,47,
32,52,43,35,48,40,31,51,36,28,
47,32,52,44,28,48,40,25,44,36,
56,41,32,52,37,29,48,40,25,45);
function f_Paques(a: word): t_Date;
{ Fonction qui renvoie la date de Pâques, pour une année comprise entre 1900 et 2199. La date est
extraite d'une table. }
begin
if a < 1900 then a := 1900;
if a > 2199 then a := 2199;
result.s := DIMANCHE;
if PAQUES[a-1900] < 32 then
begin
result.j := PAQUES[a-1900];
result.m := MARS;
end else
begin
result.j := PAQUES[a-1900] - 31;
result.m := AVRIL;
end;
result.a := a;
end;
{const
N: array[1..12]of word = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);}
type
t_NombreJours = array[boolean, 1..12]of word;
const
N: t_NombreJours = (
(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));
function Bissext(a: word): boolean;
{ Fonction pour savoir si une année est bissextile. }
begin
result := ((a mod 4=0) and not((a mod 100=0) and not(a mod 400=0)));
end;
function f_RelativePaques(a: word; d: integer): t_Date;
{ Calcule une date relative à la date de Pâques, pour une année comprise entre 1900 et 2199. Le
paramètre d est la différence de jours. }
var
p: t_Date;
vs, vj, vm, va: word;
{vn: array[1..12]of word;}
b: boolean;
i: integer;
begin
if a < 1900 then a := 1900;
if a > 2199 then a := 2199;
p := f_Paques(a);
vs := p.s;
vj := p.j;
vm := p.m;
va := p.a;
{for i := 1 to 12 do
vn[i] := N[i];
if Bissext(a) then
Inc(vn[FEVRIER]);}
b := Bissext(a);
if d < 0 then i := -1 else i := +1;
while Abs(d) > 0 do
begin
Dec(d, i);
Inc(vs, i);
if vs = 0 then
vs := SAMEDI;
if vs = 8 then
vs := DIMANCHE;
Inc(vj, i);
if vj = 0 then
begin
Dec(vm);
if vm = 0 then
begin
Dec(va);
vm := DECEMBRE;
end;
{vj := vn[vm];}
vj := N[b, vm];
end;
{if vj > vn[vm] then}
if vj > N[b, vm] then
begin
Inc(vm);
if vm = 13 then
begin
Inc(va);
vm := JANVIER;
end;
vj := 1;
end;
end;
result.s := vs;
result.j := vj;
result.m := vm;
result.a := va;
end;
function IntToStr(i: word): string;
begin
Str(i, result);
end;
function f_Chaine(d: t_Date): string;
begin
result := NOMSDESJOURS[d.s] + ' ' + IntToStr(d.j) + ' ' + NOMSDESMOIS[d.m] + ' ' + IntToStr(d.a);
end;
end. |
Partager