home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_show / parking / date.e < prev    next >
Text File  |  1999-06-05  |  3KB  |  129 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class DATE
  17.  
  18. inherit
  19.    ANY
  20.       redefine print_on
  21.       end;
  22.  
  23. creation {ANY}
  24.    make
  25.  
  26. feature {ANY}
  27.  
  28.    print_on(file: OUTPUT_STREAM) is
  29.       do
  30.          file.put_string("day : ");
  31.          file.put_integer(day);
  32.          file.put_string(" minute : ");
  33.          file.put_integer(min);
  34.       end;
  35.  
  36.    minutes_to(after: DATE): INTEGER is
  37.          -- Count of minutes to go to `after'.
  38.       require
  39.          after >= Current
  40.       do
  41.          Result := ((after.day - day) * 24 * 60 + (after.min - min));
  42.       ensure
  43.          Result >= 0;
  44.       end;
  45.  
  46.    day_night_to(d2: DATE): ARRAY[INTEGER] is
  47.          -- Result @ Result.lower : Night time.
  48.          -- Result @ Result.upper : Day time.
  49.       require
  50.          d2 >= Current
  51.       local
  52.          min_jour, min_nuit: INTEGER;
  53.          save_day, save_min: INTEGER;
  54.       do
  55.          from
  56.             save_day := day;
  57.             save_min := min;
  58.          until
  59.             is_equal(d2)
  60.          loop
  61.             if day_time then
  62.                min_jour := min_jour + 1;
  63.             else
  64.                min_nuit := min_nuit + 1;
  65.             end;
  66.             add_time(1);
  67.          end;
  68.          day := save_day;
  69.          min := save_min;
  70.          Result := <<min_jour,min_nuit>>
  71.       ensure
  72.          Result.count = 2;
  73.          (Result @ 1) + (Result @ 2) = minutes_to(d2)
  74.       end;
  75.  
  76.    infix ">=" (d2: like Current): BOOLEAN is
  77.       require
  78.          d2 /= Void
  79.       do
  80.          Result := (day > d2.day) or else
  81.                    ((day = d2.day) and then (min >= d2.min));
  82.       end
  83.  
  84.    day_time: BOOLEAN is
  85.          -- Is it Sunny ?
  86.       do
  87.          Result := (min >= 6*60) and (min <= 22*60);
  88.       end;
  89.  
  90.    nigth_time: BOOLEAN is
  91.          -- Is it the night ?
  92.       do
  93.          Result := not day_time;
  94.       end;
  95.  
  96. feature {ANY} -- Modifications :
  97.  
  98.    make(vday, vmin: INTEGER) is
  99.       do
  100.          day := vday;
  101.          min := vmin;
  102.       ensure
  103.          day = vday;
  104.          min = vmin;
  105.       end;
  106.  
  107.    add_time(nb_min: INTEGER) is
  108.       do
  109.          min := min + nb_min;
  110.          if min > (24*60) then
  111.             day := day + (min // (24*60));
  112.             min := min \\ (24*60);
  113.          end;
  114.       end;
  115.  
  116. feature {DATE}
  117.  
  118.    day, min : INTEGER;
  119.  
  120. invariant
  121.  
  122.    day >= 0;
  123.  
  124.    min >= 0;
  125.  
  126.    min < 24 * 60;
  127.  
  128. end -- DATE
  129.