getdate.pas 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. Program GetDate;
  2. { GetDate v1.0 1995 by Andreas Tetzl }
  3. { Public Domain }
  4. {
  5. Translated to fpc pascal
  6. 19 Mar 2001.
  7. [email protected]
  8. }
  9. uses amigados, strings;
  10. const template : pchar = 'Format/K,Help/S';
  11. version : pchar = '$VER: GetDate 1.0 (21.2.95)';
  12. VAR DS : tDateStamp;
  13. DT : _tDateTime;
  14. rda : pRDArgs;
  15. WeekDay, Date, Time, hours, mins, secs, day, month, year : pchar;
  16. vec : Array[0..1] of longint;
  17. i : longint;
  18. LFormat : pchar;
  19. Procedure PrintFormat;
  20. VAR Str : string;
  21. tmp : string;
  22. Begin
  23. Str := strpas(LFormat);
  24. tmp := '';
  25. For i:=1 to length(Str) do
  26. begin
  27. If Str[i]='%' then
  28. Begin
  29. Case UpCase(Str[i+1]) of
  30. ('D') : tmp := tmp + strpas(Date);
  31. ('W') : tmp := tmp + strpas(WeekDay);
  32. ('T') : tmp := tmp + strpas(Time);
  33. ('H') : tmp := tmp + strpas(hours);
  34. ('M') : tmp := tmp + strpas(Mins);
  35. ('S') : tmp := tmp + strpas(Secs);
  36. ('A') : tmp := tmp + strpas(Day);
  37. ('O') : tmp := tmp + strpas(Month);
  38. ('Y') : tmp := tmp + strpas(Year);
  39. end;
  40. end
  41. else
  42. tmp := tmp + Str[i];
  43. end;
  44. Writeln(tmp);
  45. end;
  46. Procedure Help;
  47. Begin
  48. Writeln(#10'GetDate v1.0 1995 by Andreas Tetzl');
  49. Writeln('Public Domain'#10);
  50. Writeln('How to use the placeholders for Format:'#10);
  51. Writeln(' %d : Datum');
  52. Writeln(' %w : Weekday');
  53. Writeln(' %t : Time with Hour, Minutes and Seconds');
  54. Writeln(' %h : Hour');
  55. Writeln(' %m : Minutes');
  56. Writeln(' %s : Seconds');
  57. Writeln(' %a : Day');
  58. Writeln(' %o : Month');
  59. Writeln(' %y : Year'#10);
  60. Exit;
  61. end;
  62. begin
  63. For i:=0 to 1 do Vec[i]:=0;
  64. rda:=ReadArgs(Template,@vec,NIL);
  65. If rda=NIL then
  66. Begin
  67. If PrintFault(IoErr,NIL) then;
  68. halt(10);
  69. end;
  70. LFormat:=StrAlloc(100);
  71. If StrComp(pointer(vec[0]),pchar('')) <> 0 then StrCopy(LFormat,pointer(vec[0])) else LFormat:=NIL;
  72. If vec[1]<>0 then Help;
  73. WeekDay:=StrAlloc(LEN_DATSTRING);
  74. Date:=StrAlloc(LEN_DATSTRING);
  75. Time:=StrAlloc(LEN_DATSTRING);
  76. Hours:=StrAlloc(10);
  77. Mins:=StrAlloc(10);
  78. Secs:=StrAlloc(10);
  79. Day:=StrAlloc(10);
  80. Month:=StrAlloc(10);
  81. Year:=StrAlloc(10);
  82. DateStamp(pDateStamp(@DS));
  83. DT.dat_Stamp:=DS;
  84. DT.dat_Format:=Format_DOS;
  85. DT.dat_StrDay:=WeekDay;
  86. DT.dat_StrDate:=Date;
  87. DT.dat_StrTime:=Time;
  88. If DOSDateToStr(@DT) then begin
  89. StrlCopy(hours,Time,2);
  90. StrlCopy(Mins,addr(Time[3]),2);
  91. StrlCopy(Secs,addr(Time[6]),2);
  92. StrlCopy(Day,Date,2);
  93. StrlCopy(Month,addr(Date[3]),3);
  94. StrlCopy(Year,addr(Date[7]),2);
  95. { In den deutschen Locale-Strings von OS3.0 scheint ein Fehler zu sein. }
  96. { Am Datums-String ist hinten noch ein Leerzeichen, also '16-Feb-95 '. }
  97. { Hier wird geprüft, ob das letzte Zeichen ein Leerzeichen ist. }
  98. { Das Leerzeichen wird dann durch '\0' (Stringende) ersetzt. }
  99. If Date[StrLen(Date)-1]=' ' then Date[StrLen(Date)-1]:=#0;
  100. end;
  101. If LFormat=NIL then
  102. Writeln(WeekDay,' ',Date,' ',Time)
  103. else
  104. PrintFormat;
  105. StrDispose(LFormat);
  106. StrDispose(WeekDay);
  107. StrDispose(date);
  108. StrDispose(Time);
  109. StrDispose(hours);
  110. StrDispose(mins);
  111. StrDispose(secs);
  112. StrDispose(Day);
  113. StrDispose(Month);
  114. StrDispose(Year);
  115. end.