home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / atrgf31.zip / dateshow.cmd < prev    next >
OS/2 REXX Batch file  |  1993-03-22  |  31KB  |  871 lines

  1. /*
  2. program: rgfshow.cmd
  3. type:    REXXSAA-OS/2, version 2.x
  4. purpose: explain and demo REXX-scripts
  5. version: 1.2
  6. date:    1991-05-20
  7.          1991-08-02
  8.          1992-06-01, RGF, introduced SysGetKey()
  9.          1993-03-22, RGF, show just DATERGF-related functions
  10. needs:   RxUtils loaded
  11.  
  12. author:  Rony G. Flatscher,
  13.          Wirtschaftsuniversität/Vienna
  14.          RONY@AWIWUW11.BITNET
  15.          rony@wu-wien.ac.at
  16.  
  17. remark:  this program makes extensive use of REXX' stems. If you wish
  18.          to add your own programs, follow the following steps:
  19.          1) Search last "toshow.0"-entry
  20.          2) Add another "toshow.0.x"-entry, where "x" is the preceeding
  21.             number incremented by one
  22.          3) Search last "toshow."-block
  23.          4) copy it (starting from the line containing "block" to the
  24.             end
  25.          5) change descriptions to your program
  26.          6) add at the end of this script your examples in procedure
  27.             form "YOUR_PROGRAM_NAME_EXTENSION:"
  28.          7) add SHOW_IT-statements
  29.             - if SHOW_IT has no arguments, a pause will be executed
  30.             - argument1: describes following example
  31.             - argument2: contains the PROGRAM-name with arguments (optional)
  32.             - argument3: contains a remark pertaining to example (optional)
  33.          8) If your program or REXX-procedure does not return a value, use
  34.             "SHOW_IT2" instead of "SHOW_IT"
  35.  
  36.  
  37. All rights reserved, copyrighted 1991, no guarantee that it works without
  38. errors, etc. etc.
  39.  
  40. donated to the public domain granted that you are not charging anything
  41. (money etc.) for it and derivates based upon it, as you did not write it,
  42. etc. if that holds you may bundle it with commercial programs too
  43.  
  44. you may freely distribute this program, granted that no changes are made
  45. to it and that the accompanying tutorial "RGFSHOW.CMD" is being distributed
  46. together with DATERGF.CMD, DATE2STR.CMD, ATRGF.CMD, TIMEIT.CMD
  47.  
  48. Please, if you find an error, post me a message describing it, I will
  49. try to fix and rerelease it to the net.
  50. */
  51.  
  52.  
  53. /* check whether RxFuncs are loaded, if not, load them */
  54. IF RxFuncQuery('SysLoadFuncs') THEN
  55. DO
  56.     /* load the load-function */
  57.     CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'       
  58.  
  59.     /* load the Sys* utilities */
  60.     CALL SysLoadFuncs                                                 
  61. END
  62.  
  63.  
  64. /* define toshow-description-subscripts */
  65. aha. = ''               /* set default value for stem to nothing = '' */
  66. aha.1 = 'rexx'
  67. aha.2 = 'description'
  68. aha.3 = 'comment'
  69. aha.4 = 'version'
  70. aha.5 = 'date'
  71. aha.6 = 'author'
  72. aha.7 = 'address'
  73. aha.8 = 'organization'
  74. aha.9 = 'country'
  75. aha.10 = 'rights'
  76. aha.11 = 'misc'
  77.  
  78.  
  79. toshow. = ''            /* set default value for stem to nothing = '' */
  80. i = 0
  81. toshow.0.1 = 1          /* index for DATERGF.CMD */
  82. toshow.0.2 = 2          /* index for DATE2STR.CMD */
  83. /*
  84. toshow.0.3 = 3          /* index for ATRGF.CMD */
  85. toshow.0.4 = 4          /* index for TIMEIT.CMD */
  86. */
  87.  
  88. /* DATERGF.CMD - block */
  89. i = i + 1
  90. toshow.i.rexx         = "DATERGF.CMD  - date/time conversions & arithmetics"
  91. toshow.i.description  = "comprehensive set for date/time conversion & arithmetics"
  92. toshow.i.comment      = "(accounts for change from Julian to Gregorian calendar in 1582)"
  93. toshow.i.version      = "1.3"
  94. toshow.i.date         = "1992/06/18"
  95. toshow.i.author       = "Rony G. Flatscher"
  96. toshow.i.address      = "RONY@AWIWUW11.BITNET --- or --- rony@wu-wien.ac.at"
  97. toshow.i.organization = "Wirtschaftsuniversität Wien (University of Economics Vienna)"
  98. toshow.i.country      = "Austria - heart of Europe"
  99. toshow.i.rights       = "Copyrighted (1991), all rights reserved"
  100. toshow.i.misc         = "donated to the public domain"
  101.  
  102. toshow.i.1            = " (1)   Show syntax"
  103. toshow.i.1.1          = "CALL DATERGF ?"
  104. toshow.i.2            = " (2)   Show conversions with sorted dates (YYYYMMDD)"
  105. toshow.i.2.1          = "CALL DATERGF_CONVERSIONS"
  106. toshow.i.3            = " (3)   Show arithmetics with sorted dates"
  107. toshow.i.3.1          = "CALL DATERGF_BASIC_CALCULATIONS"
  108. toshow.i.4            = " (4)   Show year related functions"
  109. toshow.i.4.1          = "CALL DATERGF_YEAR"
  110. toshow.i.5            = " (5)   Show month related functions"
  111. toshow.i.5.1          = "CALL DATERGF_MONTH"
  112. toshow.i.6            = " (6)   Show day related functions"
  113. toshow.i.6.1          = "CALL DATERGF_DAY"
  114. toshow.i.7            = " (7)   Show week related functions"
  115. toshow.i.7.1          = "CALL DATERGF_WEEK"
  116. toshow.i.8            = " (8)   Show quarter related functions"
  117. toshow.i.8.1          = "CALL DATERGF_QUARTER"
  118.  
  119. toshow.i.9            = " (9)   Show additional functions"
  120. toshow.i.9.1          = "CALL DATERGF_MISCELLANEOUS"
  121. toshow.i.10           = "(10)   Show examples with today's date"
  122. toshow.i.10.1         = "CALL DATERGF_EXAMPLES"
  123. toshow.i.11           = "(11)   SHOW ALL EXAMPLES supplied herein"
  124. toshow.i.11.1         = "CALL DATERGF_CONVERSIONS"
  125. toshow.i.11.2         = "CALL DATERGF_BASIC_CALCULATIONS"
  126. toshow.i.11.3         = "CALL DATERGF_YEAR"
  127. toshow.i.11.4         = "CALL DATERGF_MONTH"
  128. toshow.i.11.5         = "CALL DATERGF_DAY"
  129. toshow.i.11.6         = "CALL DATERGF_WEEK"
  130. toshow.i.11.7         = "CALL DATERGF_QUARTER"
  131. toshow.i.11.8         = "CALL DATERGF_MISCELLANEOUS"
  132. toshow.i.11.9         = "CALL DATERGF_EXAMPLES"
  133. toshow.i.11.10        = "CALL DATERGF_STORY_DATES"
  134. toshow.i.12           = "(12)   A little story about dates ..."
  135. toshow.i.12.1         = "CALL DATERGF_STORY_DATES"
  136. /* end of DATERGF.CMD - block */
  137.  
  138.  
  139. /* DATE2STR.CMD - block */
  140. i = i + 1
  141. toshow.i.rexx         = "DATE2STR.CMD - format date into string pattern"
  142. toshow.i.description  = "allow formatting of sorted date into string pattern"
  143. toshow.i.comment      = "uses DATERGF.CMD"
  144. toshow.i.version      = "1.1"
  145. toshow.i.date         = "1992/06/18"
  146. toshow.i.author       = "Rony G. Flatscher"
  147. toshow.i.address      = "RONY@AWIWUW11.BITNET --- or --- rony@wu-wien.ac.at"
  148. toshow.i.organization = "Wirtschaftsuniversität Wien (University of Economics Vienna)"
  149. toshow.i.country      = "Austria - heart of Europe"
  150. toshow.i.rights       = "Copyrighted (1991), all rights reserved"
  151. toshow.i.misc         = "donated to the public domain"
  152.  
  153. toshow.i.1            = " (1)   Show syntax"
  154. toshow.i.1.1          = "CALL DATE2STR ?"
  155. toshow.i.2            = " (2)   Show examples"
  156. toshow.i.2.1          = "CALL DATE2STR_EXAMPLES"
  157. /* end of DATE2STR.CMD - block */
  158.  
  159.  
  160. /* ATRGF.CMD - block */
  161. i = i + 1
  162. toshow.i.rexx         = "ATRGF.CMD    - execute command later"
  163. toshow.i.description  = "allows for (repeating) executions of given command at given time"
  164. toshow.i.comment      = "uses DATERGF.CMD, DATE2STR.CMD, SLEEP.EXE"
  165. toshow.i.version      = "1.1"
  166. toshow.i.date         = "1991/08/02"
  167. toshow.i.author       = "Rony G. Flatscher"
  168. toshow.i.address      = "RONY@AWIWUW11.BITNET --- or --- rony@wu-wien.ac.at"
  169. toshow.i.organization = "Wirtschaftsuniversität Wien (University of Economics Vienna)"
  170. toshow.i.country      = "Austria - heart of Europe"
  171. toshow.i.rights       = "Copyrighted (1991), all rights reserved"
  172. toshow.i.misc         = "donated to the public domain"
  173.  
  174. toshow.i.1            = " (1)   Show syntax"
  175. toshow.i.1.1          = "CALL ATRGF ?"
  176. toshow.i.2            = " (2)   Show examples, executing command the next possible time"
  177. toshow.i.2.1          = "CALL ATRGF_AS_FAST_AS_POSSIBLE"
  178. toshow.i.3            = " (3)   Show examples, executing command the next given day or date"
  179. toshow.i.3.1          = "CALL ATRGF_NEXT"
  180. toshow.i.4            = " (4)   Show examples, executing command on EVERY given day or date"
  181. toshow.i.4.1          = "CALL ATRGF_EVERY"
  182. toshow.i.5            = " (5)   Show examples, executing command EVERYTIME INTERVAL passed by"
  183. toshow.i.5.1          = "CALL ATRGF_INTERVAL"
  184. toshow.i.6            = " (6)   SHOW ALL EXAMPLES supplied herein"
  185. toshow.i.6.1          = "CALL ATRGF_AS_FAST_AS_POSSIBLE"
  186. toshow.i.6.2          = "CALL ATRGF_NEXT"
  187. toshow.i.6.3          = "CALL ATRGF_EVERY"
  188. toshow.i.6.4          = "CALL ATRGF_INTERVAL"
  189. /* end of ATRGF.CMD - block */
  190.  
  191. /* TIMEIT.CMD - block */
  192. i = i + 1
  193. toshow.i.rexx         = "TIMEIT.CMD   - time program or REXX-script"
  194. toshow.i.description  = "allows for timing the duration of a program"
  195. toshow.i.comment      = "uses DATE2STR.CMD"
  196. toshow.i.version      = "1.1"
  197. toshow.i.date         = "1991/08/02"
  198. toshow.i.author       = "Rony G. Flatscher"
  199. toshow.i.address      = "RONY@AWIWUW11.BITNET --- or --- rony@wu-wien.ac.at"
  200. toshow.i.organization = "Wirtschaftsuniversität Wien (University of Economics Vienna)"
  201. toshow.i.country      = "Austria - heart of Europe"
  202. toshow.i.rights       = "Copyrighted (1991), all rights reserved"
  203. toshow.i.misc         = "donated to the public domain"
  204.  
  205. toshow.i.1            = " (1)   Show syntax"
  206. toshow.i.1.1          = "CALL TIMEIT ?"
  207. toshow.i.2            = " (2)   Show examples"
  208. toshow.i.2.1          = "CALL TIMEIT_EXAMPLES"
  209. /* end of TIMEIT.CMD - block */
  210.  
  211.  
  212. /* Start of program */
  213. spaces = RIGHT('', 10)
  214. DO FOREVER
  215.    i = 1       /* show main menu */
  216.    SAY
  217.    SAY '==============================================================================='
  218.    SAY
  219.    DO WHILE toshow.0.i <> ''
  220.       tmp = toshow.0.i
  221.       SAY spaces "("i")" toshow.tmp.rexx
  222.       i = i + 1
  223.    END
  224.    i = i - 1
  225.  
  226.    SAY
  227.    SAY spaces "Enter choice: 1 -" i "(0 to quit demo-program)"
  228.    DO FOREVER
  229.       PULL answer
  230.       IF TRANSLATE(answer) = "Q" THEN EXIT
  231.       IF answer >= 0 & answer <= i THEN LEAVE
  232.       ELSE BEEP(1000,10)
  233.    END
  234.  
  235.    IF answer = 0 THEN LEAVE
  236.  
  237.  
  238.    DO FOREVER   /* show appropriate submenu */
  239.       spaces = RIGHT('', 10)
  240.       SAY
  241.       SAY '=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--='
  242.       SAY
  243.       SAY '     'toshow.answer.rexx':'
  244.       SAY
  245.       SAY spaces "(99)   About" WORD(toshow.answer.rexx, 1) "..."
  246.       i = 1
  247.       DO WHILE toshow.answer.i <> ''
  248.          SAY spaces toshow.answer.i
  249.          i = i + 1
  250.       END
  251.       i = i - 1
  252.  
  253.       SAY
  254.       SAY spaces "Enter choice: 1 -" i", 99 (0 to end)"
  255.  
  256.       DO FOREVER
  257.          PULL answer2
  258.          IF TRANSLATE(answer2) = "Q" THEN EXIT
  259.  
  260.          IF (answer2 >= 0 & answer2 <= i) | answer2 = 99 THEN LEAVE
  261.          ELSE BEEP(1000,10)
  262.       END
  263.  
  264.       IF answer2 = 0 THEN LEAVE
  265.       ELSE IF answer2 = 99 THEN
  266.       DO  /* show author-stuff */
  267.          i = 1
  268.          DO WHILE aha.i <> ''
  269.             INTERPRET "tmp = toshow.answer."||aha.i
  270.             IF tmp <> '' THEN SAY RIGHT(aha.i,12)':' tmp
  271.             i = i + 1
  272.          END
  273.          SAY
  274.  
  275.          SAY RIGHT("Hit a key to continue, q to quit immediately.", 79, "=")
  276.          tmp = TRANSLATE(SysGetKey("noecho"))
  277.          IF tmp = "Q" THEN EXIT    /* q for quit was pressed */
  278.       END
  279.       ELSE /* show examples */
  280.       DO
  281.           i = 1
  282.           DO WHILE toshow.answer.answer2.i <> ''
  283.              INTERPRET toshow.answer.answer2.i
  284.              i = i + 1
  285.           END
  286.       END
  287.    END
  288. END
  289. SAY "end of RGFSHOW.CMD --------------"
  290. EXIT
  291.  
  292. /*****************************************************************************/
  293. /*****************************************************************************/
  294.  
  295.  
  296. /**********************/
  297. /* DATERGF - examples */
  298. /**********************/
  299.  
  300.  
  301. DATERGF_CONVERSIONS:
  302.  
  303. CALL  SHOW_IT 'Calculate days since 0000/01/01 (== 1. day == 1) and the reverse'
  304.  
  305. CALL  SHOW_IT '- calculate days:',,
  306.               'DATERGF("00000101")'
  307. CALL  SHOW_IT '- calculate days:',,
  308.               'DATERGF("19940301")'
  309. CALL SHOW_IT
  310.  
  311.  
  312. CALL  SHOW_IT '- calculate days:',,
  313.               'DATERGF("99991231")'
  314. CALL  SHOW_IT '- calculate days based on 0000/01/01 (= 1. day == 1) with optional time:',,
  315.               'DATERGF("19940301 16:45:01")',,
  316.               '(728356. day, time fraction .6979...)'
  317. CALL  SHOW_IT '- calculate sorted date (with optional time) from days[.fraction]:',,
  318.               'DATERGF("728356.69792824074074", "S")',,
  319.               '(produces sorted date and optional time, flag: "S")'
  320. CALL SHOW_IT
  321.  
  322.  
  323.  
  324. CALL  SHOW_IT 'Transform sorted date into Julian date and the reverse'
  325.  
  326. CALL  SHOW_IT '- transform given sorted date into Julian date:',,
  327.               'DATERGF("19940301","J")',,
  328.               '(60th day in 1994, flag: "J")'
  329. CALL  SHOW_IT '- transform given Julian date into sorted date (Julian Reversed):',,
  330.               'DATERGF("1994060","JR")',,
  331.               '(1st March in 1994, flag: "JR")'
  332. CALL SHOW_IT
  333.  
  334.  
  335. CALL  SHOW_IT 'Transform time into decimal fraction and the reverse'
  336.  
  337. CALL  SHOW_IT '- transform given time into decimal fraction:',,
  338.               'DATERGF("5:45:01pm","F")',,
  339.               '(flag: "F")'
  340. CALL  SHOW_IT '- transform given fraction into 24hour-time (Fraction Reversed):',,
  341.               'DATERGF("0.739594907407407","FR")',,
  342.               '(note: resulting time is 24hour-format, flag: "FR")'
  343. CALL SHOW_IT
  344.  
  345.  
  346.  
  347. CALL  SHOW_IT 'Calculate seconds based on given days with optional decimal time fraction'
  348.  
  349. CALL  SHOW_IT '- calculate seconds from days[.fraction]:',,
  350.               'DATERGF("1.739594907407407","SEC")'
  351.  
  352. CALL  SHOW_IT '- calculate days[.fraction] from seconds (Seconds Reversed):',,
  353.               'DATERGF("150301","SECR")'
  354.  
  355. CALL SHOW_IT
  356.  
  357. RETURN
  358. /*****************************************************************************/
  359.  
  360.  
  361. DATERGF_BASIC_CALCULATIONS:
  362.  
  363. /* Calculations with sorted dates */
  364. CALL  SHOW_IT 'Calculations on sorted dates:'
  365.  
  366. CALL  SHOW_IT '- difference between two sorted dates (optional time):',,
  367.               'DATERGF("19940301 12:00","-S", "19940201")',,
  368.               '(difference between both dates is 28.5 days)'
  369. CALL SHOW_IT
  370.  
  371. CALL  SHOW_IT '- difference between sorted date and a given amount of days:',,
  372.               'DATERGF("19940301 12:00", "-", "28.5")',,
  373.               '(note: result without time, as time = 00:00:00)'
  374. CALL  SHOW_IT '- addition between sorted date and a given amount of days:',,
  375.               'DATERGF("19940201", "+", "28.5")'
  376. CALL SHOW_IT
  377.  
  378. RETURN
  379. /*****************************************************************************/
  380.  
  381.  
  382. DATERGF_MISCELLANEOUS:
  383.  
  384. CALL  SHOW_IT 'Miscellaneous functions for sorted dates'
  385.  
  386. CALL  SHOW_IT '- check date (if valid, return sorted date):',,
  387.               'DATERGF("19920229","C")',,
  388.               '(valid, because it is a leap-year)'
  389. CALL SHOW_IT
  390.  
  391. CALL  SHOW_IT '- check date:',,
  392.               'DATERGF("19920230","C")',,
  393.               '(invalid)'
  394. CALL  SHOW_IT '- test if leap-year:',,
  395.               'DATERGF("19920715","L")',,
  396.               '(leap-year)'
  397. CALL SHOW_IT
  398.  
  399. CALL  SHOW_IT '- test if leap-year:',,
  400.               'DATERGF("19931105","L")',,
  401.               '(not a leap-year)'
  402. CALL SHOW_IT
  403.  
  404. RETURN
  405. /*****************************************************************************/
  406.  
  407.  
  408.  
  409. DATERGF_YEAR:
  410.  
  411. CALL  SHOW_IT 'Year related functions for sorted dates'
  412.  
  413. CALL  SHOW_IT '- check sorted date and return year:',,
  414.               'DATERGF("19940715","Y")'
  415. CALL  SHOW_IT '- get first date of year (Year Begin):',,
  416.               'DATERGF("19940715","YB")'
  417. CALL SHOW_IT
  418.  
  419. CALL  SHOW_IT '- get last date of year (Year End):',,
  420.               'DATERGF("19940715 8:05:01pm","YE")'
  421. CALL  SHOW_IT '- get first date of year and add 182 days and 12 hours:',,
  422.               'DATERGF("19940715","YB","182.5")'
  423. CALL SHOW_IT
  424.  
  425. CALL  SHOW_IT '- return the semester of the given date (1. or 2. half of year):',,
  426.               'DATERGF("19940715","HY")'
  427. CALL  SHOW_IT '- return the beginning date of this date''s half-year (Half''s Year Begin):',,
  428.               'DATERGF("19940715","HYB")'
  429. CALL SHOW_IT
  430.  
  431. CALL  SHOW_IT '- return the ending date of this date''s half-year (Half''s Year End):',,
  432.               'DATERGF("19940715","HYE")'
  433. CALL  SHOW_IT '- return the beginning date of this date''s half-year, add 120.3333333333 days:',,
  434.               'DATERGF("19940715","HYB", "120.3333333333")'
  435. CALL SHOW_IT
  436.  
  437. RETURN
  438. /*****************************************************************************/
  439.  
  440.  
  441. DATERGF_MONTH:
  442.  
  443. CALL  SHOW_IT 'Month related functions for sorted dates'
  444.  
  445. CALL  SHOW_IT '- check sorted date and return month:',,
  446.               'DATERGF("19940715","M")'
  447. CALL  SHOW_IT '- return monthname:',,
  448.               'DATERGF("19940715","MN")'
  449. CALL SHOW_IT
  450.  
  451. CALL  SHOW_IT '- get first date of month (Month begin):',,
  452.               'DATERGF("19940715","MB")'
  453. CALL  SHOW_IT '- get last date of month (Month end):',,
  454.               'DATERGF("19920215","ME")',,
  455.               '(leap-year, therefore 29 days)'
  456. CALL  SHOW_IT '- get last date of month and add 14 days:',,
  457.               'DATERGF("19920215","ME","14")'
  458. CALL SHOW_IT
  459.  
  460. RETURN
  461. /*****************************************************************************/
  462.  
  463.  
  464. DATERGF_DAY:
  465.  
  466. CALL  SHOW_IT 'Day related functions for sorted dates'
  467.  
  468. CALL  SHOW_IT '- check date and return day:',,
  469.               'DATERGF("19940715","D")'
  470. CALL SHOW_IT
  471.  
  472. CALL  SHOW_IT '- return dayname:',,
  473.               'DATERGF("19940715","DN")'
  474. CALL  SHOW_IT '- return weekdayindex (Monday = 1, ..., Sunday = 7):',,
  475.               'DATERGF("19940715","DI")',,
  476.               '(Fridays will allways return 5)'
  477. CALL SHOW_IT
  478.  
  479. RETURN
  480. /*****************************************************************************/
  481.  
  482.  
  483. DATERGF_WEEK:
  484.  
  485. CALL  SHOW_IT 'Week of year related functions for sorted dates'
  486.  
  487. CALL  SHOW_IT '- return week of year:',,
  488.               'DATERGF("19940715","W")'
  489. CALL  SHOW_IT '- return week of year:',,
  490.               'DATERGF("19940105","W")'
  491. CALL  SHOW_IT '- Attention for the following ''exotic'' weeks:'
  492. CALL SHOW_IT
  493.  
  494. CALL  SHOW_IT '- return week of year:',,
  495.               'DATERGF("19921231","W")',,
  496.               '(53. week is CORRECT !!!)'
  497. CALL  SHOW_IT '- return week of year:',,
  498.               'DATERGF("19930101","W")',,
  499.               '(53. week is CORRECT !!!)'
  500. CALL  SHOW_IT '- return week of year:',,
  501.               'DATERGF("15821231","W")',,
  502.               '(1582 had 10 days less, hence 51. week)'
  503. CALL SHOW_IT
  504.  
  505. CALL  SHOW_IT '- return the date for Monday of this date''s week (Week Begin = Monday):',,
  506.               'DATERGF("19940715","WB")',,
  507.               '(Date for Monday)'
  508. CALL  SHOW_IT '- return the date for Sunday of this date''s week (Week End = Sunday):',,
  509.               'DATERGF("19940715","WE")',,
  510.               '(Date for Sunday)'
  511. CALL SHOW_IT
  512.  
  513. CALL  SHOW_IT '- return the date for Friday of this date''s week (add 4 to Monday):',,
  514.               'DATERGF("19940715","WB", "4")',,
  515.               '(Date for Friday, same as date itself)'
  516. CALL  SHOW_IT '- return the date for Saturday of this date''s week (add 5 to Monday):',,
  517.               'DATERGF("19940715","WB", "5")',,
  518.               '(Date for Saturday)'
  519. CALL  SHOW_IT '- return the date for last week''s Thursday (subtract 4 from Monday):',,
  520.               'DATERGF("19940715","WB", "-4")',,
  521.               '(Date for last week''s Thursday)'
  522. CALL SHOW_IT
  523.  
  524. RETURN
  525. /*****************************************************************************/
  526.  
  527.  
  528. DATERGF_QUARTER:
  529.  
  530. CALL  SHOW_IT 'Quarter of year related functions for sorted dates'
  531.  
  532. CALL  SHOW_IT '- return the quarter of the given date:',,
  533.               'DATERGF("19940715","Q")'
  534. CALL  SHOW_IT '- return the beginning date of this date''s quarter (Quarter Begin):',,
  535.               'DATERGF("19940715","QB")'
  536. CALL SHOW_IT
  537.  
  538. CALL  SHOW_IT '- return the ending date of this date''s quarter (Quarter End):',,
  539.               'DATERGF("19940715","QE")'
  540. CALL  SHOW_IT '- return the ending date of this date''s quarter and add 45 days:',,
  541.               'DATERGF("19940715","QE", "45")'
  542. CALL SHOW_IT
  543.  
  544. RETURN
  545. /*****************************************************************************/
  546.  
  547.  
  548. DATERGF_EXAMPLES:
  549.  
  550. CALL  SHOW_IT 'Miscellaneous EXAMPLES of DATERGF() with today''s date:'
  551.  
  552. CALL  SHOW_IT '- today''s date is:',,
  553.               'DATE("S")',,
  554.               '("DATE" is a REXX-built-in-function)'
  555. CALL  SHOW_IT '- return today''s dayname:',,
  556.               'DATERGF(DATE("S"),"DN")'
  557. CALL SHOW_IT
  558.  
  559. CALL  SHOW_IT '- return today''s dayindex (1 = Monday, ..., 7 = Sunday):',,
  560.               'DATERGF(DATE("S"),"DI")'
  561. CALL  SHOW_IT '- return today''s week of year:',,
  562.               'DATERGF(DATE("S"),"W")'
  563. CALL  SHOW_IT '- return present quarter:',,
  564.               'DATERGF(DATE("S"),"Q")'
  565. CALL SHOW_IT
  566.  
  567. CALL  SHOW_IT '- return today''s date in Julian format:',,
  568.               'DATERGF(DATE("S"),"J")'
  569. CALL  SHOW_IT '- return number of days elapsed since the beginning of this year:',,
  570.               'DATERGF(DATE("S"),"-S", DATERGF(DATE("S"),"YB"))',,
  571.               '(note the 1 day difference to Julian date!)'
  572. CALL SHOW_IT
  573.  
  574. CALL  SHOW_IT '- return number of days elapsed since the beginning of this quarter:',,
  575.               'DATERGF(DATE("S"),"-S", DATERGF(DATE("S"),"QB"))'
  576. CALL  SHOW_IT '- return the Monday, two weeks ago:',,
  577.               'DATERGF(DATE("S"),"WB", "-14")',,
  578.               '(get Monday of this week and subtract 14 days)'
  579.  
  580. CALL SHOW_IT
  581.  
  582. RETURN
  583. /*****************************************************************************/
  584.  
  585. DATERGF_STORY_DATES:
  586.  
  587.  
  588. SAY 'A little story about dates ...'
  589. SAY '=============================='
  590. SAY
  591. SAY 'Men allways tried to measure time.  In the beginning the best way to measure'
  592. SAY 'it seemed to have been counting the days between two full moons (29,5306'
  593. SAY 'days).  Then people started to count the number of full moons in order to'
  594. SAY 'find the number which comprised a full year.  They alternatively used'
  595. SAY '29 and 30 days for a moon-month. A full year consisted of six 29 day-months '
  596. SAY 'and six 30 day-months giving a total of 354 days per moon-year.'
  597. SAY
  598. SAY 'As a true sun-year lasts 365 days (actually 365 days and 5:48:46) the'
  599. SAY 'moon-year was off by 11 days.  Therefore different rules applied to adjust'
  600. SAY 'to the sun-year by adding sometimes a thirteenth month to a month-year. The'
  601. SAY 'Roman tax system was based on moon-months, so they had to pay more taxes in'
  602. SAY 'moon-years consisting of 13 months (some think that therefore the Romans'
  603. SAY 'thought that number 13 was one that drew bad luck).'
  604. SAY
  605. SAY 'The moon-year was used by most of the ancient peoples, e.g. Babylonians,'
  606. SAY 'Jews, Greek, Romans, Japanese (until 1873 !), Chinese (until 1911 !) etc.'
  607. SAY
  608.  
  609. CALL SHOW_IT
  610.  
  611. SAY 'The Egyptians were using 365 days for a year quiet early.  As the correct'
  612. SAY 'time for the earth to turn around the sun is about 365,25 days the Egyptian'
  613. SAY 'sun-year was off by one day every four years.  238 B.C.  they started to'
  614. SAY 'introduce a leap-year every four years to correct the situation.'
  615. SAY
  616. SAY 'Julius Gaius Caesar introduced the Egyptian sun-year with correcting'
  617. SAY 'leap-years every four years.  This new calendar was called the'
  618. SAY 'Julian Calendar thereafter.'
  619. SAY
  620. SAY 'As mentioned above it takes exactly 365 days and 5:48:46 for the earth to'
  621. SAY 'turn around the sun once and NOT 365 days and 6:00:00 as is implied by'
  622. SAY '365,25 days. Therefore the Julian Calendar caused an error if it was used'
  623. SAY 'for centuries as it assumed 11 minutes and 14 seconds more than was correct.'
  624. SAY
  625.  
  626. CALL SHOW_IT
  627.  
  628. SAY 'In 1582 the error in the Julian Calendar accounted already for 10 whole'
  629. SAY 'days.  The Roman Catholic Pope Gregor XIII therefore had the Julian Calendar'
  630. SAY 'corrected by'
  631. SAY
  632. SAY '        - skipping 10 days in 1582 (4. October was followed by the 15.),'
  633. SAY '        - changing the rule for leap-years: from then on every year'
  634. SAY '          dividable without a rest by 4 was a leap-year (like the Julian'
  635. SAY '          Calendar) EXCEPT for whole centuries which are not dividable'
  636. SAY '          without a rest by 400 (i.e.  1700, 1800, 1900, 2100 etc.  are not'
  637. SAY '          leap-years whereas 1600, 2000, 2400 etc. ARE leap-years).'
  638. SAY
  639. SAY 'This new calendar is called Gregorian Calendar.'
  640. SAY
  641. SAY 'As it was a Roman Catholic pope who devised this change it took quite a long'
  642. SAY 'time for others to adapt it. E.g. the German Protestants adapted it in 1700,'
  643. SAY 'the Great Britains in 1752, Russia after World War I (including some Balkan'
  644. SAY 'states).'
  645. SAY
  646. SAY 'Still the Gregorian Calendar will be off by one day every 3333 years.'
  647. SAY
  648.  
  649. CALL SHOW_IT
  650.  
  651. SAY 'The most correct ancient sun-year calendar known today is a Middle American'
  652. SAY 'one, stemming from the ancient Olmeks which will be correct for appr. 6000'
  653. SAY 'years.'
  654. SAY
  655. SAY '--- end of an otherwise endless story ...'
  656. SAY
  657.  
  658. CALL SHOW_IT
  659.  
  660. RETURN
  661. /*****************************************************************************/
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668. /*********************/
  669. /* DATE2STR-examples */
  670. /*********************/
  671.  
  672.  
  673. DATE2STR_EXAMPLES:
  674.  
  675. CALL  SHOW_IT 'Standard delimiter (%):',,
  676.               'DATE2STR("19940301","USA: %mm/%dd/%yyyy = %dddd (month = %mmmm)")',,
  677.               '(USA-style)'
  678. CALL  SHOW_IT 'Standard delimiter (%):',,
  679.               'DATE2STR("19940106","%d. %m. %yyyy = %j. day in %yyyy and %w. week!")'
  680. CALL  SHOW_IT 'Standard delimiter (%):',,
  681.               'DATE2STR("19930101","%mm/%dd/%yy = %ddd %w. week!")',,
  682.               '(53. week IS CORRECT for this year !!)'
  683. CALL SHOW_IT
  684.  
  685. CALL  SHOW_IT 'Delimiter: "#"',,
  686.               'DATE2STR("29940521","USA: #m/#dd/#yyyy = #DDD (month = #MMMM)","#")',,
  687.               '(Delimiter: #, USA-style)'
  688. CALL  SHOW_IT 'Delimiter: "\"',,
  689.               'DATE2STR("19960301","Austria: \d. \m. \yy = \jjj. day in \yyyy","\")',,
  690.               '(Delimiter: \, leap year!)'
  691. CALL SHOW_IT
  692.  
  693. RETURN
  694. /*****************************************************************************/
  695.  
  696.  
  697.  
  698. /********************/
  699. /* TIMEIT-examples  */
  700. /********************/
  701.  
  702.  
  703. TIMEIT_EXAMPLES:
  704.  
  705. CALL  SHOW_IT2 'Time the duration of SLEEP.EXE (3 seconds to sleep):',,
  706.                'TIMEIT SLEEP 3000 ?'
  707. CALL SHOW_IT
  708.  
  709. CALL  SHOW_IT2 'Time the duration of the listing of *.SYS-files on drive C: and the waiting time until you press a key to continue:',,
  710.                'TIMEIT DIR C:\*.sys & PAUSE'
  711. CALL SHOW_IT
  712.  
  713. CALL  SHOW_IT2 'Time the duration of the REXX-script ATRGF.CMD:',,
  714.                'TIMEIT ATRGF /W /I:00:01 @echo I''ll be back in a minute...'
  715. CALL SHOW_IT
  716.  
  717. RETURN
  718. /*****************************************************************************/
  719.  
  720. /********************/
  721. /* ATRGF-examples  */
  722. /********************/
  723.  
  724. ATRGF_AS_FAST_AS_POSSIBLE:
  725.  
  726. CALL  SHOW_IT3 'Execute the DIR-command at coming midnight in its own window:',,
  727.                'ATRGF /W 00:00 DIR C:\*.*'
  728.  
  729. CALL SHOW_IT
  730.  
  731. CALL  SHOW_IT3 'Execute the DIR-command at 11:45pm, as early as possible:',,
  732.                'ATRGF /W 11:45pm DIR C:\*.*'
  733. CALL SHOW_IT
  734.  
  735. RETURN
  736. /*****************************************************************************/
  737.  
  738. ATRGF_NEXT:
  739.  
  740. CALL  SHOW_IT3 'Start the backup-procedure next sunday at 14:30:',,
  741.                'ATRGF /W 14:30 /NE:SU back_it_up',,
  742.                '(BACK_IT_UP would be executed if it existed)'
  743.  
  744. CALL SHOW_IT
  745.  
  746. CALL  SHOW_IT3 'Start the backup-procedure on the last day of every month (31) at 14:30:',,
  747.                'ATRGF /W 14:30 /NE:31 back_it_up',,
  748.                '(BACK_IT_UP would be executed if it existed)'
  749.  
  750. CALL SHOW_IT
  751.  
  752. RETURN
  753. /*****************************************************************************/
  754.  
  755.  
  756. ATRGF_EVERY:
  757.  
  758. CALL  SHOW_IT3 'Start the backup-procedure Monday thru Friday at 14:30:',,
  759.                'ATRGF /W 14:30 /E:MO-FR back_it_up',,
  760.                '(BACK_IT_UP would be executed if it existed)'
  761.  
  762. CALL SHOW_IT
  763.  
  764. CALL  SHOW_IT3 'Start the backup-procedure on every 1st, 2nd, 3rd, 15th and last day in month (31), additionally on every friday at 14:30:',,
  765.                'ATRGF /W 14:30 /E:15,31-1,FR-SA back_it_up',,
  766.                '(BACK_IT_UP would be executed if it existed)'
  767.  
  768. CALL SHOW_IT
  769.  
  770. CALL  SHOW_IT3 'Test ATRGF with above example and show invocation dates:',,
  771.                'ATRGF /W /T 14:30 /E:15,31-1,FR-SA back_it_up',,
  772.                '(BACK_IT_UP would be executed if it existed)'
  773.  
  774. CALL SHOW_IT
  775.  
  776. RETURN
  777. /*****************************************************************************/
  778.  
  779.  
  780. ATRGF_INTERVAL:
  781.  
  782. CALL  SHOW_IT3 'Echo the message every minute:',,
  783.                "ATRGF /W /I:00:01 @ECHO HI! I'll be back in a minute... "
  784.  
  785. CALL SHOW_IT
  786.  
  787. CALL  SHOW_IT3 'Test-mode: interval every 4 hours and 45 minutes:',,
  788.                "ATRGF /W /T /I:04:45 @echo I'll be back in a minute..."
  789.  
  790. CALL SHOW_IT
  791.  
  792. CALL  SHOW_IT3 'Start the backup-procedure, starting at midnight, every 6 hours:',,
  793.                'ATRGF /W 00:00 /I:06:00 back_it_up',,
  794.                '(BACK_IT_UP would be executed every 6 hours, starting at midnight, if it existed)'
  795.  
  796. CALL SHOW_IT
  797.  
  798. CALL  SHOW_IT3 'Test-mode: interval starting at midnight, every 6 hours:',,
  799.                'ATRGF /W /T 00:00 /I:06:00 back_it_up',,
  800.                '(Test-mode: BACK_IT_UP would be executed every 6 hours, starting at midnight, if it existed)'
  801.  
  802. CALL SHOW_IT
  803.  
  804. RETURN
  805. /*****************************************************************************/
  806.  
  807.  
  808.  
  809. /*****************************************************************************/
  810. /* show example, execute it, show result */
  811. SHOW_IT:
  812.     IF ARG() = 0 THEN   /* no arguments ? */
  813.     DO
  814.        SAY RIGHT("Hit a key to continue, q to quit immediately.", 79, "=")
  815.        tmp = TRANSLATE(SysGetKey("noecho"))
  816.  
  817.        IF tmp = "Q" THEN EXIT    /* q for quit was pressed */
  818.  
  819.        BEEP(100,3)
  820.        PARSE PULL tmp
  821.        RETURN
  822.     END
  823.  
  824.     SAY
  825.     SAY ARG(1)                                  /* header info */
  826.     IF ARG(2) <> '' THEN DO
  827.        SAY
  828.        SAY '      'ARG(2)                       /* show example */
  829.        INTERPRET 'A = 'ARG(2)                   /* execute example */
  830.        SAY
  831.        SAY '      result: "'A'" 'ARG(3)         /* show result */
  832.     END
  833.     SAY
  834.     RETURN
  835.  
  836. SHOW_IT2:       /* execute programs and REXX-procedures which do not return values */
  837.     SAY
  838.     SAY ARG(1)                                  /* header info */
  839.     IF ARG(2) <> '' THEN DO
  840.        SAY
  841.        SAY '      'ARG(2)                       /* show example */
  842.        '@CALL 'ARG(2)                           /* execute example */
  843.        SAY
  844.        IF ARG() > 2 THEN
  845.        DO
  846.           SAY '      'ARG(3)                    /* show comment */
  847.           SAY
  848.        END
  849.     END
  850.     SAY
  851.     RETURN
  852.  
  853.  
  854. SHOW_IT3:       /* execute programs and REXX-procedures which do not return values */
  855.     SAY
  856.     SAY ARG(1)                                  /* header info */
  857.     IF ARG(2) <> '' THEN DO
  858.        SAY
  859.        SAY '      'ARG(2)                       /* show example */
  860.        '@CALL ' ARG(2)                          /* execute example */
  861.        SAY
  862.        IF ARG() > 2 THEN
  863.        DO
  864.           SAY '      'ARG(3)                    /* show comment */
  865.           SAY
  866.        END
  867.     END
  868.     SAY
  869.     RETURN
  870.  
  871.