summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/webtbs/tw12894.pp
blob: 0e69ba440d1f638b5bbacd3bfb785db23e0616f9 (plain)
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
program Project1;

uses
 Classes, SysUtils, DateUtils;

var
 utime : longword;
 sec : word;
 currentDt, convertedDt : TDateTime;
 times: longint;
 s1, s2: ansistring;

begin
 for sec := 0 to 59 do
   begin
     currentDt := EncodeDateTime(1989, 9, 16, 12, 0, sec, 0);
     utime := DateTimeToUnix(currentDt);
     convertedDt := UnixToDateTime(utime);
     s1:=FormatDateTime('mm/dd/yyyy HH:nn:ss', currentDt);
     s2:=FormatDateTime('mm/dd/yyyy HH:nn:ss', convertedDt);
     writeln(s1 + ' = ' + IntToStr(utime) + ' = ' + s2);
     if (s1<>s2) then
       halt(1);
 end;
 for times:=-10000 to 10000 do
   if times<>datetimetounix(unixtodatetime(times)) then
     begin
       writeln('error for ',times,', becomes ',datetimetounix(unixtodatetime(times)));
       halt(2);
     end;

 // check some borderline cases
 currentDt := EncodeDateTime(1899, 12, 29, 6, 0, 0, 0);
 convertedDt := EncodeDateTime(1899, 12, 30, 6, 0, 0, 0);
 writeln(currentDt:0:4,' - ',convertedDt:0:4);
 DateSeparator := '-'; // further test assumes we have '-' as a date separator
 s1:=FormatDateTime('mm/dd/yyyy HH:nn:ss', currentDt);
 s2:=FormatDateTime('mm/dd/yyyy HH:nn:ss', convertedDt);
 writeln(s1);
 writeln(s2);
 if (currentDt<>-1.25) or
    (convertedDt<>0.25) or
    (s1<>'12-29-1899 06:00:00') or
    (s2<>'12-30-1899 06:00:00') or
    (DaysBetween(currentDt,convertedDt)<>1) or
    (HoursBetween(currentDt,convertedDt)<>24) or
    (MinutesBetween(currentDt,convertedDt)<>24*60) or
    (SecondsBetween(currentDt,convertedDt)<>24*60*60) or
    (MilliSecondsBetween(currentDt,convertedDt)<>24*60*60*1000) then
   begin
     writeln('between ',s1,' and ',s2);
     writeln(DaysBetween(currentDt,convertedDt));
     writeln(HoursBetween(currentDt,convertedDt));
     writeln(MinutesBetween(currentDt,convertedDt));
     writeln(SecondsBetween(currentDt,convertedDt));
     writeln(MilliSecondsBetween(currentDt,convertedDt));
     halt(3);
   end;
 currentDt := EncodeDateTime(1899, 12, 30, 6, 0, 0, 0);
 convertedDt := EncodeDateTime(1899, 12, 29, 6, 0, 0, 0);
 if (DaysBetween(currentDt,convertedDt)<>1) or
    (HoursBetween(currentDt,convertedDt)<>24) or
    (MinutesBetween(currentDt,convertedDt)<>24*60) or
    (SecondsBetween(currentDt,convertedDt)<>24*60*60) or
    (MilliSecondsBetween(currentDt,convertedDt)<>24*60*60*1000) then
   halt(4);
 currentDt := EncodeDateTime(1898, 12, 30, 6, 0, 0, 0);
 convertedDt := EncodeDateTime(1899, 12, 30, 6, 0, 0, 0);
 { 0 and 11 rather than 1 and 12, because YearsBetween and MonthsBetween
   are averaged over 4 years -> include a leap year }
 if (YearsBetween(currentDt,convertedDt)<>0) or
    (MonthsBetween(currentDt,convertedDt)<>11) or
    (DaysBetween(currentDt,convertedDt)<>365) or
    (HoursBetween(currentDt,convertedDt)<>365*24) or
    (MinutesBetween(currentDt,convertedDt)<>365*24*60) or
    (SecondsBetween(currentDt,convertedDt)<>365*24*60*60) or
    (MilliSecondsBetween(currentDt,convertedDt)<>365*24*60*60*1000) then
   begin
     writeln('between ',s1,' and ',s2);
     writeln(YearsBetween(currentDt,convertedDt));
     writeln(MonthsBetween(currentDt,convertedDt));
     writeln(DaysBetween(currentDt,convertedDt));
     writeln(HoursBetween(currentDt,convertedDt));
     writeln(MinutesBetween(currentDt,convertedDt));
     writeln(SecondsBetween(currentDt,convertedDt));
     writeln(MilliSecondsBetween(currentDt,convertedDt));
     halt(5);
   end;
 currentDt := EncodeDateTime(1898, 12, 29, 6, 0, 0, 0);
 convertedDt := EncodeDateTime(1899, 12, 30, 6, 0, 0, 0);
 if (YearsBetween(currentDt,convertedDt)<>1) or
    (MonthsBetween(currentDt,convertedDt)<>12) or
    (DaysBetween(currentDt,convertedDt)<>366) or
    (HoursBetween(currentDt,convertedDt)<>366*24) or
    (MinutesBetween(currentDt,convertedDt)<>366*24*60) or
    (SecondsBetween(currentDt,convertedDt)<>366*24*60*60) or
    (MilliSecondsBetween(currentDt,convertedDt)<>366*24*60*60*1000) then
   halt(6);
  currentDt := 39939.796069305557;
  convertedDt := 39939.0;
  if YearsBetween(currentDt,convertedDt)<>0 then
    halt(7);
// convertedDt:=incseconds(currentDt,

end.