Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

date.cc

00001 /*
00002 *  Name:         date.cc
00003 *  Author:       Francisco Rodrigo Escobedo Robles
00004 *  Contributor:  Rafael Jesus Alcantara Perez
00005 *  Summary:      Base date class
00006 *  Date:         $Date: 2003/04/14 00:18:35 $
00007 *  Revision:     $Revision: 1.1 $
00008 *
00009 *  Copyright (C) 2000-2001  Francisco Rodrigo Escobedo Robles <frer@dedalo-ing.com>
00010 *  Copyright (C) 2002       Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00011 *
00012 *  This program is free software; you can redistribute it and/or modify
00013 *  it under the terms of the GNU General Public License as published by
00014 *  the Free Software Foundation; either version 2 of the License, or
00015 *  (at your option) any later version.
00016 *
00017 *  This program is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  You should have received a copy of the GNU General Public License
00023 *  along with this program; if not, write to the Free Software
00024 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00025 *  MA 02111-1307, USA.
00026 */
00027 
00028 #include <ctime>
00029 #include <mpcl/text/date.hh>
00030 
00031 
00032 //
00033 //  C O N S T R U C T O R S
00034 //
00035 
00036 mpcl::text::IDate::
00037 IDate (const IDate::EDateType keDATE_TYPE)
00038   throw (TConstraintException)    :
00039   tSecondsFromEpoch ((time_t) -1)
00040 {
00041 
00042   using std::time;
00043   using std::time_t;
00044 
00045   switch (keDATE_TYPE)
00046   {
00047     case eEmpty:
00048     {
00049       tSecondsFromEpoch = (time_t) -1;
00050       break;
00051     }
00052     case eNow:
00053     {
00054       tSecondsFromEpoch = time (NULL);
00055       break;
00056     }
00057     case eTomorrow:
00058     {
00059       tSecondsFromEpoch = time (NULL);
00060       addDays (1);
00061       break;
00062     }
00063     default:
00064     {
00065       throw TConstraintException ("invalid date type", __FILE__, __LINE__);
00066     }
00067   }
00068 
00069 }  // IDate()
00070 
00071 
00072 void mpcl::text::IDate::set ( const int kiYEAR    ,
00073                               const int kiMONTH   ,
00074                               const int kiDAY     ,
00075                               const int kiHOUR    ,
00076                               const int kiMINUTES ,
00077                               const int kiSECONDS )
00078   throw (TConstraintException)
00079 {
00080 
00081   using std::mktime;
00082   using std::time_t;
00083   using std::tm;
00084   
00085   struct tm   sDateTm;
00086 
00087   sDateTm.tm_year  = kiYEAR  - 1900;
00088   sDateTm.tm_mon   = kiMONTH - 1;
00089   sDateTm.tm_mday  = kiDAY;
00090   sDateTm.tm_hour  = kiHOUR;
00091   sDateTm.tm_min   = kiMINUTES;
00092   sDateTm.tm_sec   = kiSECONDS;
00093   sDateTm.tm_isdst = 0;
00094   if ( (time_t) -1 == (tSecondsFromEpoch = mktime (&sDateTm)) )
00095   {
00096     throw TConstraintException ("invalid date", __FILE__, __LINE__);
00097   }
00098 
00099 }  // set()

Generated on Mon Oct 13 02:35:22 2003 for MPCL by doxygen1.2.18