-
Notifications
You must be signed in to change notification settings - Fork 0
/
secondsbetweendatetime2.cbl
123 lines (123 loc) · 5.45 KB
/
secondsbetweendatetime2.cbl
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
identification division.
program-id. secondsbetweendatetime2.
*************************************************************
**** returns a 31 byte number of seconds between two valid
**** dates and times. passed as 4 arguments :
**** ccyymmdd hhmmss ccyymmdd hhmmss
**** calls TEST-FORMATTED-DATETIME function for edit
**** checks of dates and times
**** always check return codes when executing
*************************************************************
environment division.
configuration section.
source-computer.
System76
* with debugging mode
.
repository.
function all intrinsic.
data division.
working-storage section.
01 w-d1 pic x(08).
01 w-t1 pic x(06).
01 w-d2 pic x(08).
01 w-t2 pic x(06).
01 n-d1 pic 9(08).
01 n-t1 pic 9(06).
01 n-d2 pic 9(08).
01 n-t2 pic 9(06).
01 n-2 pic 9(02).
01 n-d3 pic 9(08).
01 n-t3 pic 9(06).
01 w-i1 comp-x pic x(04).
01 w-i2 comp-x pic x(04).
01 w-days pic 9(07).
01 w-seconds pic s9(31).
01 arg-knt comp-5 pic x(01).
01 seconds-per-day value 86400 pic 9(05).
01 seconds-per-hour value 3600 pic 9(04).
01 seconds-per-min value 60 pic 9(02).
01 tfd pic 9(08).
procedure division.
accept arg-knt from argument-number
if arg-knt <> 4
display 'four arguments are required:' upon SYSERR
display ' 1. first date ccyymmdd' upon SYSERR
display ' 2. first time hhmmss' upon SYSERR
display ' 3. second date ccyymmdd' upon SYSERR
display ' 4. second time hhmmss' upon SYSERR
goback returning -1
end-if
accept w-d1 from argument-value
accept w-t1 from argument-value
accept w-d2 from argument-value
accept w-t2 from argument-value
move test-formatted-datetime("YYYYMMDD", w-d1) to tfd
if tfd not = 0
display "Date 1 invalid" upon SYSERR
display "Error code = " tfd upon SYSERR
goback returning tfd
end-if
move w-d1 to n-d1
move test-formatted-datetime("hhmmss", w-t1) to tfd
if tfd not = 0
display "Time 1 invalid" upon SYSERR
display "Error code = " tfd upon SYSERR
goback returning tfd
end-if
move w-t1 to n-t1
move test-formatted-datetime("YYYYMMDD", w-d2) to tfd
if tfd not = 0
display "Date 2 invalid" upon SYSERR
display "Error code = " tfd upon SYSERR
goback returning tfd
end-if
move w-d2 to n-d2
move test-formatted-datetime("hhmmss", w-t2) to tfd
if tfd not = 0
display "Time 2 invalid" upon SYSERR
display "Error code = " tfd upon SYSERR
goback returning tfd
end-if
move w-t2 to n-t2
if n-d1 greater than n-d2
move n-d1 to n-d3
move n-t1 to n-t3
move n-d2 to n-d1
move n-t2 to n-t1
move n-d3 to n-d2
move n-t3 to n-t2
end-if
move integer-of-date(n-d1) to w-i1
move integer-of-date(n-d2) to w-i2
compute w-days = w-i1 - w-i2
end-compute
compute w-seconds = (w-days * seconds-per-day)
end-compute
* display w-seconds
move n-t1(1:2) to n-2
compute w-seconds = (w-seconds - (n-2 * seconds-per-hour))
end-compute
move n-t1(3:2) to n-2
compute w-seconds = (w-seconds - (n-2 * seconds-per-min))
end-compute
move n-t1(5:2) to n-2
compute w-seconds = (w-seconds - n-2)
end-compute
move n-t2(1:2) to n-2
compute w-seconds = (w-seconds + (n-2 * seconds-per-hour))
end-compute
move n-t2(3:2) to n-2
compute w-seconds = (w-seconds + (n-2 * seconds-per-min))
end-compute
move n-t2(5:2) to n-2
compute w-seconds = (w-seconds + n-2)
end-compute
if w-seconds less than 0
compute w-seconds = (w-seconds * -1)
end-compute
end-if
display w-seconds
move 0 to return-code
goback
.