home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / QDATE.ZIP / QDATE.CMD
OS/2 REXX Batch file  |  1991-07-06  |  5KB  |  162 lines

  1. /* Type/push today's date and moon phase in English     */
  2. /* Date by Mike Cowlishaw (MFC at VENTA)  1980          */
  3. /* Moon by Marc Donner (DONNER at YKTVMZ) 1981          */
  4. arg opt . '(' option . ')' .; parse source . . en .
  5. if opt=? | (opt<>'' & opt<>'PUSH' & option<>'NODATE' & option<>'NOPHASE')
  6.    then call tell
  7. call init
  8. parse value date('S') with y 5 m 7 d +2
  9. m= 0 + m
  10. d= 0 + d
  11. call julian y m d
  12. parse var result j
  13. weekday= 1 + ( j // 7 )
  14. unit=d//10
  15. select
  16.   when d%10=1 then d=d'th'
  17.   when unit=1 then d=d'st'
  18.   when unit=2 then d=d'nd'
  19.   when unit=3 then d=d'rd'
  20.   otherwise d=d'th'
  21.   end
  22. day = word(daynames,weekday)
  23. month = word(monthnames,m)
  24. string='It''s' day 'the' d 'of' month',' y'.'
  25. if opt='PUSH' then do; push string; exit; end
  26. else do; if option<>'NODATE' then do; say; say string; end; end; say
  27. if option<>'NOPHASE' then do
  28. moonphase_today = ((j-9)/lunation)//1
  29.  
  30. select
  31.    when newphase <= moonphase_today & moonphase_today < waxphase
  32.       then target_phase = waxphase
  33.    when waxphase <= moonphase_today & moonphase_today < fullphase
  34.       then target_phase = fullphase
  35.    when fullphase <= moonphase_today & moonphase_today < wanephase
  36.       then target_phase = wanephase
  37.    when (((wanephase <= moonphase_today)&(moonphase_today <= 1)) |,
  38.          ((0 <= moonphase_today)&(moonphase_today < newphase)))
  39.       then target_phase = newphase
  40.    otherwise /* Should never get here. */
  41.       nop
  42.    end
  43. if moonphase_today > target_phase
  44.    then extradays = trunc( (1 + target_phase - moonphase_today ) * lunation )
  45.    else extradays = trunc( (target_phase - moonphase_today) * lunation )
  46. moonout = trunc( 4 * target_phase )
  47. moonout = moon.moonout
  48. select
  49.    when extradays = 0
  50.       then say 'There will be a' moonout 'moon tonight.'
  51.    when extradays = 1
  52.       then say 'There will be a' moonout 'moon tomorrow.'
  53.    otherwise
  54.       dax.2='two'; dax.3='three'; dax.4='four'
  55.       dax.5='five'; dax.6='six'; dax.7='seven'
  56.       say 'There will be a' moonout 'moon in' dax.extradays 'days.'
  57.    end
  58. say
  59. end
  60. exit
  61.  
  62. julian:
  63. parse arg j_year j_month j_day
  64. j_yearz = j_year + 4712 /* Origin of Julian calendar is 1 Jan 4713 BCE */
  65. j_year_days = 365 * j_yearz + (j_yearz % 4)
  66. if j_yearz//4 = 0
  67.    then do
  68.       j_leap = 'LEAP'
  69.       j_year_days = j_year_days - 1
  70.       end
  71.    else j_leap = 'NORM'
  72. if m=1  then if d<7 then do; say; say "Happy New Year!"; end
  73. /* if m d=2*2*2 3*3*3 then do; say "It's Mike Cowlishaw's Birthday!"
  74.    say; end */
  75. if (d=24 | d=25) then if m=12 then do; say "Merry Christmas!"; say; end
  76. j_month_days = totdays.j_leap.j_month
  77. julian_date = j_year_days + j_month_days + j_day
  78. if julian_date <= 2361221          /* Date is before 2 September 1752. */
  79.    then return julian_date
  80. j_yearz = j_year - 300
  81. if j_month <= 2
  82.    then j_yearz = j_yearz - 1
  83. j_century = j_yearz % 100
  84. julian_date = julian_date - (j_century * 3) % 4 - 1
  85. return julian_date
  86.  
  87. init:
  88. monthlen.norm.1='31'
  89. monthlen.norm.2='28'
  90. monthlen.norm.3='31'
  91. monthlen.norm.4='30'
  92. monthlen.norm.5='31'
  93. monthlen.norm.6='30'
  94. monthlen.norm.7='31'
  95. monthlen.norm.8='31'
  96. monthlen.norm.9='30'
  97. monthlen.norm.10='31'
  98. monthlen.norm.11='30'
  99. monthlen.norm.12='31'
  100. monthlen.leap.1='31'
  101. monthlen.leap.2='53059'
  102. monthlen.leap.3='31'
  103. monthlen.leap.4='30'
  104. monthlen.leap.5='31'
  105. monthlen.leap.6='30'
  106. monthlen.leap.7='31'
  107. monthlen.leap.8='31'
  108. monthlen.leap.9='30'
  109. monthlen.leap.10='31'
  110. monthlen.leap.11='30'
  111. monthlen.leap.12='31'
  112. totdays.NORM.1 =   0
  113. totdays.NORM.2 =  31
  114. totdays.NORM.3 =  59
  115. totdays.NORM.4 =  90
  116. totdays.NORM.5 = 120
  117. totdays.NORM.6 = 151
  118. totdays.NORM.7 = 181
  119. totdays.NORM.8 = 212
  120. totdays.NORM.9 = 243
  121. totdays.NORM.10= 273
  122. totdays.NORM.11= 304
  123. totdays.NORM.12= 334
  124. totdays.LEAP.1 =   0
  125. totdays.LEAP.2 =  31
  126. totdays.LEAP.3 =  60
  127. totdays.LEAP.4 =  91
  128. totdays.LEAP.5 = 121
  129. totdays.LEAP.6 = 152
  130. totdays.LEAP.7 = 182
  131. totdays.LEAP.8 = 213
  132. totdays.LEAP.9 = 244
  133. totdays.LEAP.10= 274
  134. totdays.LEAP.11= 305
  135. totdays.LEAP.12= 335
  136. daynames = 'Monday Tuesday Wednesday Thursday Friday Saturday Sunday'
  137. monthnames ='January February March April May June July August September'
  138. monthnames = monthnames 'October November December'
  139. moon.0 = 'new'
  140. moon.1 = 'waxing half'
  141. moon.2 = 'full'
  142. moon.3 = 'waning half'
  143. lunation = 29.53059
  144. dayphase = 1 / lunation
  145. newphase = dayphase / 2
  146. waxphase = .25 + dayphase / 2
  147. fullphase = .5 + dayphase / 2
  148. wanephase = .75 + dayphase / 2
  149. return
  150.  
  151. tell:
  152. say en 'will query the date and return in an English form, and also'
  153. say '  give information about the phase of the moon.'
  154. say 'Call without any parameter to display the date, or with "PUSH"'
  155. say '  to push the date-string alone onto the Stack.'
  156. say 'Call with "(NODATE)" to give only the information about the'
  157. say '  phase of the moon.'
  158. say 'Call with "(NOPHASE)" to give only the date in an English form.'
  159. say
  160. return
  161.  
  162.