home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / COREL6 / SCRIPTS / NORMAL.CSC < prev    next >
Encoding:
Text File  |  1995-08-12  |  4.3 KB  |  133 lines

  1. REM Extracts day and year from a date variable.
  2. REM Normal.csc 12 July, 1995
  3.  
  4. REM This script takes the number value of a date variable, and extracts the year, month, day, hour, minute, seconds and weekday.
  5. REM It basically counts years from 1900 until it gets to the right year, then it counts months - etc.
  6. REM Changing the Testdate variable will change the day being normalized
  7.  
  8. DECLARE SUB normalizedate(BYVAL d AS DATE, BYREF i%, BYREF count&, BYREF year&)  'normalizedate for extracting month, day, year
  9. DECLARE SUB normalizetime(BYVAL td AS DATE, BYREF h%, BYREF m%, BYREF s%)  'normalizedate for extracting month, day, year
  10. DECLARE SUB getweekday(BYVAL wkd AS DATE, BYREF wkday%)
  11.  
  12. GLOBAL daysinmonth%(12)        'Global Array TO hold the days in each month.
  13.  
  14.  
  15. REM This is the date that gets passed
  16. DIM testdate as date        'The date being translated
  17. testdate = 34890.879            'the date being translated
  18.  
  19. DIM month$(12), weekday$(7)  'arrays to hold values
  20. DIM info%, days&, yr&        'Variables for passing be reference
  21.  
  22. month(1) = "January"        'stores the strings for the months
  23. month(2) = "February"
  24. month(3) = "March"
  25. month(4) = "April"
  26. month(5) = "May"
  27. month(6) = "June"
  28. month(7) = "July"
  29. month(8) = "August"
  30. month(9) = "September"
  31. month(10) = "October"
  32. month(11) = "November"
  33. month(12) = "December"
  34.  
  35. weekday(1) = "Monday"        'stores the strings for the weekday
  36. weekday(2) = "Tuesday"
  37. weekday(3) = "Wednesday"
  38. weekday(4) = "Thursday"
  39. weekday(5) = "Friday"
  40. weekday(6) = "Saturday"
  41. weekday(7) = "Sunday"
  42.  
  43. daysinmonth(1) = 31            'stores the number of days in each month
  44. daysinmonth(2) = 28            'febuary leap years taken into account later
  45. daysinmonth(3) = 31
  46. daysinmonth(4) = 30
  47. daysinmonth(5) = 31
  48. daysinmonth(6) = 30
  49. daysinmonth(7) = 31
  50. daysinmonth(8) = 31
  51. daysinmonth(9) = 30
  52. daysinmonth(10) = 31
  53. daysinmonth(11) = 30
  54. daysinmonth(12) = 31
  55.  
  56.  
  57. normalizedate testdate, info, days, yr        'calls the translate function
  58. normalizetime testdate, hour%, minute%, second%
  59. getweekday testdate, wday%
  60.  
  61. Hourstring = CSTR(hour)
  62. minutestring = CSTR(minute)
  63. Secondstring = CSTR(second)
  64.  
  65. IF LEN(Hourstring) = 1 THEN Hourstring = "0" + Hourstring
  66. IF LEN(Minutestring) = 1 THEN Minutestring = "0" + Minutestring
  67. IF LEN(Secondstring) = 1 THEN Secondstring = "0" + Secondstring
  68.  
  69. MESSAGE "The Time works out to be " + Hourstring + ":" + Minutestring + ":" + Secondstring
  70. MESSAGE "The Test date works out to be " + month(info) + STR(days) + "," + STR(yr)
  71. MESSAGE "The Test Date is a " + weekday(wday)
  72.  
  73. SUB normalizedate(d AS DATE, i%, count&, year&)            'translate SUB
  74.             'notice that values are changed by reference
  75.     DIM b AS BOOLEAN, leapyear AS BOOLEAN, numday%        'local variables
  76.     count& = d - 1     'temporary counter variable (-1 because dates count from dec. 31, 1899)
  77.     year = 1900        'initialise the year counter to 1900 (date 2)
  78.     numday = 365        'initiase number of days in a year
  79.     leapyear = false    'boolean for whether or not a leap year
  80.  
  81.     IF count <= numday THEN         'if count < numbers of days in this year, end loop
  82.         b = true    
  83.     END if
  84.  
  85.     DO WHILE b = false        'determines the year, by subtracting numday from count, and incrementing year
  86.         count = count - numday
  87.         year = year + 1
  88.         numday = 365        'reinitialise numday
  89.         leapyear = false    'reinitialise leapyear
  90.  
  91.         IF (year MOD 4 = 0 AND year MOD 100 <> 0) OR year MOD 400 = 0 THEN         'if leap year
  92.             numday = 366            'set numday and leapyear
  93.             leapyear = true
  94.         END IF
  95.         IF count <= numday THEN         'if count < numbers of days in this year, end loop
  96.             b = true    
  97.         END IF
  98.     LOOP
  99. i% = 1        'initialise index
  100. b = false        'reset loop variable
  101. IF leapyear THEN        'set days in month for feb.
  102.     daysinmonth(2) = 29
  103. END IF
  104.  
  105.     DO WHILE b = false    'determines the month, again by counting.
  106.         IF count <= daysinmonth(i) THEN 
  107.             b = true
  108.             EXIT DO
  109.         END IF
  110.         count = count - daysinmonth(i)
  111.     i = i + 1
  112.     LOOP
  113. END SUB
  114.  
  115. SUB normalizetime(td AS DATE, h%, m%, s%)
  116.     CONST ONEHOUR# = 1.0 /24
  117.     CONST ONEMINUTE# = 1.0/(24*60)
  118.     CONST ONESECOND# = 1.0/(24*60*60)
  119.     time1& = td - 0.5
  120.     td = td - time1        'remove the integer part of d
  121.     h% = (td / onehour) - 0.5
  122.     td = (td - h * onehour)
  123.     m% = (td / oneminute) - 0.5
  124.     td = td - m * oneminute
  125.     s% = (td /onesecond) - 0.5
  126. END SUB
  127.  
  128. SUB getweekday(wkd AS DATE, wkday%)
  129.     CONST offset = 6
  130.     weektemp& = wkd - 0.5 + offset
  131.     wkday = (weektemp MOD 7) + 1
  132. END SUB
  133.