Browse Source

+ Initial check-in

michael 20 years ago
parent
commit
414637c6e8

+ 101 - 0
docs/datutex/Makefile

@@ -0,0 +1,101 @@
+#######################################################################
+#
+# Makefile to compile all examples and convert them to LaTeX
+# 
+#######################################################################
+
+# Compiler
+
+ifndef FPC
+ifdef PP
+FPC=$(PP)
+endif
+endif
+ifndef FPC
+FPCPROG:=$(strip $(wildcard $(addsuffix /fpc$(SRCEXEEXT),$(SEARCHPATH))))
+ifneq ($(FPCPROG),)
+FPCPROG:=$(firstword $(FPCPROG))
+FPC:=$(shell $(FPCPROG) -PB)
+ifneq ($(findstring Error,$(FPC)),)
+override FPC=ppc386
+endif
+else
+override FPC=ppc386
+endif
+endif
+override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
+override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)
+
+# Unit directory
+# UNITDIR=/usr/lib/ppc/0.99.0/linuxunits
+
+
+# Any options you wish to pass.
+PPOPTS=
+
+# Script to convert the programs to LaTeX examples which can be included.
+PP2TEX=../pp2tex
+
+# Script to collect all examples in 1 file.
+MAKETEX=make1tex
+
+#######################################################################
+# No need to edit after this line.
+#######################################################################
+
+ifdef UNITDIR
+PPOPTS:=$(PPOPTS) -Up$(UNITDIR);
+endif
+
+.SUFFIXES: .pp .tex
+
+.PHONY: all tex clean execute
+
+OBJECTS=ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12\
+        ex13 ex14 ex15 ex16 ex17 ex18 ex19 ex20 ex21 ex22 ex23 ex24\
+        ex25 ex26 ex27 ex28 ex29 ex30 ex31 ex32 ex33 ex34 ex35 ex36\
+        ex37 ex38 ex39 ex40 ex41 ex42 ex43 ex44 ex45 ex46 ex47\
+        ex48 ex49 ex50 ex51 ex52 ex53 ex54 ex55 ex56 ex57 ex58\
+        ex59 ex60 ex61 ex62 ex63 ex64 ex65 ex66 ex67 ex68 ex69 ex70\
+        ex71 ex72 ex73 ex74 ex75 ex76 ex77 ex78 ex79 ex80 \
+        ex81 ex82 ex83 ex84 ex85 ex86 ex87 ex88 ex89 ex90 ex91 ex92 \
+        ex93
+        
+# This might not be the same list as objects, since some of the
+# tests might be interactive.
+TOTEST=ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12\
+        ex13 ex14 ex15 ex16 ex17 ex18 ex19 ex20 ex21 ex22 ex23 ex24\
+        ex25 ex26 ex27 ex28 ex29 ex30 ex31 ex32 ex35 ex36\
+        ex37 ex39 ex41 ex42 ex43 ex44 ex45 ex46 ex47\
+        ex48 ex49 ex50 ex51 ex52 ex53 ex54 ex55 ex56 ex57 ex58\
+        ex59 ex60 ex61 ex62 ex63 ex64 ex65 ex66 ex67 ex68 ex69 ex70\
+        ex72 ex73 ex74 ex75 ex76 ex77 ex78 ex79 ex80 \
+        ex81 ex82 ex83 ex84 ex85 ex86 ex87 ex88 ex89 ex90 ex91 ex92 \
+        ex93    
+
+LOGFILE=$(addsuffix .log, $(TOTEST))
+        
+
+TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
+
+all : $(OBJECTS)
+
+execute: $(LOGFILE)
+
+tex : $(TEXOBJECTS)
+
+onetex : tex
+	$(MAKETEX) $(TEXOBJECTS)
+
+clean : 
+	rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS)
+	rm -f *.ow *.sw *.exe *.dll *.ppw *.tmp *.log *.dat
+ 
+$(OBJECTS): %: %.pp
+	$(FPC) $(PPOPTS) $*
+
+$(TEXOBJECTS): %.tex: %.pp head.tex foot.tex
+	$(PP2TEX) $*
+
+$(LOGFILE): %.log: %.exe 
+	$* > $*.log

+ 23 - 0
docs/datutex/README

