home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / rkrmsrc / resources / read_battclock.e < prev    next >
Text File  |  1977-12-31  |  2KB  |  64 lines

  1. -> Read_BattClock.e
  2. ->
  3. -> Example of reading the BattClock and converting its output to a useful
  4. -> measure of time by calling the Amiga2Date() utility function.
  5.  
  6. OPT PREPROCESS
  7.  
  8. -> E-Note: E does not (as of v3.1a) support Resources in the conventional way
  9. MODULE 'other/battclock',  -> E-Note: swapping these two trips a bug in EC v3.1a
  10.        'utility',
  11.        'resources/battclock',
  12.        'utility/date'
  13.  
  14. ENUM ERR_NONE, ERR_LIB, ERR_RES
  15.  
  16. RAISE ERR_LIB IF OpenLibrary()=NIL,
  17.       ERR_RES IF OpenResource()=NIL
  18.  
  19. PROC main() HANDLE
  20.   DEF days:PTR TO LONG, months:PTR TO LONG, ampm,
  21.       amigaTime, myClock:clockdata
  22.   days:=['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
  23.          'Friday', 'Saturday']
  24.   months:=['January', 'February', 'March', 'April', 'May', 'June',
  25.            'July', 'August', 'September', 'October', 'November', 'December']
  26.  
  27.   utilitybase:=OpenLibrary('utility.library', 33)
  28.   battclockbase:=OpenResource(BATTCLOCKNAME)
  29.  
  30.   -> Get number of seconds till now
  31.   amigaTime:=readBattClock()
  32.  
  33.   -> Convert to a ClockData structure
  34.   Amiga2Date(amigaTime, myClock)
  35.  
  36.   WriteF('\nRobin, tell everyone the BatDate and BatTime')
  37.  
  38.   -> Print the Date
  39.   WriteF('\n\nOkay Batman, the BatDate is ')
  40.   WriteF('\s, \s \d, \d', days[myClock.wday], months[myClock.month-1],
  41.                           myClock.mday, myClock.year)
  42.  
  43.   -> Convert military time to normal time and set AM/PM
  44.   IF myClock.hour<12
  45.     ampm:='AM'  -> hour less than 12, must be morning
  46.   ELSE
  47.     ampm:='PM'  -> hour greater than 12,must be night
  48.     myClock.hour:=myClock.hour-12  -> Subtract the extra 12 of military
  49.   ENDIF
  50.  
  51.   IF myClock.hour=0 THEN myClock.hour:=12  -> Don't forget the 12s
  52.  
  53.   -> Print the time
  54.   WriteF('\n             the BatTime is ')
  55.   WriteF('\d:\z\d[2]:\z\d[2] \s\n\n',
  56.          myClock.hour, myClock.min, myClock.sec, ampm)
  57. EXCEPT DO
  58.   IF utilitybase THEN CloseLibrary(utilitybase)
  59.   SELECT exception
  60.   CASE ERR_LIB;  WriteF('Error: Could not open utility.library\n')
  61.   CASE ERR_RES;  WriteF('Error: Unable to open the \s\n', BATTCLOCKNAME)
  62.   ENDSELECT
  63. ENDPROC
  64.