getdate.pas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. i:=i+1;
  41. end
  42. else
  43. tmp := tmp + Str[i];
  44. end;
  45. Writeln(tmp);
  46. end;
  47. Procedure Help;
  48. Begin
  49. Writeln(#10'GetDate v1.0 1995 by Andreas Tetzl');
  50. Writeln('Public Domain'#10);
  51. Writeln('How to use the placeholders for Format:'#10);
  52. Writeln(' %d : Datum');
  53. Writeln(' %w : Weekday');
  54. Writeln(' %t : Time with Hour, Minutes and Seconds');
  55. Writeln(' %h : Hour');
  56. Writeln(' %m : Minutes');
  57. Writeln(' %s : Seconds');
  58. Writeln(' %a : Day');
  59. Writeln(' %o : Month');
  60. Writeln(' %y : Year'#10);
  61. Exit;
  62. end;
  63. begin
  64. For i:=0 to 1 do Vec[i]:=0;
  65. rda:=ReadArgs(Template,@vec,NIL);
  66. If rda=NIL then
  67. Begin
  68. If PrintFault(IoErr,NIL) then;
  69. halt(10);
  70. end;
  71. LFormat:=StrAlloc(100);
  72. If StrComp(pointer(vec[0]),pchar('')) <> 0 then StrCopy(LFormat,pointer(vec[0])) else LFormat:=NIL;
  73. If vec[1]<>0 then Help;
  74. WeekDay:=StrAlloc(LEN_DATSTRING);
  75. Date:=StrAlloc(LEN_DATSTRING);
  76. Time:=StrAlloc(LEN_DATSTRING);
  77. Hours:=StrAlloc(10);
  78. Mins:=StrAlloc(10);
  79. Secs:=StrAlloc(10);
  80. Day:=StrAlloc(10);
  81. Month:=StrAlloc(10);
  82. Year:=StrAlloc(10);
  83. DateStamp(pDateStamp(@DS));
  84. DT.dat_Stamp:=DS;
  85. DT.dat_Format:=Format_DOS;
  86. DT.dat_StrDay:=WeekDay;
  87. DT.dat_StrDate:=Date;
  88. DT.dat_StrTime:=Time;
  89. If DOSDateToStr(@DT) then begin
  90. StrlCopy(hours,Time,2);
  91. StrlCopy(Mins,addr(Time[3]),2);
  92. StrlCopy(Secs,addr(Time[6]),2);
  93. StrlCopy(Day,Date,2);
  94. StrlCopy(Month,addr(Date[3]),3);
  95. StrlCopy(Year,addr(Date[7]),2);
  96. { In den deutschen Locale-Strings von OS3.0 scheint ein Fehler zu sein. }
  97. { Am Datums-String ist hinten noch ein Leerzeichen, also '16-Feb-95 '. }
  98. { Hier wird geprüft, ob das letzte Zeichen ein Leerzeichen ist. }
  99. { Das Leerzeichen wird dann durch '\0' (Stringende) ersetzt. }
  100. If Date[StrLen(Date)-1]=' ' then Date[StrLen(Date)-1]:=#0;
  101. end;
  102. If LFormat=NIL then
  103. Writeln(WeekDay,' ',Date,' ',Time)
  104. else
  105. PrintFormat;
  106. StrDispose(LFormat);
  107. StrDispose(WeekDay);
  108. StrDispose(date);
  109. StrDispose(Time);
  110. StrDispose(hours);
  111. StrDispose(mins);
  112. StrDispose(secs);
  113. StrDispose(Day);
  114. StrDispose(Month);
  115. StrDispose(Year);
  116. end.