-
Notifications
You must be signed in to change notification settings - Fork 0
/
TOD.PAS
117 lines (112 loc) · 2.9 KB
/
TOD.PAS
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
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2022
@website(https://www.gladir.com/cpm86-0)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program TOD;
Uses Crt,DOS;
Function PadZeroLeft(Value:Integer;Space:Byte):String;
Var
S:String;
Begin
Str(Value,S);
While Length(S)<Space do S:='0'+S;
PadZeroLeft:=S;
End;
Var
Pos:(PMonth,PDay,PYear,PHour,PMin,PSec);
Year,Month,Day,DayOfMonth,Hour,Minute,Second,CentSec,Err:Word;
I,Y:Byte;
S,T:String;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('TOD : Cette commande permet de demander la date et l''heure de la journee.');
WriteLn;
WriteLn('Syntaxe : TOD [/?] [mois/jour/annee heure:minute:seconde]');
WriteLn;
WriteLn(' mois Ce parametre permet d''indiquer le mois');
WriteLn(' jour Ce parametre permet d''indiquer le jour du mois');
WriteLn(' annee Ce parametre permet d''indiquer l''annee');
WriteLn(' heure Ce parametre permet d''indiquer l''heure');
WriteLn(' minute Ce parametre permet d''indiquer les minutes');
WriteLn(' seconde Ce parametre permet d''indiquer les secondes');
WriteLn(' P Ce parametre permet d''afficher l''heure en continue');
End
Else
If(ParamStr(1)='P')or(ParamStr(1)='p')Then Begin
Y:=WhereY;
Repeat
GotoXY(1,Y);
GetDate(Year,Month,Day,DayOfMonth);
GetTime(Hour,Minute,Second,CentSec);
Write(PadZeroLeft(Month,2),'-',PadZeroLeft(Day,2),'-',PadZeroLeft(Year mod 100,2),
' ':7,PadZeroLeft(Hour,2),':',PadZeroLeft(Minute,2),':',PadZeroLeft(Second,2));
Until Keypressed;
If(ReadKey<>#0)Then;
WriteLn;
End
Else
If ParamCount>0Then Begin
T:='';
Pos:=PMonth;
S:=ParamStr(1);
For I:=1 to Length(S)do Begin
If S[I]<>'/'Then T:=T+S[I];
If S[I]='/'Then Begin
If Pos=PMonth Then Begin
Val(T,Month,Err);
Pos:=PDay;
End
Else
If Pos=PDay Then Begin
Val(T,Day,Err);
Pos:=PYear;
End
Else
Val(T,Year,Err);
T:='';
End;
End;
If T<>''Then Val(T,Year,Err);
SetDate(Year,Month,Day);
S:=ParamStr(2);
If S<>''Then Begin
T:='';
Hour:=0;
Minute:=0;
Second:=0;
Pos:=PHour;
For I:=1 to Length(S)do Begin
If S[I]<>':'Then T:=T+S[I];
If S[I]=':'Then Begin
If Pos=PHour Then Begin
Val(T,Hour,Err);
Pos:=PMin;
End
Else
If Pos=PMin Then Begin
Val(T,Minute,Err);
Pos:=PSec;
End
Else
Val(T,Second,Err);
T:='';
End;
End;
If T<>''Then Begin
If(Pos=PMin)Then Val(T,Minute,Err)
Else Val(T,Second,Err);
End;
SetTime(Hour,Minute,Second,0);
End;
End
Else
Begin
GetDate(Year,Month,Day,DayOfMonth);
GetTime(Hour,Minute,Second,CentSec);
WriteLn(Month:2,'-',PadZeroLeft(Day,2),'-',PadZeroLeft(Year mod 100,2),
' ':6,PadZeroLeft(Hour,2),':',PadZeroLeft(Minute,2),':',
PadZeroLeft(Second,2));
End;
END.