home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / CCARACT.ZIP / cheure.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-23  |  3.2 KB  |  184 lines

  1. #include <afx.h>
  2. #pragma hdrstop
  3. #include "cheure.hpp"
  4.  
  5. CHeure::CHeure()
  6. {
  7.  h = 0;
  8.  m = 0;
  9.  s = 0;
  10. };
  11.  
  12. CHeure::CHeure( int heure, int minute, int seconde )
  13. {
  14.  h = heure;
  15.  m = minute;
  16.  s = seconde;
  17. };
  18.  
  19. CHeure::~CHeure()
  20. {
  21. };
  22.  
  23. void CHeure::HeureSysteme()
  24. {
  25.  CTime ct;
  26.  ct.GetCurrentTime();
  27.  AffecteHeure( ct.GetHour() );
  28.  AffecteMinute( ct.GetMinute() );
  29.  AffecteSeconde( ct.GetSecond() );
  30. };
  31.  
  32. int CHeure::PrendHeure()
  33. {
  34.  return(h);
  35. }
  36.  
  37. int CHeure::PrendMinute()
  38. {
  39.  return(m);
  40. }
  41.  
  42. int CHeure::PrendSeconde()
  43. {
  44.  return(s);
  45. }
  46.  
  47. bool CHeure::AffecteHeure( int heure )
  48. {
  49.  if ( heure < 0 || heure > 23 ) return false;
  50.  h = heure;
  51.  return true;
  52. }
  53.  
  54. bool CHeure::AffecteMinute( int minute )
  55. {
  56.  if ( minute < 0 || minute > 59 ) return false;
  57.  m = minute;
  58.  return true;
  59. }
  60.  
  61. bool CHeure::AffecteSeconde( int seconde )
  62. {
  63.  if ( seconde < 0 || seconde > 59 ) return false;
  64.  s = seconde;
  65.  return true;
  66. }
  67.  
  68.  
  69. bool CHeure::operator=( CHeure ch )
  70. {
  71.  if ( !AffecteHeure(ch.PrendHeure()) ) return false;
  72.  if ( !AffecteHeure(ch.PrendMinute()) ) return false;
  73.  if ( !AffecteHeure(ch.PrendSeconde()) ) return false;
  74.  return true;
  75. }
  76.  
  77.  
  78. bool CHeure::operator==( CHeure ch )
  79. {
  80.  return ( h == ch.PrendHeure()
  81.    && m == ch.PrendMinute()
  82.    && s == ch.PrendSeconde() );
  83. }
  84.  
  85. bool CHeure::operator>( CHeure ch )
  86. {
  87.  if ( h > ch.PrendHeure() ) return true;
  88.  if ( m > ch.PrendMinute() ) return true;
  89.  if ( s > ch.PrendSeconde() ) return true;
  90.  return false;
  91. }
  92.  
  93. bool CHeure::operator>=( CHeure ch )
  94. {
  95.  if ( h < ch.PrendHeure() ) return false;
  96.  if ( h > ch.PrendHeure() ) return true;
  97.  if ( m < ch.PrendMinute() ) return false;
  98.  if ( m > ch.PrendMinute() ) return true;
  99.  if ( s >= ch.PrendSeconde() ) return true;
  100.  return false;
  101. }
  102.  
  103. bool CHeure::operator<( CHeure ch )
  104. {
  105.  if ( h < ch.PrendHeure() ) return true;
  106.  if ( m < ch.PrendMinute() ) return true;
  107.  if ( s < ch.PrendSeconde() ) return true;
  108.  return false;
  109. }
  110.  
  111. bool CHeure::operator<=( CHeure ch )
  112. {
  113.  if ( h > ch.PrendHeure() ) return false;
  114.  if ( h < ch.PrendHeure() ) return true;
  115.  if ( m > ch.PrendMinute() ) return false;
  116.  if ( m < ch.PrendMinute() ) return true;
  117.  if ( s <= ch.PrendSeconde() ) return true;
  118.  return false;
  119. }
  120.  
  121. CString CHeure::Format( char * f )
  122. {
  123.  CString resultat = "";
  124.  char buf[3];
  125.  
  126.  while ( (*f) )
  127.  {
  128.   if ( *f == '%' )
  129.     {
  130.      f++;
  131.      switch(*f)
  132.      {
  133.       case 'H' :
  134.           sprintf(buf,"%02d",h);
  135.       break;
  136.       case 'M' :
  137.           sprintf(buf,"%02d",m);
  138.       break;
  139.       case 'S' :
  140.           sprintf(buf,"%02d",s);
  141.       break;
  142.       default :
  143.          buf[0] = '\0';
  144.      }
  145.      resultat+=buf;
  146.     }
  147.   else
  148.     {
  149.      resultat += *f;
  150.     }
  151.  
  152.   f++;
  153.  }
  154.  return resultat;
  155. }
  156.  
  157. // Relation avec CTime, le temps des MFC
  158.  
  159. CHeure * CHeure::operator=( CTime ct )
  160. {
  161.  h = ct.GetHour();
  162.  m = ct.GetMinute();
  163.  s = ct.GetSecond();
  164.  return this;
  165. }
  166.  
  167.  
  168. bool CHeure::operator==( CTime ct  )
  169. {
  170.  return( h == ct.GetHour() && m == ct.GetMinute() && s == ct.GetSecond() );
  171. }
  172.  
  173.  
  174. bool CHeure::EgaleHeureMinute( CHeure ch  )
  175. {
  176.  return ( h == ch.PrendHeure() && m == ch.PrendMinute() );
  177. }
  178.  
  179. bool CHeure::EgaleHeureMinute( CTime ct  )
  180. {
  181.  return( h == ct.GetHour() && m == ct.GetMinute() );
  182. }
  183.  
  184.