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