///////////////////////////////////////////////////////////////////////////////
//                             Lisaac Library                                //
//                                                                           //
//                   LSIIT - ULP - CNRS - INRIA - FRANCE                     //
//                                                                           //
//   This program is free software: you can redistribute it and/or modify    //
//   it under the terms of the GNU General Public License as published by    //
//   the Free Software Foundation, either version 3 of the License, or       //
//   (at your option) any later version.                                     //
//                                                                           //
//   This program is distributed in the hope that it will be useful,         //
//   but WITHOUT ANY WARRANTY; without even the implied warranty of          //
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
//   GNU General Public License for more details.                            //
//                                                                           //
//   You should have received a copy of the GNU General Public License       //
//   along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
//                                                                           //
//                     http://isaacproject.u-strasbg.fr/                     //
///////////////////////////////////////////////////////////////////////////////
Section Header
  
  + name        :=Expanded  TIME;



  - copyright   := "2003-2005 Jérome Boutet, 2003-2007 Benoit Sonntag";
  
  - comment     := "Time";
  
  - type        := `unsigned long`;
  
  - default     := `0`:TIME;
  
Section Insert
  
  - parent_object:OBJECT := OBJECT;
  
Section Private
  
  - to_raw:UINTEGER_32 <-
  (
    CONVERT[SELF, UINTEGER_32].on Self
  );
Section Public

  - hour:UINTEGER_8 <-
  (
    (to_raw >> 24).to_uinteger_8
  );
  
  - minute:UINTEGER_8 <-
  (
    ((to_raw & 0FF0000h) >> 16).to_uinteger_8
  );
  
  - second:UINTEGER_8 <-
  (
    ((to_raw & 0FF00h) >> 8).to_uinteger_8
  );

  - csecond:UINTEGER_8 <-
  (
    (to_raw & 0FFh).to_uinteger_8
  );
  
Section Public
  
  - '>' Right 60 other:SELF :BOOLEAN <- to_raw > other.to_raw;
  
  - '<' Right 60 other:SELF :BOOLEAN <- to_raw < other.to_raw;
  
  - '>=' Right 60 other:SELF :BOOLEAN <- to_raw >= other.to_raw;
  
  - '<=' Right 60 other:SELF :BOOLEAN <- to_raw <= other.to_raw;
  
  - to_csecond:INTEGER <- hour.to_integer * (60*60*100) + 
  minute.to_integer * (60*100) + 
  second.to_integer * 100 + 
  csecond;
  
  - '-' Right 60 other:SELF :SELF <- 
  ( 
    create_csecond (Self -# other)
  );
  
  // BSBS: A uniformiser -# +# ???
  
  - '-#' Right 60 other:SELF :INTEGER <- to_csecond - other.to_csecond;
  
  - '+#' Right 60 other:INTEGER :TIME <-
  ( 
    create_csecond (to_csecond + other)
  );
  
  - create (h,m,s,cs:INTEGER) :TIME <-
  ( + t:UINTEGER_32;
    ? {h.in_range 0 to 23};
    ? {m.in_range 0 to 59};
    ? {s.in_range 0 to 59};
    ? {cs.in_range 0 to 99};
    
    t := h.to_uinteger_32 <<24;
    t := t | (m.to_uinteger_32 << 16);
    t := t | (s.to_uinteger_32 << 8);
    t := t | cs;
    CONVERT[UINTEGER_32, SELF].on t
  );
  
  - create_csecond csec:INTEGER :SELF <-
  ( + h,m,s,cs,diff:INTEGER;
    
    diff := csec;
    h := diff / (60*60*100);
    diff := diff % (60*60*100);
    
    m := diff / (60*100);
    diff := diff % (60*100);
    
    s := diff / 100;
    cs := diff % 100;    
    
    create (h,m,s,cs)
  );
  
  - to_string:STRING <-
  ( + result:STRING;
    result := STRING.create 8;
    append_in result;
    result
  );
  
  - append_in str:STRING <-
  (
    hour.append_in str format 2 with '0';
    str.add_last ':';
    minute.append_in str format 2 with '0';
    str.add_last ':';
    second.append_in str format 2 with '0';
    str.add_last ',';
    csecond.append_in str format 2 with '0';
  );

  - append_short_in str:STRING <-
  (
    hour.append_in str format 2 with '0';
    str.add_last ':';
    minute.append_in str format 2 with '0';
  );
  
  - update <-
  (
    // JBJB A FAIRE !!    
  );
  
  - print <-
  (
    to_string.print;
  );



