[go: up one dir, main page]

Menu

[b88bd8]: / montage.pas  Maximize  Restore  History

Download this file

248 lines (196 with data), 6.5 kB

  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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
{ $Id$
Copyright (C) 1991-2001 Peter Mandrella
Copyright (C) 2000-2002 OpenXP team (www.openxp.de)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
}
UNIT montage;
{$I xpdefine.inc }
interface
uses
sysutils,
typeform,
xpglobal;
var //Februar hat variable Zahl von Tagen
monat : Array[1..12] of record
tag : String[9];
zahl: Byte;
end =
((tag: 'Januar'; zahl: 31), (tag: 'Februar'; zahl: 28),
(tag: 'Maerz'; zahl: 31), (tag: 'April'; zahl: 30),
(tag: 'Mai'; zahl: 31), (tag: 'Juni'; zahl: 30),
(tag: 'Juli'; zahl: 31), (tag: 'August'; zahl: 31),
(tag: 'September';zahl: 30), (tag: 'Oktober'; zahl: 31),
(tag: 'November'; zahl: 30), (tag: 'Dezember'; zahl: 31));
type fdate = packed record
t,m : byte;
j : smallword;
end;
function ddow(dd:fdate):byte;
function dow(d:string):byte; { Wochentag 1..7 }
function dowst(d:string):string; { Wochentag Mo..So }
procedure schalt(jahr:integer); { Schaltjahr-Korrektur }
procedure incd(var d);
procedure decd(var d);
function prevd(d:datetimest):datetimest;
function nextd(d:datetimest):datetimest;
function sommer(const d,z:datetimest):boolean; { Sommerzeit? }
implementation
procedure schalt(jahr:integer);
begin
if IsLeapYear(jahr) then monat[2].zahl:=29
else monat[2].zahl:=28;
end;
procedure incd(var d);
begin
with fdate(d) do begin
if m>12 then m:=12
else if m<1 then m:=1;
schalt(j);
inc(t);
if t>monat[m].zahl then begin
t:=1; inc(m);
if m>12 then begin
m:=1; inc(j);
end;
end;
end;
end;
procedure decd(var d);
begin
with fdate(d) do begin
if m>12 then m:=12
else if m<1 then m:=1;
schalt(j);
dec(t);
if t=0 then begin
dec(m);
if m=0 then begin
m:=12;
dec(j);
end;
t:=monat[m].zahl;
end;
end;
end;
function prevd(d:datetimest):datetimest;
var dat : fdate;
res : integer;
begin
with dat do begin
val(LeftStr(d,2),t,res);
val(copy(d,4,2),m,res);
val(RightStr(d,4),j,res);
decd(dat);
prevd:=formi(t,2)+'.'+formi(m,2)+'.'+formi(j,4);
end;
end;
function nextd(d:datetimest):datetimest;
var dat : fdate;
res : integer;
begin
with dat do begin
val(LeftStr(d,2),t,res);
val(copy(d,4,2),m,res);
val(RightStr(d,4),j,res);
incd(dat);
nextd:=formi(t,2)+'.'+formi(m,2)+'.'+formi(j,4);
end;
end;
{ d ist im DateTime-Formst (s. TYPEFORM) }
{ 1=Mo, 2=Di, ..., 7=So }
{ Algorithmus zur Wochentagberechnung nach DOS 11/87, S. 86 }
function ddow(dd:fdate):byte;
var nt : integer;
begin
with dd do
if (t>0)and(m>0)and(j>0) then { MK 01/00 falls Record leer, wird 1 (Mo) zurckgegeben }
begin
if m<3 then begin
m:=m+12; dec(j);
end;
nt:=(((t+(13*m+3)div 5+(5*j)shr 2-(j div 100)+j div 400)+1)mod 7);
if nt=0 then ddow:=7
else ddow:=nt;
end else
ddow := 1;
end;
function dow(d:string):byte;
var dd : fdate;
res : integer;
begin
val(copy(d,1,2),dd.t,res);
val(copy(d,4,2),dd.m,res);
val(copy(d,7,4),dd.j,res);
dow:=ddow(dd);
end;
function dowst(d:string):string; { Wochentag Mo..So }
begin
dowst:=copy('MoDiMiDoFrSaSo',dow(d)*2-1,2);
end;
{ letzter Sonntag im Maerz - letzter Sonntag im September }
function sommer(const d,z:datetimest):boolean;
var t,m : byte;
res,d1 : integer;
begin
val(copy(d,1,2),t,res);
val(copy(d,4,2),m,res);
d1:=dow('01'+mid(d,3)); { 1. Tag des aktuellen Monats }
if d1>4 then d1:=-7+d1;
if ((m>3) and (m<10)) or { April bis September }
((m=3) and (t>29-d1)) or { Letzter Sonntag im Maerz schon vorbei? }
((m=3) and (t=29-d1) and { Letzter Sonntag im Maerz nach 01:59 Uhr? }
(ival(copy(z,1,2)+copy(z,4,2)) > 159)) or
((m=10) and (t<29-d1)) or { Letzter Sonntag im Oktober noch nicht da? }
((m=10) and (t=29-d1) and { Letzter Sonntag im Oktober vor 03:00 Uhr? }
(ival(copy(z,1,2)+copy(z,4,2)) < 300))
then sommer:=true else sommer:=false;
end;
{
$Log: montage.pas,v $
Revision 1.18 2003/08/28 00:16:59 mk
- SchaltJ() -> IsLeapYear()
Revision 1.17 2002/12/21 05:37:51 dodi
- removed questionable references to Word type
Revision 1.16 2002/12/13 11:51:58 cl
- fixed Range Check Error
Revision 1.15 2002/12/12 11:58:41 dodi
- set $WRITEABLECONT OFF
Revision 1.14 2002/12/04 16:57:00 dodi
- updated uses, comments and todos
Revision 1.13 2002/07/25 20:43:52 ma
- updated copyright notices
Revision 1.12 2002/01/14 11:40:56 cl
- after-merge compile fixes
Revision 1.11 2002/01/13 15:07:23 mk
- Big 3.40 Update Part I
Revision 1.10 2001/09/10 15:58:01 ml
- Kylix-compatibility (xpdefines written small)
- removed div. hints and warnings
Revision 1.9 2001/09/08 16:29:30 mk
- use FirstChar/LastChar/DeleteFirstChar/DeleteLastChar when possible
- some AnsiString fixes
Revision 1.8 2001/03/13 19:24:56 ma
- added GPL headers, PLEASE CHECK!
- removed unnecessary comments
Revision 1.7 2000/10/17 10:13:23 mk
- Unit Sysutils hinzugefuegt
Revision 1.6 2000/10/17 10:05:42 mk
- Left->LeftStr, Right->RightStr
Revision 1.5 2000/04/30 15:54:21 mk
- unbenutze globale Variable adow entfernt
Revision 1.4 2000/04/04 10:33:56 mk
- Compilierbar mit Virtual Pascal 2.0
Revision 1.3 2000/02/15 20:43:36 mk
MK: Aktualisierung auf Stand 15.02.2000
}
end.