@@ -0,0 +1,23 @@
+This directory contains the examples for the Sysutils unit.
+
+ex1.pp contains an example of the DateOf function.
+ex2.pp contains an example of the TimeOf function.
+ex3.pp contains an example of the IsInLeapYear function.
+ex4.pp contains an example of the IsPM function.
+ex5.pp contains an example of the IsValidDate function.
+ex6.pp contains an example of the IsValidTime function.
+ex6.pp contains an example of the IsValidDateTime function.
+ex9.pp contains an example of the IsValidDateDay function.
+ex10.pp contains an example of the IsValidDateWeek function.
+ex11.pp contains an example of the IsValidMonthWeek function.
+ex12.pp contains an example of the WeeksInYear function.
+ex13.pp contains an example of the WeeksInAYear function.
+ex14.pp contains an example of the DaysInYear function.
+ex15.pp contains an example of the DaysInAYear function.
+ex16.pp contains an example of the DaysInMonth function.
+ex18.pp contains an example of the Yesterday function.
+ex20.pp contains an example of the IsToday function.
+ex21.pp contains an example of the IsSameDay function.
+ex22.pp contains an example of the PreviousDayOfWeek function.
+ex23.pp contains an example of the YearOf function.
+ex24.pp contains an example of the StartOfTheYear function.

+ 9 - 0
docs/datutex/ex1.pp

@@ -0,0 +1,9 @@
+Program Example1;
+
+{ This program demonstrates the DateOf function }
+
+Uses SysUtils,DateUtils;
+
+Begin
+  Writeln('Date is: ',DateTimeToStr(DateOf(Now)));
+End.

+ 27 - 0
docs/datutex/ex10.pp

