Rev 17035 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
16904 | guerimand | 1 | !! input is two word : first is type and second is date format YYYYMMDD |
2 | !! type are : |
||
3 | !! - whatday : calculate num of day in the week |
||
4 | !! - nextday : calculate date for next day |
||
5 | !! - prevday : calculate date for previous day |
||
6 | :: - endmonth : calculate number of day to the end of the month |
||
7 | |||
8 | !distribute word $wims_read_parm into type_,val_ |
||
9 | j_=!char 7 to 8 of $val_ |
||
10 | m_=!char 5 to 6 of $val_ |
||
11 | a_=!char 1 to 4 of $val_ |
||
12 | l_=31,28,31,30,31,30,31,31,30,31,30,31 |
||
13 | !reset output |
||
14 | |||
15 | !if $type_ notitemof whatday,nextday,endmonth,prevday |
||
16 | !exit |
||
17 | !else |
||
18 | !goto $type_ |
||
19 | !endif |
||
20 | |||
21 | :whatday |
||
17665 | bpr | 22 | !! use Mike Keith algorythm (year must be between 1583 and 9999) |
16904 | guerimand | 23 | !! 1=Monday etc... |
17665 | bpr | 24 | !ifval $m_=1 or $m_=2 |
16904 | guerimand | 25 | c_=1 |
26 | !else |
||
27 | c_=0 |
||
28 | !endif |
||
29 | A_ = $[$a_ - $c_] |
||
30 | M_ = $[$m_ + 12*$c_ - 2] |
||
31 | output = $[( $j_ + $A_ + floor($A_/4) - floor($A_/100) + floor($A_/400) + floor((31*$M_)/12) )%7] |
||
32 | !if $output=0 |
||
33 | output=7 |
||
34 | !endif |
||
35 | !exit |
||
36 | |||
37 | :nextday |
||
38 | !ifval $m_=2 and $j_=28 |
||
39 | !ifval $a_%4=0 and ($a_%400=0 or $a_%100!=0) |
||
40 | output=$(a_)0229 |
||
41 | !else |
||
42 | output=$(a_)0301 |
||
43 | !endif |
||
44 | !else |
||
45 | !ifval $j_<$(l_[$m_]) |
||
46 | j_=!char 2 to 3 of $[101+$j_] |
||
47 | output=$a_$m_$j_ |
||
48 | !else |
||
49 | !ifval $m_=12 |
||
17035 | guerimand | 50 | a_=!char 2 to 5 of $[10001+$a_] |
16904 | guerimand | 51 | output=$(a_)0101 |
52 | !else |
||
53 | m_=!char 2 to 3 of $[101+$m_] |
||
54 | output=$a_$(m_)01 |
||
55 | !endif |
||
56 | !endif |
||
57 | !endif |
||
58 | !exit |
||
59 | |||
60 | :prevday |
||
61 | !ifval $j_>1 |
||
62 | j_=!char 2 to 3 of $[99+$j_] |
||
63 | output=$a_$m_$j_ |
||
64 | !else |
||
65 | !ifval $m_>1 |
||
66 | !ifval $m_=3 and $a_%4=0 and ($a_%400=0 or $a_%100!=0) |
||
67 | output=$(a_)0229 |
||
68 | !else |
||
69 | m_=!char 2 to 3 of $[99+$m_] |
||
70 | output=$a_$m_$(l_[$[$m_]]) |
||
71 | !endif |
||
72 | !else |
||
17035 | guerimand | 73 | a_=!char 2 to 5 of $[9999+$a_] |
16904 | guerimand | 74 | output=$(a_)1231 |
75 | !endif |
||
76 | !endif |
||
77 | !exit |
||
78 | |||
79 | :endmonth |
||
80 | l_=!item $m_ of $l_ |
||
81 | !ifval $m_=2 and $a_%4=0 and ($a_%400=0 or $a_%100!=0) |
||
17665 | bpr | 82 | l_=29 |
16904 | guerimand | 83 | !endif |
84 | output=$[$l_-$j_+1] |
||
17665 | bpr | 85 | !exit |