Rev 6613 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6613 | Rev 7597 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | (* |
1 | (* |
2 | Copyright 2016 Anton Krotov |
2 | Copyright 2016, 2018 Anton Krotov |
Line 3... | Line 3... | ||
3 | 3 | ||
4 | This program is free software: you can redistribute it and/or modify |
4 | This program is free software: you can redistribute it and/or modify |
5 | it under the terms of the GNU Lesser General Public License as published by |
5 | it under the terms of the GNU Lesser General Public License as published by |
6 | the Free Software Foundation, either version 3 of the License, or |
6 | the Free Software Foundation, either version 3 of the License, or |
Line 17... | Line 17... | ||
17 | 17 | ||
Line 18... | Line 18... | ||
18 | MODULE DateTime; |
18 | MODULE DateTime; |
Line 19... | Line 19... | ||
19 | 19 | ||
Line 20... | Line 20... | ||
20 | IMPORT KOSAPI; |
20 | IMPORT KOSAPI; |
21 | 21 | ||
22 | CONST ERR* = -7.0D5; |
22 | CONST ERR* = -7.0E5; |
23 | 23 | ||
24 | PROCEDURE Encode*(Year, Month, Day, Hour, Min, Sec: INTEGER): LONGREAL; |
24 | PROCEDURE Encode*(Year, Month, Day, Hour, Min, Sec: INTEGER): REAL; |
25 | VAR d, i: INTEGER; M: ARRAY 13 OF CHAR; Res: LONGREAL; |
25 | VAR d, i: INTEGER; M: ARRAY 14 OF CHAR; Res: REAL; |
26 | BEGIN |
26 | BEGIN |
Line 36... | Line 36... | ||
36 | DEC(Year); |
36 | DEC(Year); |
37 | d := Year * 365 + (Year DIV 4) - (Year DIV 100) + (Year DIV 400) + Day - 693594; |
37 | d := Year * 365 + (Year DIV 4) - (Year DIV 100) + (Year DIV 400) + Day - 693594; |
38 | FOR i := 1 TO Month - 1 DO |
38 | FOR i := 1 TO Month - 1 DO |
39 | d := d + ORD(M[i]) - ORD("0") + 28 |
39 | d := d + ORD(M[i]) - ORD("0") + 28 |
40 | END; |
40 | END; |
41 | Res := LONG(FLT(d)) + LONG(FLT(Hour * 3600000 + Min * 60000 + Sec * 1000)) / 86400000.0D0 |
41 | Res := FLT(d) + FLT(Hour * 3600000 + Min * 60000 + Sec * 1000) / 86400000.0 |
42 | END |
42 | END |
43 | END |
43 | END |
44 | RETURN Res |
44 | RETURN Res |
45 | END Encode; |
45 | END Encode; |
Line 46... | Line 46... | ||
46 | 46 | ||
47 | PROCEDURE Decode*(Date: LONGREAL; VAR Year, Month, Day, Hour, Min, Sec: INTEGER): BOOLEAN; |
47 | PROCEDURE Decode*(Date: REAL; VAR Year, Month, Day, Hour, Min, Sec: INTEGER): BOOLEAN; |
Line 48... | Line 48... | ||
48 | VAR Res, flag: BOOLEAN; d, t, i: INTEGER; M: ARRAY 13 OF CHAR; |
48 | VAR Res, flag: BOOLEAN; d, t, i: INTEGER; M: ARRAY 14 OF CHAR; |
49 | 49 | ||
50 | PROCEDURE MonthDay(n: INTEGER): BOOLEAN; |
50 | PROCEDURE MonthDay(n: INTEGER; VAR d, Month: INTEGER; M: ARRAY OF CHAR): BOOLEAN; |
51 | VAR Res: BOOLEAN; |
51 | VAR Res: BOOLEAN; |
52 | BEGIN |
52 | BEGIN |
53 | Res := FALSE; |
53 | Res := FALSE; |
Line 58... | Line 58... | ||
58 | END |
58 | END |
59 | RETURN Res |
59 | RETURN Res |
60 | END MonthDay; |
60 | END MonthDay; |
Line 61... | Line 61... | ||
61 | 61 | ||
62 | BEGIN |
62 | BEGIN |
63 | IF (Date >= -693593.0D0) & (Date < 2958466.0D0) THEN |
63 | IF (Date >= -693593.0) & (Date < 2958466.0) THEN |
64 | d := FLOOR(Date); |
64 | d := FLOOR(Date); |
65 | t := FLOOR((Date - LONG(FLT(d))) * 86400000.0D0); |
65 | t := FLOOR((Date - FLT(d)) * 86400000.0); |
66 | d := d + 693593; |
66 | d := d + 693593; |
67 | Year := 1; |
67 | Year := 1; |
68 | Month := 1; |
68 | Month := 1; |
69 | WHILE d > 0 DO |
69 | WHILE d > 0 DO |
Line 80... | Line 80... | ||
80 | M[2] := "1" |
80 | M[2] := "1" |
81 | END; |
81 | END; |
82 | i := 1; |
82 | i := 1; |
83 | flag := TRUE; |
83 | flag := TRUE; |
84 | WHILE flag & (i <= 12) DO |
84 | WHILE flag & (i <= 12) DO |
85 | flag := MonthDay(i); |
85 | flag := MonthDay(i, d, Month, M); |
86 | INC(i) |
86 | INC(i) |
87 | END; |
87 | END; |
88 | Day := d; |
88 | Day := d; |
89 | Hour := t DIV 3600000; |
89 | Hour := t DIV 3600000; |
90 | t := t MOD 3600000; |
90 | t := t MOD 3600000; |
Line 96... | Line 96... | ||
96 | Res := FALSE |
96 | Res := FALSE |
97 | END |
97 | END |
98 | RETURN Res |
98 | RETURN Res |
99 | END Decode; |
99 | END Decode; |
Line 100... | Line 100... | ||
100 | 100 | ||
101 | PROCEDURE Now*(VAR Year, Month, Day, Hour, Min, Sec: INTEGER); |
101 | PROCEDURE Now*(VAR Year, Month, Day, Hour, Min, Sec, Msec: INTEGER); |
102 | VAR date, time: INTEGER; |
102 | VAR date, time: INTEGER; |
103 | BEGIN |
103 | BEGIN |
104 | date := KOSAPI.sysfunc1(29); |
104 | date := KOSAPI.sysfunc1(29); |
Line 132... | Line 132... | ||
132 | Sec := time MOD 16; |
132 | Sec := time MOD 16; |
133 | time := time DIV 16; |
133 | time := time DIV 16; |
134 | Sec := (time MOD 16) * 10 + Sec; |
134 | Sec := (time MOD 16) * 10 + Sec; |
135 | time := time DIV 16; |
135 | time := time DIV 16; |
Line 136... | Line 136... | ||
136 | 136 | ||
- | 137 | Year := Year + 2000; |
|
137 | Year := Year + 2000 |
138 | Msec := 0 |
Line 138... | Line 139... | ||
138 | END Now; |
139 | END Now; |
139 | 140 |