@@ -0,0 +1,27 @@
+Program Example10;
+
+{ This program demonstrates the IsValidDateWeek function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  Y,W,D : Word;
+  B : Boolean;
+
+Begin 
+  For Y:=2000 to 2004 do
+    begin
+    B:=True;
+    For W:=51 to 54 do
+      For D:=1 to 7 do
+        If B then 
+          begin
+          B:=IsValidDateWeek(Y,W,D);
+          If Not B then
+            if (D=1) then
+              Writeln(Y,' has exactly ',W,' weeks.')
+            else
+              Writeln(Y,' has ',W,' weeks and ',D-1,' days.');
+          end;
+    end;
+End.

+ 27 - 0
docs/datutex/ex11.pp

@@ -0,0 +1,27 @@
+Program Example11;
+
+{ This program demonstrates the IsValidDateMonthWeek function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  Y,W,D : Word;
+  B : Boolean;
+
+Begin 
+  For Y:=2000 to 2004 do
+    begin
+    B:=True;
+    For W:=4 to 6 do
+      For D:=1 to 7 do
+        If B then 
+          begin
+          B:=IsValidDateMonthWeek(Y,12,W,D);
+          If Not B then
+            if (D=1) then
+              Writeln('December ',Y,' has exactly ',W,' weeks.')
+            else
+              Writeln('December ',Y,' has ',W,' weeks and ',D-1,' days.');
+          end;
+    end;
+End.

+ 13 - 0
docs/datutex/ex12.pp

@@ -0,0 +1,13 @@
+Program Example12;
+
+{ This program demonstrates the WeeksInYear function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  Y : Word;
+
+Begin
+  For Y:=1992 to 2010 do
+    Writeln(Y,' has ',WeeksInYear(EncodeDate(Y,2,1)),' weeks.');
+End.

+ 13 - 0
docs/datutex/ex13.pp

@@ -0,0 +1,13 @@
+Program Example13;
+
+{ This program demonstrates the WeeksInAYear function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  Y : Word;
+
+Begin
+  For Y:=1992 to 2010 do
+    Writeln(Y,' has ',WeeksInAYear(Y),' weeks.');
+End.

+ 13 - 0
docs/datutex/ex14.pp

@@ -0,0 +1,13 @@
+Program Example14;
+
+{ This program demonstrates the DaysInYear function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  Y : Word;
+
+Begin
+  For Y:=1992 to 2010 do
+    Writeln(Y,' has ',DaysInYear(EncodeDate(Y,1,1)),' days.');
+End.

+ 13 - 0
docs/datutex/ex15.pp

@@ -0,0 +1,13 @@
+Program Example15;
+
+{ This program demonstrates the DaysInAYear function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  Y : Word;
+
+Begin
+  For Y:=1992 to 2010 do
+    Writeln(Y,' has ',DaysInAYear(Y),' days.');
+End.

+ 14 - 0
docs/datutex/ex16.pp

@@ -0,0 +1,14 @@
+Program Example16;
+
+{ This program demonstrates the DaysInMonth function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  Y,M : Word;
+
+Begin
+  For Y:=1992 to 2010 do
+    For M:=1 to 12 do
+      Writeln(LongMonthNames[m],' ',Y,' has ',DaysInMonth(EncodeDate(Y,M,1)),' days.');
+End.

+ 14 - 0
docs/datutex/ex17.pp

@@ -0,0 +1,14 @@
+Program Example17;
+
+{ This program demonstrates the DaysInAMonth function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  Y,M : Word;
+
+Begin
+  For Y:=1992 to 2010 do
+    For M:=1 to 12 do
+      Writeln(LongMonthNames[m],' ',Y,' has ',DaysInAMonth(Y,M),' days.');
+End.

+ 10 - 0
docs/datutex/ex18.pp

@@ -0,0 +1,10 @@
+Program Example18;
+
+{ This program demonstrates the Yesterday function }
+
+Uses SysUtils,DateUtils;
+
+Begin
+  Writeln(FormatDateTime('"Today is " dd mmmm yyyy',Today));
+  Writeln(FormatDateTime('"Yesterday was " dd mmmm yyyy',Yesterday));
+End.

+ 10 - 0
docs/datutex/ex19.pp

@@ -0,0 +1,10 @@
+Program Example19;
+
+{ This program demonstrates the Tomorrow function }
+
+Uses SysUtils,DateUtils;
+
+Begin
+  Writeln(FormatDateTime('"Today is" dd mmmm yyyy',Today));
+  Writeln(FormatDateTime('"Tomorrow will be" dd mmmm yyyy',Tomorrow));
+End.

+ 9 - 0
docs/datutex/ex2.pp

@@ -0,0 +1,9 @@
+Program Example2;
+
+{ This program demonstrates the TimeOf function }
+
+Uses SysUtils,DateUtils;
+
+Begin
+  Writeln('Time is : ',TimeToStr(TimeOf(Now)));
+End.

+ 11 - 0
docs/datutex/ex20.pp

@@ -0,0 +1,11 @@
+Program Example20;
+
+{ This program demonstrates the IsToday function }
+
+Uses SysUtils,DateUtils;
+
+Begin
+  Writeln('Today     : ',IsToday(Today));
+  Writeln('Tomorrow  : ',IsToday(Tomorrow));
+  Writeln('Yesterday : ',IsToday(Yesterday));
+End.

+ 18 - 0
docs/datutex/ex21.pp

@@ -0,0 +1,18 @@
+Program Example21;
+
+{ This program demonstrates the IsSameDay function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  I : Integer;
+  D : TDateTime;
+  
+Begin
+  For I:=1 to 3 do
+    begin
+    D:=Today+Random(3)-1;
+    Write(FormatDateTime('dd mmmm yyyy "is today : "',D));
+    Writeln(IsSameDay(D,Today));
+    end;
+End.

+ 13 - 0
docs/datutex/ex22.pp

@@ -0,0 +1,13 @@
+Program Example22;
+
+{ This program demonstrates the PreviousDayOfWeek function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  D : Word;
+
+Begin
+  For D:=1 to 7 do
+    Writeln('Previous day of ',D,' is : ',PreviousDayOfWeek(D));
+End.

+ 20 - 0
docs/datutex/ex23.pp

@@ -0,0 +1,20 @@
+Program Example23;
+
+{ This program demonstrates the YearOf function }
+
+Uses SysUtils,DateUtils;
+
+Var 
+  D : TDateTime;
+
+Begin
+  D:=Now;
+  Writeln('Year        : ',YearOf(D));
+  Writeln('Month       : ',MonthOf(D));
+  Writeln('Day         : ',DayOf(D));
+  Writeln('Week        : ',WeekOf(D));
+  Writeln('Hour        : ',HourOf(D));
+  Writeln('Minute      : ',MinuteOf(D));
+  Writeln('Second      : ',SecondOf(D));
+  Writeln('MilliSecond : ',MilliSecondOf(D));
+End.

+ 12 - 0
docs/datutex/ex24.pp

@@ -0,0 +1,12 @@
+Program Example24;
+
+{ This program demonstrates the StartOfTheYear function }
+
+Uses SysUtils,DateUtils;
+
+Const
+  Fmt = '"First day of this year : "dd mmmm yyyy';
+
+Begin
+  Writeln(FormatDateTime(Fmt,StartOfTheYear(Today)));
+End.

+ 12 - 0
docs/datutex/ex25.pp

@@ -0,0 +1,12 @@
+Program Example25;
+
+{ This program demonstrates the EndOfTheYear function }
+
+Uses SysUtils,DateUtils;
+
+Const
+  Fmt = '"Last day of this year : "dd mmmm yyyy';
+
+Begin
+  Writeln(FormatDateTime(Fmt,EndOfTheYear(Today)));
+End.

+ 12 - 0
docs/datutex/ex26.pp

@@ -0,0 +1,12 @@
+Program Example26;
+
+{ This program demonstrates the StartOfAYear function }
+
+Uses SysUtils,DateUtils;
+
+Const
+  Fmt = '"First day of this year : "dd mmmm yyyy';
+
+Begin
+  Writeln(FormatDateTime(Fmt,StartOfAYear(YearOf(Today))));
+End.

+ 12 - 0
docs/datutex/ex27.pp

@@ -0,0 +1,12 @@
+Program Example25;
+
+{ This program demonstrates the EndOfAYear function }
+
+Uses SysUtils,DateUtils;
+
+Const
+  Fmt = '"Last day of this year : "dd mmmm yyyy';
+
+Begin
+  Writeln(FormatDateTime(Fmt,EndOfAYear(YearOf(Today))));
+End.

+ 9 - 0
docs/datutex/ex3.pp

@@ -0,0 +1,9 @@
+Program Example3;
+
+{ This program demonstrates the IsInLeapYear function }
+
+Uses SysUtils,DateUtils;
+
+Begin
+  Writeln('Current year is leap year: ',IsInLeapYear(Date));
+End.

+ 9 - 0
docs/datutex/ex4.pp

@@ -0,0 +1,9 @@
+Program Example4;
+
+{ This program demonstrates the IsPM function }
+
+Uses SysUtils,DateUtils;
+
+Begin
+  Writeln('Current time is PM : ',IsPM(Now));
+End.

+ 16 - 0
docs/datutex/ex5.pp

@@ -0,0 +1,16 @@
+Program Example5;
+
+{ This program demonstrates the IsValidDate function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  Y,M,D : Word;
+
+Begin
+  For Y:=2000 to 2004 do
+   For M:=1 to 12 do
+     For D:=1 to 31 do
+       If Not IsValidDate(Y,M,D) then 
+         Writeln(D,' is not a valid day in ',Y,'/',M);
+End.

+ 21 - 0
docs/datutex/ex6.pp

@@ -0,0 +1,21 @@
+Program Example6;
+
+{ This program demonstrates the IsValidTime function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  H,M,S,MS : Word;
+  I : Integer;
+  
+Begin
+  For I:=1 to 10 do
+    begin
+    H:=Random(48);
+    M:=Random(120);
+    S:=Random(120);
+    MS:=Random(2000);
+    If Not IsValidTime(H,M,S,MS) then
+      Writeln(H,':',M,':',S,'.',MS,' is not a valid time.');
+    end;
+End.

+ 25 - 0
docs/datutex/ex7.pp

@@ -0,0 +1,25 @@
+Program Example7;
+
+{ This program demonstrates the IsValidDateTime function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  Y,Mo,D : Word;
+  H,M,S,MS : Word;
+  I : Integer;
+  
+Begin
+  For I:=1 to 10 do
+    begin
+    Y:=2000+Random(5);
+    Mo:=Random(15);
+    D:=Random(40);
+    H:=Random(32);
+    M:=Random(90);
+    S:=Random(90);
+    MS:=Random(1500);
+    If Not IsValidDateTime(Y,Mo,D,H,M,S,MS) then
+      Writeln(Y,'-',Mo,'-',D,' ',H,':',M,':',S,'.',MS,' is not a valid date/time.');
+    end;
+End.

+ 14 - 0
docs/datutex/ex9.pp

@@ -0,0 +1,14 @@
+Program Example9;
+
+{ This program demonstrates the IsValidDateDay function }
+
+Uses SysUtils,DateUtils;
+
+Var
+  Y : Word;
+
+Begin
+  For Y:=1996 to 2004 do
+    if  IsValidDateDay(Y,366) then
+      Writeln(Y,' is a leap year');
+End.

+ 9 - 0
docs/datutex/newex

@@ -0,0 +1,9 @@
+#!/bin/sh
+if [ -e ex${1}.pp ]; then
+  mv ex${1}.pp ex${1}.pp.orig
+fi
+sed -e s/Example/Example$1/ -e s/\\\*\\\*\\\*/$2/ <template.pp >ex${1}.pp
+echo "ex${1}.pp contains an example of the $2 function." >>README
+joe ex${1}.pp
+ppc386 ex${1}.pp && ex${1}
+rm ex${1}.o

+ 8 - 0
docs/datutex/template.pp

@@ -0,0 +1,8 @@
+Program Example;
+
+{ This program demonstrates the *** function }
+
+Uses SysUtils,DateUtils;
+
+Begin
+End.