(file) Return to CIMDateTime.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

   1 karl  1.50 //%2005////////////////////////////////////////////////////////////////////////
   2 mike  1.10 //
   3 karl  1.42 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
   4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   6 karl  1.37 // IBM Corp.; EMC Corporation, The Open Group.
   7 karl  1.42 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   9 karl  1.50 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
  11 mike  1.10 //
  12            // Permission is hereby granted, free of charge, to any person obtaining a copy
  13 kumpf 1.22 // of this software and associated documentation files (the "Software"), to
  14            // deal in the Software without restriction, including without limitation the
  15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  16 mike  1.10 // sell copies of the Software, and to permit persons to whom the Software is
  17            // furnished to do so, subject to the following conditions:
  18 david.dillard 1.54 //
  19 kumpf         1.22 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  20 mike          1.10 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  21                    // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  22 kumpf         1.22 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  23                    // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  24                    // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  25 mike          1.10 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26                    // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27                    //
  28                    //==============================================================================
  29                    // Author: Mike Brasher (mbrasher@bmc.com)
  30                    //
  31 kumpf         1.14 // Modified By: Sushma Fernandes, Hewlett-Packard Company
  32 kumpf         1.17 //                  (sushma_fernandes@hp.com)
  33                    //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
  34 kumpf         1.26 //              Carol Ann Krug Graves, Hewlett-Packard Company
  35                    //                (carolann_graves@hp.com)
  36 w.white       1.43 //              Willis White (whiwill@ibm.com) PEP #192
  37 gs.keenan     1.51 //              Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)
  38 mike          1.10 //
  39                    //%/////////////////////////////////////////////////////////////////////////////
  40                    
  41 kumpf         1.17 #include <time.h>
  42 w.white       1.43 #include <math.h>
  43                    #include <errno.h>
  44 david.dillard 1.54 #include "CIMDateTime.h"
  45                    #include "InternalException.h"
  46 kumpf         1.53 #include <Pegasus/Common/AutoPtr.h>
  47 w.white       1.43 #include <Pegasus/Common/Tracer.h>
  48                    #include <Pegasus/Common/MessageLoader.h> //l10n
  49                    #include <cassert>
  50                    
  51 mike          1.10 
  52 kumpf         1.32 
  53 kumpf         1.14 #if defined(PEGASUS_OS_TYPE_WINDOWS)
  54 kumpf         1.41 # include <Pegasus/Common/CIMDateTimeWindows.cpp>
  55 kumpf         1.14 #elif defined(PEGASUS_OS_TYPE_UNIX)
  56 kumpf         1.41 # include <Pegasus/Common/CIMDateTimeUnix.cpp>
  57 kumpf         1.14 #elif defined(PEGASUS_OS_TYPE_NSK)
  58 kumpf         1.41 # include <Pegasus/Common/CIMDateTimeNsk.cpp>
  59 gs.keenan     1.51 #elif defined(PEGASUS_OS_VMS)
  60                    # include <Pegasus/Common/CIMDateTimeVms.cpp>
  61 kumpf         1.14 #else
  62 kumpf         1.41 # error "Unsupported platform"
  63 kumpf         1.14 #endif
  64                    
  65                    PEGASUS_USING_STD;
  66                    
  67 mike          1.10 PEGASUS_NAMESPACE_BEGIN
  68                    
  69                    #define PEGASUS_ARRAY_T CIMDateTime
  70                    # include "ArrayImpl.h"
  71                    #undef PEGASUS_ARRAY_T
  72                    
  73 karl          1.16 // ATTN: P3 KS 04/17/02 Need methods for determining inequalities.
  74 mike          1.11 
  75 karl          1.16 // ATTN: P3 KS 04/17/02 Need methods for extracting components (e.g., minutes, hours)?
  76 mike          1.11 
  77 karl          1.16 // ATTN: P3 KS 04/17/02 Needs constructor that creates from individual elements(year,...)
  78 mike          1.10 
  79                    static const char _NULL_INTERVAL_TYPE_STRING[] = "00000000000000.000000:000";
  80 karl          1.12 static const char _NULL_DATE_TYPE_STRING[] = "00000000000000.000000-000";
  81 w.white       1.43 static const Uint64 _TEN_THOUSAND_YEARS = PEGASUS_UINT64_LITERAL(315569520000000000);
  82                    static const Uint64 _HUNDRED_MILLION_DAYS = PEGASUS_UINT64_LITERAL(8640000000000000000);
  83                    static const Uint64 _ONE_DAY = PEGASUS_UINT64_LITERAL(86400000000);
  84 david.dillard 1.54 static const Uint64 _ONE_HOUR = PEGASUS_UINT64_LITERAL(3600000000);
  85 w.white       1.43 static const Uint64 _ONE_MINUTE = 60000000;
  86                    static const Uint64 _ONE_SECOND = 1000000;
  87                    
  88 mike          1.10 
  89 w.white       1.43  /* the CIMDateTimeRep class holds the data for the CIMDateTime class as it's protected
  90 david.dillard 1.54 data members.It also allows for "setting" and "getting" of individual components of
  91 w.white       1.43 date time.
  92                    */
  93 a.arora       1.40 class CIMDateTimeRep
  94                    {
  95                    public:
  96 w.white       1.43     String microSec;
  97                        String seconds;
  98                        String minutes;
  99                        String hours;
 100                        String days;
 101                        String month;
 102                        String year;
 103                        String utcOffSet;
 104                    
 105 a.arora       1.40     enum { FORMAT_LENGTH = 25 };
 106                    
 107                        //
 108                        // Length of the string required to store only the date and time without
 109                        // the UTC sign and UTC offset.
 110                        // Format is yyyymmddhhmmss.
 111                        // Note : The size does not include the null byte.
 112                        //
 113 david.dillard 1.54     enum { DATE_TIME_LENGTH = 14 };
 114 a.arora       1.40 
 115                        //
 116                        // Length of the string required to store the  formatted date and time
 117                        // Format is yyyy:mm:dd:hh:mm:ss.
 118                        //
 119                        enum { FORMATTED_DATE_TIME = 20 };
 120 kumpf         1.21 
 121 w.white       1.43     //char buffer_day [5];
 122                        //    sprintf(yearbuf, "%4d", (days_rem+1));   // day of the month is never 0 (1-31)
 123                        //    ye_mo_da = ye_mo.append(buffer_day);
 124                    
 125                    
 126 a.arora       1.40     char data[FORMAT_LENGTH + 1];
 127 david.dillard 1.54 
 128 w.white       1.43 
 129                        /* Checks for correctness and sets the MicroSeconds value of CIMDateTimeRep
 130                        */
 131 w.white       1.45     Uint16 set_microSec(const String & mS);
 132 w.white       1.43 
 133                        /* Checks for correctness and sets the UTC offset of CIMDateTimeRep
 134                        */
 135 w.white       1.46     Boolean set_utcOffSet(const String & uOff);
 136 w.white       1.43 
 137                        /*Changes the CIMDateTimeRep data member data[] .
 138                        @param value - value to be inserted into data[]
 139                        @param index - position in data[] to start inserting the value
 140 david.dillard 1.55     @param size - size of the value paramiter (number of characters
 141 w.white       1.43     */
 142                        void set_data(const String & value, Uint32 index, Uint32 size);
 143 david.dillard 1.54 
 144 w.white       1.43 
 145                        /* these set functions are not used yet.
 146                        when they become used the enum CIMDateTime::Field should be moved to CIMDateTimeRep
 147                        */
 148                        void set_seconds(const String & sec);
 149                        void set_minutes(const String & min);
 150                        void set_hours(const String & ho);
 151 david.dillard 1.54     void set_days(const String & da);
 152 w.white       1.43     void set_month(const String & mon);
 153                        void set_year(const String & ye);
 154 david.dillard 1.54 
 155 david.dillard 1.55     void copy(const CIMDateTimeRep * cTR);
 156 w.white       1.43 
 157                     };
 158                    
 159                    
 160                    /* this method  copies the all the information from one CIMDateTimeRep to another
 161                    */
 162 david.dillard 1.55 void CIMDateTimeRep::copy(const CIMDateTimeRep * cTR)
 163                    {
 164                        //cout << "Start of Rep::copy" << endl;
 165                        microSec = cTR->microSec;
 166                        seconds = cTR->seconds;
 167                        minutes = cTR->minutes;
 168                        hours = cTR->hours;
 169                        days = cTR->days;
 170                        month = cTR->month;
 171                        year = cTR->year;
 172                        utcOffSet = cTR->utcOffSet;
 173                        memcpy(data, cTR->data, sizeof(data));
 174                        //cout << "end of Rep::copy" << endl <<endl;
 175                    }
 176 w.white       1.43 
 177                    /* set_microSec checks the format of the string that will be
 178                    used as the micro seconds value. If the format is correct it sets the
 179                    micro seconds value
 180                    */
 181 w.white       1.45 Uint16 CIMDateTimeRep::set_microSec(const String & mS)
 182 w.white       1.43 {
 183 david.dillard 1.54     //  String fin_data = sum_data.append(mS.subString(21,4));
 184                    
 185 w.white       1.43     //cout << "begining of set_microSec" << endl;
 186                        Uint32 ast_post;
 187 david.dillard 1.54 
 188 w.white       1.43     ast_post = mS.find("*");
 189                        if (ast_post == PEG_NOT_FOUND) {
 190                            set_data(mS, 15, 6);
 191                            microSec = mS;
 192                            return 2;
 193                        }
 194                    
 195                       // cout << "after find  block" << endl;
 196                        Uint32 sub_len = 6 - ast_post;
 197                        String ast = "******";
 198                        String in_comp = mS.subString(ast_post, sub_len);
 199                        if (!String::compare(in_comp, ast, sub_len)){
 200                            set_data(mS, 15, 6);
 201                            microSec = mS;
 202                            return 0;
 203                        }
 204                        else{
 205                           // cout << "error in set_microSec - this is the value " << mS << endl;
 206                            Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 207                              "Error in CIMDateTimeRep::set_microSec - '*' was found in micor second string");
 208                            return 1;
 209 w.white       1.43     }
 210                    }
 211 a.arora       1.40 
 212                    
 213 w.white       1.43 /*set_data set the data member CIMDateTimeRep::set_data
 214                    */
 215                    void CIMDateTimeRep::set_data(const String & value, Uint32 index, Uint32 size)
 216                    {
 217                        for (Uint32 i=0; i < size; i++) {
 218 w.white       1.47         data[index+i] = (char) value[i];
 219 david.dillard 1.54     }
 220 w.white       1.43 }
 221                    
 222                    
 223                    /* the following 6 methods are not used
 224                    */
 225                    void CIMDateTimeRep::set_seconds(const String & sec)
 226                    {
 227                        seconds = sec;
 228                    }
 229 david.dillard 1.54 
 230 w.white       1.43 void CIMDateTimeRep::set_minutes(const String & min)
 231                    {
 232                        minutes = min;
 233                    }
 234 david.dillard 1.54 
 235 w.white       1.43 void CIMDateTimeRep::set_hours(const String & ho)
 236                    {
 237                        hours = ho;
 238                    }
 239 david.dillard 1.54 
 240 w.white       1.43 void CIMDateTimeRep::set_days(const String & da)
 241                    {
 242                        days = da;
 243                    }
 244                    
 245                    void CIMDateTimeRep::set_month(const String & mon)
 246                    {
 247                        month = mon;
 248                    }
 249 david.dillard 1.54 
 250 w.white       1.43 void CIMDateTimeRep::set_year(const String & ye)
 251                    {
 252                        year = ye;
 253                    }
 254                    
 255                    /* set_utcOffSet checks the format of the string representing the UTC
 256                    offset if it is correct it sets the data member CIMDateTimeRep::utcOffSet
 257                    */
 258 w.white       1.46 Boolean CIMDateTimeRep::set_utcOffSet(const String & uOffSet)
 259 w.white       1.43 {
 260                        if (uOffSet.size() != 4) {
 261                            Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 262                                  "The size of the UTC offset is %d but is but it should be 4", uOffSet.size());
 263                            return false;
 264                        }
 265                    
 266 david.dillard 1.55     Char16 ch_one = uOffSet[0];
 267 w.white       1.43     if (ch_one != ':' && ch_one != '+' && ch_one != '-') {
 268                            Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 269 david.dillard 1.56         "The UTC off set must begin with a ':' or '+' or '-'. The value of the first character of UTC offset is %u", static_cast<Uint16>(ch_one));
 270 w.white       1.43         return false;
 271                        }
 272                    
 273 kumpf         1.62     // the UTC must not have asterisks in it
 274 w.white       1.43     Uint32 spot = uOffSet.find("*");
 275 kumpf         1.62     if (spot != PEG_NOT_FOUND)
 276                        {
 277 w.white       1.43         Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 278                                          "'*' was found in the UTC offset this is not allowed");
 279                            return false;
 280                        }
 281 david.dillard 1.54 
 282 w.white       1.43 
 283                        String uOff_num = uOffSet.subString(1,3);
 284 kumpf         1.62     for (int i=0; i < 3; i++)
 285                        {
 286 kumpf         1.63         if ((uOff_num[i] < '0') || (uOff_num[i] > '9'))
 287 kumpf         1.62         {
 288 w.white       1.43             Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 289 kumpf         1.62                  "Format is wrong - UTC offset contains non digit character.");
 290 w.white       1.43             return false;
 291                            }
 292                        }
 293                    
 294 kumpf         1.62     // intervals (:) must have 000 utc offset
 295                        if ((ch_one == (char)':') && !String::equal(uOff_num, "000"))
 296                        {
 297 w.white       1.43         Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 298                                          "Trying to incorrectly set a intervals time zone");
 299                            return false;
 300                        }
 301                    
 302                        utcOffSet =  uOffSet;
 303 kumpf         1.62     set_data(uOffSet, 21, 4);   // change _rep->data to reflect changes made
 304 w.white       1.43 
 305                        return true;
 306                    }
 307                    
 308                    
 309                    /*Constructor
 310                    */
 311 a.arora       1.40 CIMDateTime::CIMDateTime()
 312 mike          1.10 {
 313 a.arora       1.40     _rep = new CIMDateTimeRep();
 314 kumpf         1.53     AutoPtr<CIMDateTimeRep> rep(_rep);
 315                    
 316 mike          1.10     clear();
 317 kumpf         1.53 
 318                        rep.release();
 319 mike          1.10 }
 320                    
 321 w.white       1.43 /*Takes properly formated string and creates a CIMDateTime out of it
 322                    */
 323 a.arora       1.40 CIMDateTime::CIMDateTime(const String & str)
 324 mike          1.10 {
 325 a.arora       1.40     _rep = new CIMDateTimeRep();
 326 kumpf         1.53     AutoPtr<CIMDateTimeRep> rep(_rep);
 327                    
 328 kumpf         1.21     if (!_set(str))
 329                        {
 330 kumpf         1.28         throw InvalidDateTimeFormatException();
 331 kumpf         1.21     }
 332 kumpf         1.53 
 333                        rep.release();
 334 mike          1.10 }
 335                    
 336 w.white       1.43 /*Copy constructor
 337                    */
 338 a.arora       1.40 CIMDateTime::CIMDateTime(const CIMDateTime& x)
 339 mike          1.10 {
 340 a.arora       1.40     _rep = new CIMDateTimeRep();
 341 kumpf         1.53     AutoPtr<CIMDateTimeRep> rep(_rep);
 342                    
 343 w.white       1.43     _rep->copy(x._rep);
 344 kumpf         1.53 
 345                        rep.release();
 346 david.dillard 1.54 }
 347 w.white       1.43 
 348                    /*constructs a CIMDateTime object from micro second value.
 349                    pusdo code:
 350                    check to make sure
 351                        if not interval{
 352                            check to make sure number of micro seconds is not greater then or equal to
 353                            10,000 years (uper bound of time stamp)
 354                         }
 355                        if interval {
 356 david.dillard 1.54         check to make sure heck to make surenumber of micro seconds is not greater
 357 w.white       1.43         then or equal to 100 millon years (uperbound of interval)
 358                        }
 359 david.dillard 1.54 
 360 w.white       1.43     number of days = day_sub1
 361 david.dillard 1.54 
 362 w.white       1.43     if interval{
 363                            get number of 400 year blocks  (number of days in 400 years is always the same)
 364                            While (numer of days after taking out 400 year blocks > 365){
 365                                if (not a leap year){
 366                                    subtract 365 days from tottal
 367                                }
 368                                else{
 369                                    subtract 366 days from toatal
 370                                }
 371                            }
 372 david.dillard 1.54 
 373                            tottal number of years = year
 374                    
 375 w.white       1.43         if (year we are calculating months for is a leap year){
 376                                add one to end date of Feb and add on to start end end days of all month after Feb
 377                            }
 378 david.dillard 1.54 
 379 w.white       1.43         if (number of days left after taking of years is between 334 and 365){
 380                                we are in the 12th month
 381                                subtract months from number of days left
 382                             }
 383                             else if (number of days left after taking of years is between 334 and 304){
 384                                we are in the 11th month
 385                                subtract months from number of days left
 386 david.dillard 1.54 
 387                    
 388 w.white       1.43             ...
 389 david.dillard 1.54 
 390                    
 391 w.white       1.43          esle if (number of days left after taking of years is between 31 and 0){
 392                                we are in the 1st month
 393 david.dillard 1.54             subtract months from number of days left
 394 w.white       1.43          }
 395                             else{
 396                                we should never get to this code
 397                             }
 398 david.dillard 1.54 
 399 w.white       1.43          get number of days left
 400                        }
 401 david.dillard 1.54 
 402 w.white       1.43     get number of hours, minutes, seconds, and microseconds
 403 david.dillard 1.54 
 404 w.white       1.43     build string representaion of object
 405 david.dillard 1.54 
 406                        send string to set()
 407                     */
 408 w.white       1.47 CIMDateTime::CIMDateTime(Uint64 microSec, Boolean interval)
 409 david.dillard 1.54 {
 410 w.white       1.43     if (microSec >= _TEN_THOUSAND_YEARS && !interval) { //time stamps must be less then number of micro Seconds in 10,000 years
 411                            MessageLoaderParms parmsTS("Common.Exception.DATETIME_OUT_OF_RANGE_EXCEPTION",
 412                                   "trying to create a CIMDateTime object (time stamp) greater then the year 10,000");
 413                            throw DateTimeOutOfRangeException(parmsTS);
 414 david.dillard 1.54     }
 415 w.white       1.43     if (microSec >= _HUNDRED_MILLION_DAYS && interval) { //intervals must be less then the number of microseconds in 100 million days
 416                            MessageLoaderParms parmsIN("Common.Exception.DATETIME_OUT_OF_RANGE_EXCEPTION",
 417                                   "can't create a CIMDateTime object (interval) greater then the year 100 million days");
 418                             throw DateTimeOutOfRangeException(parmsIN);
 419                        }
 420                    
 421                    
 422                        //Set of Strings that hold part parts of datetime    100,000,000
 423                        String year, ye_mo, ye_mo_da, ye_mo_da_ho, ye_mo_da_ho_mn, ye_mo_da_ho_mn_se, final;
 424                    
 425 w.white       1.47     Uint32 day_sub1 = (Uint32)(microSec/_ONE_DAY);
 426 w.white       1.45     Uint32 days_in400 = 146097;
 427 w.white       1.43 
 428                        if (!interval) {
 429                            Uint32 blocks_400 = day_sub1/days_in400;  //calculates the number of 400 year blocks in number
 430                            Uint32 blocks_rem = day_sub1%days_in400;  //clauclates number of day after 400 year blocks are removed
 431                            Uint32 days_rem = blocks_rem;
 432                    
 433 david.dillard 1.54 
 434 w.white       1.43         /*While loop computes number of years form number of day
 435                            taking into accoutn leap years
 436                            */
 437                            //cout << " days_rem in constuctor that takes Micro = " << days_rem << endl;
 438                            Uint32 i = 1;
 439                            Uint32 count = 0;
 440                            Uint32 leap_next = 1;
 441 david.dillard 1.54 
 442 w.white       1.43         /*  ((i%4 == 0) && (i%100 != 0)) || (i%400 == 0)) is only true for leap years. So this while
 443                            loop says "do if days_rem >= for non-leap years or days_rem >= 366 for leap years
 444 david.dillard 1.54         */
 445 w.white       1.43         while ((days_rem >= 365 && !(((i%4 == 0) && (i%100 != 0)) || (i%400 == 0))) || (days_rem >= 366 && (((i%4 == 0) && (i%100 != 0)) || (i%400 == 0)))) {
 446                                if (!(((i%4 == 0) && (i%100 != 0)) || (i%400 == 0))) {
 447                                    days_rem = days_rem - 365;
 448                                    count = count + 1;
 449                                    i = i+1;
 450                                    leap_next = leap_next + 1;
 451                                }
 452                                else{
 453                                    days_rem = days_rem - 366;
 454                                    count = count + 1;
 455                                    i = i + 1;
 456                                    leap_next = 0;
 457                                     //cout << "leap year" << endl;
 458 david.dillard 1.54             }
 459                            }
 460 w.white       1.43 
 461                          // cout << "leap next = " << leap_next << " and count = " << count << " days_rem = " << days_rem << endl;
 462                            Uint32 tot_year = (blocks_400 * 400) + count;
 463                    
 464                            //converting number of years from Uint32 -> String
 465                            char buffer_year [10];
 466                            sprintf(buffer_year, "%04d", tot_year);
 467                            year = String(buffer_year);
 468                            if (tot_year > 9999) {
 469                                assert(false);
 470                                // the calculated year should never be greater then 9999
 471                            }
 472                    
 473 david.dillard 1.54 
 474                            /*Switch block is used to calculate the the number of months from the number of days
 475                            left after years are subtracted.
 476                            */
 477 w.white       1.43 
 478                            Uint16 lp = 0;
 479                    
 480                            /*lp is 0 for non leap years and 1 for leap years
 481                            */
 482 david.dillard 1.54         if ((((i%4 == 0) && (i%100 != 0)) || (i%400 == 0))) {
 483 w.white       1.43             lp = 1;
 484                               // cout << "months are being calculated for a leap year" << endl;
 485                            }
 486                    
 487                            char bu_day [5];
 488                            sprintf(bu_day, "%02d", days_rem);
 489 david.dillard 1.54 
 490 w.white       1.43 
 491                    
 492                            /* this block of if else statments figures out the number of months. When it subtracts
 493                            days it is subtracting whole days. i.e. if 0 days for the year means Jan. 1
 494 david.dillard 1.54         */
 495 w.white       1.45         if (days_rem < Uint32(365+lp) && (days_rem >= Uint32(334+lp))) {
 496 w.white       1.43             ye_mo = year.append(String("12"));
 497                                days_rem = days_rem - (334+lp);
 498                            }
 499 w.white       1.45         else if((days_rem < Uint32(334+lp)) && (days_rem >= Uint32(304+lp))){
 500 w.white       1.43             ye_mo = year.append(String("11"));
 501                                days_rem = days_rem - (304+lp);
 502                            }
 503 w.white       1.45         else if((days_rem < Uint32(304+lp)) && (days_rem >= Uint32(273+lp))){
 504 w.white       1.43             ye_mo = year.append(String("10"));
 505                                days_rem = days_rem - (273+lp);
 506                            }
 507 w.white       1.45         else if((days_rem < Uint32(273+lp)) && (days_rem >= Uint32(243+lp))){
 508 w.white       1.43             ye_mo = year.append(String("09"));
 509                                days_rem = days_rem - (243+lp);
 510                            }
 511 w.white       1.45         else if((days_rem < Uint32(243+lp)) && (days_rem >= Uint32(212+lp))){
 512 w.white       1.43             ye_mo = year.append(String("08"));
 513                                days_rem = days_rem - (212+lp);
 514                            }
 515 w.white       1.45         else if((days_rem < Uint32(212+lp)) && (days_rem >= Uint32(181+lp))){
 516 w.white       1.43             ye_mo = year.append(String("07"));
 517                                days_rem = days_rem - (181+lp);
 518                            }
 519 w.white       1.45         else if((days_rem < Uint32(181+lp)) && (days_rem >= Uint32(151+lp))){
 520 w.white       1.43             ye_mo = year.append(String("06"));
 521                                days_rem = days_rem - (151+lp);
 522                            }
 523 w.white       1.45         else if((days_rem < Uint32(151+lp)) && (days_rem >= Uint32(120+lp))){
 524 w.white       1.43             ye_mo = year.append(String("05"));
 525                                days_rem = days_rem - (120+lp);
 526                            }
 527 w.white       1.45         else if((days_rem < Uint32(120+lp)) && (days_rem >= Uint32(90+lp))){
 528 w.white       1.43             ye_mo = year.append(String("04"));
 529                                days_rem = days_rem - (90+lp);
 530                            }
 531 w.white       1.45         else if((days_rem < Uint32(90+lp)) && (days_rem >= Uint32(59+lp))){
 532 w.white       1.43             ye_mo = year.append(String("03"));
 533                                days_rem = days_rem - (59+lp);
 534                            }
 535 w.white       1.45         else if((days_rem < Uint32(59+lp)) && (days_rem >= 31)){
 536 w.white       1.43             ye_mo = year.append(String("02"));
 537                                days_rem = days_rem - 31;
 538                            }
 539 w.white       1.45         else if(days_rem < 31){
 540 w.white       1.43             ye_mo = year.append(String("01"));
 541                            }
 542                            else{
 543                                // this code should never be exicuted
 544                                Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 545                                    "Error when caculating months in CIMDateTime::CIMDateTime(Uint \
 546                                              microSec, Boolean interval)");
 547                                assert(false);
 548                            }
 549                    
 550                           char bu_mon [5];
 551                           sprintf(bu_mon, "%02d", days_rem);
 552 david.dillard 1.54       // cout << "this is the days left after months is taken " << String(bu_mon) << endl;
 553 w.white       1.43 
 554                    
 555 david.dillard 1.54                //converting number of days from from Uint32 -> String
 556 w.white       1.43         char buffer_day [5];
 557                            sprintf(buffer_day, "%02d", (days_rem+1));   // day of the month is never 0 (1-31)
 558                            ye_mo_da = ye_mo.append(buffer_day);
 559                    
 560                        }  //end of if(!interval)
 561                        else {
 562                    
 563                          // cout << "number is an interval" << endl;
 564                            char buffer_day [20];
 565                            sprintf(buffer_day, "%08d", day_sub1);
 566                            ye_mo_da = String(buffer_day);
 567                        }
 568 david.dillard 1.54 
 569 w.white       1.43    //cout << "when days are added the string is  " << ye_mo_da << endl;
 570                    
 571 david.dillard 1.54     //get hours, minutes, seconds and microseconds
 572 w.white       1.43     Uint64 after_ymd = microSec%_ONE_DAY;
 573                    
 574 w.white       1.47     Uint32 hour_num = (Uint32)(after_ymd/_ONE_HOUR);
 575                        Uint32 after_ymdh = (Uint32)(after_ymd%_ONE_HOUR);
 576 w.white       1.43 
 577                        Uint32 min_num = after_ymdh/_ONE_MINUTE;
 578                        Uint32 after_ymdhm = after_ymdh%_ONE_MINUTE;
 579                    
 580                        Uint32 sec_num = after_ymdhm/_ONE_SECOND;
 581                    
 582                        Uint32 mic_num = after_ymdhm%_ONE_SECOND;
 583                    
 584                    
 585                    
 586                        //converting hours, minutes, seconds and microseconds from Uint32 -> String
 587                    
 588                        char buffer_hour [10];
 589                        sprintf(buffer_hour, "%02d", hour_num);
 590                        ye_mo_da_ho = ye_mo_da.append(buffer_hour);
 591                            //cout << "when hours are added the string is  " << ye_mo_da_ho << endl;
 592                    
 593                        char buffer_min [10];
 594                        sprintf(buffer_min, "%02d", min_num);
 595                        ye_mo_da_ho_mn = ye_mo_da_ho.append(buffer_min);
 596                           //cout << "when minutes are added the string is  " << ye_mo_da_ho_mn << endl;
 597 w.white       1.43 
 598                    
 599                        char buffer_sec [10];
 600                        sprintf(buffer_sec, "%02d", sec_num);
 601                        ye_mo_da_ho_mn_se = ye_mo_da_ho_mn.append(buffer_sec);
 602                       //cout << "when seconds are adder string is  " << ye_mo_da_ho_mn_se << endl;
 603                    
 604                        char buffer_mic [15];
 605                        if (interval) {     //adding correct UCT off set depending on wether object should be an interval or not
 606                            sprintf(buffer_mic, ".%06d:000", mic_num);
 607                        }
 608                        else{
 609                            sprintf(buffer_mic, ".%06d+000", mic_num);
 610                        }
 611                        final = ye_mo_da_ho_mn_se.append(buffer_mic);
 612 david.dillard 1.54     //cout << "when at the end of constructor that takes Uint64 created string is  " << final  << endl << endl;
 613 w.white       1.43 
 614                        _rep = new CIMDateTimeRep();
 615 kumpf         1.53     AutoPtr<CIMDateTimeRep> rep(_rep);
 616                    
 617 w.white       1.43     if (!_set(final)) {
 618                            Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 619                                        "CIMDateTime::CIMDateTime(Uint64 microSec, Boolean interval) failed");
 620                            throw InvalidDateTimeFormatException(); //can't pass message to this exceptions
 621                        }
 622 david.dillard 1.54 
 623 kumpf         1.53     rep.release();
 624 mike          1.10 }
 625                    
 626 w.white       1.43 
 627                    /*copies CIMDateTimeRep from passed in paramiter to the the callers CIMDateTimeRep
 628 david.dillard 1.54 effectivly copies value of one CIMDateTime to another. All data in held in
 629 w.white       1.43 CIMDateTimeRep
 630                    */
 631 mike          1.10 CIMDateTime& CIMDateTime::operator=(const CIMDateTime& x)
 632                    {
 633 w.white       1.43     //cout << "in copy constructor" << cout;
 634                        if (&x != this){
 635                            _rep->copy(x._rep);
 636                        }
 637                            //memcpy(_rep->data, x._rep->data, sizeof(_rep->data));
 638 mike          1.10 
 639                        return *this;
 640                    }
 641                    
 642 a.arora       1.40 CIMDateTime::~CIMDateTime()
 643                    {
 644                        delete _rep;
 645                    }
 646                    
 647 w.white       1.43 /* retruns a string holding the CIMDateTime value
 648                    */
 649 kumpf         1.26 String CIMDateTime::toString () const
 650 mike          1.10 {
 651 kumpf         1.26     return String (_rep->data);
 652 mike          1.10 }
 653                    
 654 w.white       1.43 /* sets a CIMDateTime to a zero valued interval
 655                    */
 656 mike          1.10 void CIMDateTime::clear()
 657                    {
 658 w.white       1.43    //cout << "this is the start of the clear method" << endl;
 659                       strcpy(_rep->data, _NULL_INTERVAL_TYPE_STRING);
 660                        String blank = "";
 661                        String str = String("000000");
 662                        Uint16 dum = _rep->set_microSec(str);
 663                        _rep->set_seconds("00");
 664                        _rep->set_minutes("00");
 665                        _rep->set_hours("00");
 666                        _rep->set_days("00");
 667 david.dillard 1.54     _rep->set_utcOffSet(String(":000"));
 668 w.white       1.43    //cout << "end of the clear method" << endl << endl;
 669                    
 670 mike          1.10 }
 671                    
 672 w.white       1.43 
 673                    /* this is one of the only ways to create a CIMDateTime object most of the constructors
 674                    call this method. It checks the value of each filed and returns false if any of them do
 675                    not have the correct format
 676                    */
 677 kumpf         1.26 Boolean CIMDateTime::_set(const String & dateTimeStr)
 678 mike          1.10 {
 679                        clear();
 680 kumpf         1.31     CString dtStr = dateTimeStr.getCString();
 681                        const char* str = dtStr;
 682 kumpf         1.26 
 683 w.white       1.43 
 684 mike          1.10     // Be sure the incoming string is the proper length:
 685 w.white       1.43     if (dateTimeStr.size() != CIMDateTimeRep::FORMAT_LENGTH){
 686                            Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 687                                  "CIMDateTime object string is not of the proper length");
 688                            return false;
 689                        }
 690 mike          1.10 
 691                    
 692                        // Determine the type (date or interval); examine the 21st character;
 693 w.white       1.43     // it must be one of ':' (interval), '+' (date), or '-' (date)
 694 mike          1.10     const Uint32 SIGN_OFFSET = 21;
 695                        const Uint32 DOT_OFFSET = 14;
 696 kumpf         1.62     Boolean isInterval = (dateTimeStr[SIGN_OFFSET] == ':');
 697 mike          1.10 
 698 w.white       1.43     if (!isInterval && dateTimeStr[SIGN_OFFSET] != '+' && dateTimeStr[SIGN_OFFSET] != '-'){
 699                            Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 700 w.white       1.44              "CIMDateTime object has an incorrect format.");
 701 w.white       1.43         return false;
 702                        }
 703 mike          1.10 
 704                    
 705                        // Check for the decimal place:
 706                    
 707 w.white       1.43     if (dateTimeStr[DOT_OFFSET] != '.'){
 708                            Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 709                                 "Incorrect Format - CIMDateTime object dosen't have decimal point in position 14");
 710                            return false;
 711                        }
 712 david.dillard 1.54 
 713 w.white       1.43 
 714 mike          1.10 
 715 kumpf         1.63     // Check to see if other characters are digits or astrisks (*)
 716 mike          1.10 
 717 kumpf         1.63     for (Uint32 i = 0; i < CIMDateTimeRep::FORMAT_LENGTH; i++)
 718                        {
 719                            if (!((i == DOT_OFFSET) || (i == SIGN_OFFSET) ||
 720                                  ((dateTimeStr[i] >= '0') && (dateTimeStr[i] <= '9')) ||
 721                                  (dateTimeStr[i] == '*')))
 722                            {
 723 w.white       1.43             Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 724 w.white       1.44                     "CIMdateTime object has an incorrect format.");
 725 w.white       1.43             return false;
 726                            }
 727 mike          1.10     }
 728 david.dillard 1.54 
 729 mike          1.10 
 730                        // Check to see if the month and day are in range (date only):
 731                    
 732 w.white       1.43     String buffer;
 733                        Field ans;
 734 david.dillard 1.54 
 735 mike          1.10     if (!isInterval)
 736                        {
 737 w.white       1.43       //get year
 738                          /* need to check that the field is valid as far as astrisk (*) are concerned */
 739                          buffer = dateTimeStr.subString(0,4);
 740                          ans = fieldcheck(buffer, _rep->year);
 741                          if (ans == SOME_WILD_CARDS){
 742                              Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 743 w.white       1.44                "CIMDateTime - Format of the string is incorrect. ");
 744 w.white       1.43           return false;
 745                          }
 746                          else if (ans == ONLY_WILD_CARDS) {
 747                              if (!restOfFields(4,dateTimeStr)){
 748                                  Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 749                                    "CIMDateTime - Format of the string is incorrect. All fields after the year \
 750 w.white       1.44                             field should be wild cards.");
 751 w.white       1.43               return false;
 752                              }
 753                          }
 754 david.dillard 1.54 
 755 kumpf         1.63         // Get the month:
 756 w.white       1.43         buffer = dateTimeStr.subString(4,2);
 757                            ans = fieldcheck(buffer, _rep->month);
 758                            if (ans == SOME_WILD_CARDS) {
 759                                Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 760 w.white       1.45                 "CIMDateTime - Format of the month field is incorrect.s");
 761 w.white       1.44            //cout << "one was returned form fieldcheck" << endl << endl;
 762 w.white       1.43             return false;           // month field has both wildcards and digits
 763                            }
 764                    
 765 david.dillard 1.54         else if (ans == ONLY_DIGITS) {          // month field has only digits
 766 w.white       1.43             long month = atoi(buffer.getCString());
 767                    
 768                                // Allow for zero month - default value processing
 769 kumpf         1.63             if (month == 0 || month > 12) {
 770 w.white       1.43                 Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 771                                    "CIMDateTime - Format of the string is incorrect. Month fild is out of range");
 772 kumpf         1.63                 return false;
 773 w.white       1.43             }
 774                            }
 775                            else if (ans == ONLY_WILD_CARDS) {
 776                              if (!restOfFields(6,dateTimeStr)){
 777                                  Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 778                                    "CIMDateTime - Format of the string is incorrect. All fields after the month \
 779 w.white       1.44                         field should ve wild cards.");
 780 w.white       1.43               return false;
 781                              }
 782                            }
 783                    
 784 david.dillard 1.54 
 785 kumpf         1.63         // Get the day:
 786 w.white       1.43 
 787                            buffer = dateTimeStr.subString(6,2);
 788                            ans = fieldcheck(buffer, _rep->days);
 789                            if (ans == SOME_WILD_CARDS) {
 790                                Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 791 w.white       1.44                 "CIMDateTime - Format of the day field is incorrect.");
 792 w.white       1.43             return false;           // month field has both wildcards and digits
 793                            }
 794                    
 795 david.dillard 1.54         else if (ans == ONLY_DIGITS) {          // month field has only digits
 796                    
 797 kumpf         1.63             long day = atoi(buffer.getCString());
 798 w.white       1.43 
 799 david.dillard 1.54             // Allow for zero day - 0 "day" values are only allowed for default object
 800                                /*ATTN: this does not check for the number of days in a
 801 w.white       1.43             particular month
 802                                */
 803                                if (day == 0 || day > 31){
 804                                    Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 805                                            "CIMDateTime - Format of the string is incorrect. Day field is incorrect");
 806 kumpf         1.63                 return false;
 807 w.white       1.43             }
 808                             }
 809                            else if (ans == ONLY_WILD_CARDS) {
 810                              if (!restOfFields(6,dateTimeStr)){
 811                                  Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 812                                    "CIMDateTime - Format of the string is incorrect. All fields after day field \
 813 w.white       1.44                             should be only wild cards.");
 814 w.white       1.43               return false;
 815                              }
 816                            }
 817                    
 818 david.dillard 1.54         //get UTC off set   for a Time Stamp
 819 w.white       1.43 
 820                            buffer = dateTimeStr.subString(21,4);
 821                            _rep->utcOffSet = buffer;
 822                            Uint32 spot = buffer.find("*");
 823                            //cout << "before if" << endl;
 824                            if(spot != PEG_NOT_FOUND){  // the UTC must not have astricks in it
 825                                Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 826                                    "CIMDateTime - Format of the is incorrect. UTC offset should not have \
 827 w.white       1.44                           a wild card in it.");
 828 w.white       1.43             return false;
 829 david.dillard 1.54         }
 830 w.white       1.43 
 831                        }  //end of if(!interval)
 832                    
 833                        else{     //Object is an Interval
 834                    
 835                            //get days if object is an interval
 836                            buffer = dateTimeStr.subString(0,8);
 837                            ans = fieldcheck(buffer, _rep->days);
 838                            if (ans == SOME_WILD_CARDS) {
 839                                Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 840                                    "CIMDateTime - Format of the object is incorrect. Day field must be have all \
 841 w.white       1.44                           wild cards or no wild cards.");
 842 w.white       1.43             return false;
 843                            }
 844                            else if (ans == ONLY_WILD_CARDS) {
 845                              if (!restOfFields(8,dateTimeStr)){
 846                                  Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 847                                      "CIMDateTime - Format of the object is incorrect. All fields after day field \
 848 david.dillard 1.54                             should be wild cards.");
 849 w.white       1.43               return false;
 850                              }
 851                            }
 852                    
 853                                          //ATTN: this block MAY not be needed
 854                            // check to make sure UTC for Intervals it '000'
 855                            buffer = dateTimeStr.subString(21,4);
 856                            _rep->utcOffSet = buffer;
 857 kumpf         1.62         if (!String::equal(_rep->utcOffSet, ":000"))
 858                            {
 859 w.white       1.43             Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 860                                       "CIMDateTime - Format of the object is incorrect. Can not set the \
 861                                              the UTC off set of an Interval");
 862                               // cout << "interval UTC offset is worng" << endl;
 863                                return false;
 864                            }
 865 mike          1.10 
 866                    
 867 w.white       1.43     }
 868 mike          1.10 
 869 w.white       1.43     //cout << "after is interval block" << endl;
 870 mike          1.10 
 871 w.white       1.43     // Check the hours and minutes:
 872                        buffer = dateTimeStr.subString(8,2);
 873                        ans = fieldcheck(buffer, _rep->hours);
 874                        if (ans == SOME_WILD_CARDS) {
 875                            Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 876                                       "CIMDateTime - Format of the object is incorrect.Hour field must have all \
 877 w.white       1.44                           wild cards or no wild cards.");
 878 w.white       1.43         return false;           // hour field has both wildcards and digits
 879                         }
 880                    
 881 david.dillard 1.54     else if (ans == ONLY_DIGITS) {          // hour field has only digits
 882 w.white       1.43         long hours = atoi(buffer.getCString());
 883                    
 884                            if (hours > 23) {
 885                                Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 886                                       "CIMDateTime - Format of the object is incorrect. Hour value is out of range");
 887                                return false;
 888                            }
 889 david.dillard 1.54 
 890 w.white       1.43     }
 891 mike          1.10 
 892 w.white       1.43     else if (ans == ONLY_WILD_CARDS) {
 893                              if (!restOfFields(10,dateTimeStr)){
 894                                  Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 895                                    "CIMDateTime - Format of the object is incorrect. All fields after the hour field \
 896 david.dillard 1.54                             should be wild cards.");
 897 w.white       1.43               return false;
 898                              }
 899                         }
 900                    
 901 david.dillard 1.54 
 902 w.white       1.43    //cout << "this is after getting hours" << endl;
 903                    
 904                        buffer = dateTimeStr.subString(10,2);
 905                        ans = fieldcheck(buffer, _rep->minutes);
 906                        if (ans == SOME_WILD_CARDS) {
 907                            Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 908                                       "CIMDateTime - Format of the object is incorrect.Minute field must have all \
 909 w.white       1.44                           wild cards or no wild cards.");
 910 w.white       1.43         return false;           // minutes field has both wildcards and digits
 911 mike          1.10     }
 912                    
 913 david.dillard 1.54     else if (ans == ONLY_DIGITS) {          // minutes field has only digits
 914 w.white       1.43         long minutes = atoi(buffer.getCString());
 915 mike          1.10 
 916 w.white       1.43         if (minutes > 59) {
 917                                Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 918                                       "CIMDateTime - Format of the object is incorrect.Minute value is out of range");
 919                                return false;
 920                    
 921                            }
 922 kumpf         1.63     }
 923 w.white       1.43 
 924                        else if (ans == ONLY_WILD_CARDS) {
 925                              if (!restOfFields(12,dateTimeStr)){
 926                                  Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 927                                    "CIMDateTime - Format of the object is incorrect. All fields after the minute \
 928 david.dillard 1.54                             field should be wild cards.");
 929 w.white       1.43               return false;
 930                              }
 931                          }
 932                    
 933                    
 934 w.white       1.45 
 935 david.dillard 1.54     // cout << "before getting seconds" << endl;
 936 w.white       1.43 
 937                        buffer = dateTimeStr.subString(12,2);
 938                        ans = fieldcheck(buffer, _rep->seconds);
 939                        if (ans == SOME_WILD_CARDS) {
 940                            Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 941                                       "CIMDateTime - Format of the object is incorrect.Second field must have all \
 942 w.white       1.44                           wild cards or no wild cards.");
 943 w.white       1.43         return false;           // seconds field has both wildcards and digits
 944                        }
 945 mike          1.10 
 946 w.white       1.47 
 947 w.white       1.43     else if (ans == ONLY_DIGITS) {          // minutes field has only digits
 948                            long seconds = atoi(buffer.getCString());
 949                            if (seconds > 59){
 950                                Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 951                                       "CIMDateTime - Format of the object is incorrect.Minute value is out of range");
 952                                return false;
 953                            }
 954 david.dillard 1.54 
 955 w.white       1.43     }
 956                        else if (ans == ONLY_WILD_CARDS) {
 957                              if (!restOfFields(14,dateTimeStr)){
 958                                  Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 959                                    "CIMDateTime - Format of the object is incorrect. All fields after the seconds \
 960 w.white       1.44                             field should have wild cards.");
 961 w.white       1.43               return false;
 962                              }
 963                          }
 964                    
 965                    
 966                        //get micro Seconds
 967                        String buffer_micro = dateTimeStr.subString(15,6);
 968                        Uint32 answ = _rep->set_microSec(buffer_micro);
 969                        if (answ == 1) {
 970                             Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
 971                                    "CIMDateTime - Format of micro seconds field is incorrect");
 972                            return false;
 973                        }
 974 david.dillard 1.54 
 975 mike          1.10 
 976 w.white       1.43     memcpy(_rep->data, str, sizeof(_rep->data));
 977 david.dillard 1.54 
 978 w.white       1.43     return true;
 979 mike          1.10 
 980 w.white       1.43 }
 981 mike          1.10 
 982                    
 983                    
 984 david.dillard 1.54 /* If a field has a wild card then all the fields with lower significance
 985 w.white       1.43     should have wild cards. This method makes sure of this.
 986                    */
 987                    Boolean CIMDateTime::restOfFields(Uint32 start_position,const String & inStr)
 988                    {
 989                        String splatCDT = "**************.******";
 990                        Uint32 placeNum = splatCDT.size() - start_position;
 991 mike          1.10 
 992 w.white       1.43     String comp = splatCDT.subString(start_position, placeNum);
 993                        String in_comp = inStr.subString(start_position, placeNum);
 994                        if (String::compare(comp, in_comp))
 995                            return false;
 996                        else
 997                            return true;
 998 mike          1.10 }
 999                    
1000 w.white       1.43 
1001                    
1002                    /*this method is just a public rapper for the _set command
1003                    */
1004 kumpf         1.26 void CIMDateTime::set(const String & str)
1005 mike          1.10 {
1006 w.white       1.43     if (!_set(str)){
1007 kumpf         1.63         throw InvalidDateTimeFormatException();
1008 w.white       1.43     }
1009                    }
1010                    
1011                    
1012                    
1013                    /*public rapper for _toMicroSeconds
1014                    converts object to UTC then it calculates the number of microseconds in the converted object
1015                    */
1016 w.white       1.57 Uint64 CIMDateTime::toMicroSeconds() const
1017 david.dillard 1.54 {
1018                    
1019 w.white       1.43     CIMDateTime un_norm;
1020 w.white       1.49     //un_norm._rep = new CIMDateTimeRep();
1021 w.white       1.43     un_norm._rep->copy(_rep);
1022                    
1023                        un_norm.convertToUTC();
1024 david.dillard 1.54 
1025 w.white       1.43     const Uint64 norm_micSec = un_norm._toMicroSeconds();
1026                    
1027                        return (norm_micSec);
1028                    }
1029                    
1030                    
1031                    
1032                    /*returns number of Micro seconds represented by a CIMDateTime object
1033                    */
1034                    Uint64 CIMDateTime::_toMicroSeconds()
1035                    {
1036                    
1037                        Uint64 mic = 0;
1038                        Uint64 sec = 0;
1039                        Uint64 min = 0;
1040                        Uint64 hor = 0;
1041                        Uint64 day = 0;
1042                        Uint64 mon = 0;
1043                        Uint64 yea = 0;
1044                        Uint64 date = 0;
1045                        Uint64 yea_400 = 0;
1046 w.white       1.43     Uint64 day_400 =0;
1047                    
1048                        Uint32 mic_sp= _rep->microSec.find('*');
1049                        if (mic_sp == PEG_NOT_FOUND) {
1050                            mic = atol(_rep->microSec.getCString());
1051                        }
1052                        else if (mic_sp > 0) {
1053                            String subMic = _rep->microSec.subString(0, mic_sp);
1054 w.white       1.52         mic = Uint64(atol(subMic.getCString()) * pow((double)10,(double)(6-mic_sp)));
1055 w.white       1.43     }
1056                        else{
1057                            mic = 0;
1058                        }
1059 david.dillard 1.54 
1060 w.white       1.43 
1061                        if (_rep->seconds.find('*') == PEG_NOT_FOUND) {
1062 david.dillard 1.54         sec = atol(_rep->seconds.getCString()) * 1000000;
1063 w.white       1.43     }
1064                    
1065 david.dillard 1.54     if (_rep->minutes.find('*') == PEG_NOT_FOUND) {
1066 w.white       1.43         min = atol(_rep->minutes.getCString()) * _ONE_MINUTE;
1067                        }
1068 david.dillard 1.54 
1069 w.white       1.43     if (_rep->hours.find('*') == PEG_NOT_FOUND) {
1070                            hor = (atol(_rep->hours.getCString())) * _ONE_HOUR;
1071                        }
1072 david.dillard 1.54 
1073 w.white       1.43 
1074                     //cout << "this is what the object holds year - " << _rep->year << " months - " << /
1075                        // _rep->month << " - days  " << _rep->days << endl << "hour - " << _rep->hours << endl;
1076                    // cout << "minute - " << _rep->minutes << endl;
1077 david.dillard 1.54 
1078 w.white       1.43 
1079                        if (!isInterval()) {
1080                    
1081                            /* change years into micro Seconds. Taking leap years into accout there are 146,097
1082                             days every 400 years. Remainder years outside of 400 year blocks will be handled by
1083                             a while loop
1084                             */
1085                            Uint64 yea_num = 0;
1086                    
1087                            if (_rep->year.find('*') == PEG_NOT_FOUND) {
1088                                yea_num = atol(_rep->year.getCString());
1089                            }
1090 david.dillard 1.54 
1091 w.white       1.43 
1092                            Uint64 yea_400 = yea_num/400;
1093                            Uint64 day_400  = yea_400 * 146097;
1094                    
1095                            Uint32 count_le = 0;
1096                            Uint32 count_r = 0;
1097                            Uint64 yea_rem = yea_num%400;
1098                            Uint32 leap_next = 0;
1099                            Uint32 count = 1;
1100                            Uint16 lp = 0;
1101                            Uint64 day_rem;
1102                    
1103                    
1104                               // (((count%4 == 0) && (count%100 != 0)) || (count%400 == 0)) is only true for leap years
1105 w.white       1.45         for (Uint32 i=1; i<=yea_rem; i++) {
1106 w.white       1.43             if (!(((count%4 == 0) && (count%100 != 0)) || (count%400 == 0))) {
1107                                    count_r = count_r + 1;
1108                                    count = count + 1;
1109                                    leap_next = leap_next + 1;
1110                                }
1111                                else {
1112                                    count_le = count_le + 1;
1113                                    count = count + 1;
1114                                    leap_next = 0;
1115                                }
1116                            }
1117 david.dillard 1.54 
1118 w.white       1.43 
1119                            /*lp is 0 for non leap years and 1 for leap years
1120                            */
1121 david.dillard 1.54         if ((((count%4 == 0) && (count%100 != 0)) || (count%400 == 0))) {
1122 w.white       1.43             lp = 1;
1123                               //cout << "months are being calculated for a leap year" << endl;
1124                            }
1125                    
1126                    
1127                            if (_rep->month.find('*') == PEG_NOT_FOUND) {
1128 david.dillard 1.54 
1129 w.white       1.43             //get number of days eqivalent to number of months in the object and multipy by number of
1130                                //micro seconds in a day
1131                                switch (atol(_rep->month.getCString())) { //months can't be equal to zero
1132                                case 1:
1133                                    mon = 00;
1134                                    break;
1135                                case 2:
1136                                    mon = 31 * _ONE_DAY;
1137                                    break;
1138                                case 3:
1139                                    mon = ((59+lp) * _ONE_DAY);
1140                                    break;
1141                                case 4:
1142                                    mon = ((90+lp) * _ONE_DAY);
1143                                    break;
1144                                case 5:
1145                                    mon = ((120+lp) * _ONE_DAY);
1146                                    break;
1147                                case 6:
1148                                    mon = ((151+lp) * _ONE_DAY);
1149                                    break;
1150 w.white       1.43             case 7:
1151                                    mon = ((181+lp) * _ONE_DAY);
1152                                    break;
1153                                case 8:
1154                                    mon = ((212+lp) * _ONE_DAY);
1155                                    break;
1156 david.dillard 1.54             case 9:
1157 w.white       1.43                 mon = ((243+lp) * _ONE_DAY);
1158                                    break;
1159                                case 10:
1160                                    mon = ((273+lp) * _ONE_DAY);
1161                                    break;
1162                                case 11:
1163                                    mon = ((304+lp) * _ONE_DAY);
1164                                    break;
1165                                case 12:
1166                                    mon = ((334+lp) * _ONE_DAY);
1167                                    break;
1168                                default:
1169 w.white       1.48                // cout << "error calculating months" << endl;
1170                                   // cout << "this is data " << (String)_rep->data << endl;
1171 david.dillard 1.54                 throw InvalidDateTimeFormatException();
1172 w.white       1.43                 Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
1173                                                  "Code should never reach this point in \
1174                                                  CIMDateTime::_toMicroSecdonds() ");
1175                                    assert(false);
1176                                }
1177                            } // end of if(!interval) block
1178                    
1179 david.dillard 1.54 
1180                    
1181 w.white       1.43         day_rem = (count_le * 366) + (count_r * 365);
1182 david.dillard 1.54         Uint64 yea = (day_rem+day_400) * _ONE_DAY;
1183                    
1184                    
1185 w.white       1.43         if (_rep->days.find('*') == PEG_NOT_FOUND) {
1186                                day = ((atol(_rep->days.getCString()))-1) * _ONE_DAY;   //time stamp "days" go from 1-31 ther is no zero
1187                            }
1188 david.dillard 1.54         day += yea; // not sure why this is needed but yea doesn't hold it's vlaue outside of
1189 w.white       1.43                     //the if!(interval) block
1190                    
1191                            //y_dd = yea/PEGASUS_UINT64_LITERAL(86400000000);  //this is just here to illistate need for "day+=yea"
1192                            //  cout << " this is at the end of the not interval block and year is " << y_dd << endl;
1193                    
1194                        }// end of if(!interval)
1195                    
1196                        else{
1197                            if (_rep->days.find('*') == PEG_NOT_FOUND) {
1198                                day = (atol(_rep->days.getCString())) * _ONE_DAY;
1199                            }
1200 david.dillard 1.54     }
1201 w.white       1.43 
1202                    
1203                        // Uint32 y_dd = yea/PEGASUS_UINT64_LITERAL(86400000000);   //this is just here to illistate need for "day+=yea"
1204                       // cout << " this is right before the addition and year is " << y_dd << endl;
1205                    
1206 david.dillard 1.54     date = mic+sec+min+hor+day+mon; //yea is not include becaue it is included in the day value of TimeStamps
1207                    
1208 w.white       1.43     return date;
1209 mike          1.10 }
1210                    
1211 w.white       1.43 
1212                    
1213                    /*compare two CIMDateTime objects for equality
1214                    */
1215 mike          1.10 Boolean operator==(const CIMDateTime& x, const CIMDateTime& y)
1216                    {
1217 kumpf         1.26     return x.equal (y);
1218 kumpf         1.14 }
1219                    
1220 w.white       1.43 
1221 david.dillard 1.54 
1222                    /* converts Time Stamps to their UTC (GMT) representation. For Intervals
1223 w.white       1.43     it does nothing.
1224                    */
1225                    void CIMDateTime::convertToUTC()
1226 kumpf         1.14 {
1227 david.dillard 1.54 
1228 w.white       1.43     if (isInterval()) {
1229                            return;    //no conversion should not be done on Intervals
1230                        }
1231                    
1232                        Uint64 normNum = 0;
1233                    
1234                        Uint64 un_normNum = this->_toMicroSeconds();
1235                    
1236 w.white       1.47    // Uint32 unnor = un_normNum/PEGASUS_UINT64_LITERAL(1000000000);
1237                       // Uint32 runnor = un_normNum%PEGASUS_UINT64_LITERAL(1000000000);
1238 david.dillard 1.54 
1239 w.white       1.43     // get UTC offSet and change it in microseconds
1240                        String utcOS = _rep->utcOffSet.subString(1,3);
1241                        Uint32 offSet = atol((utcOS).getCString());
1242                        Uint64 offSet_hor = (offSet/60) * _ONE_HOUR;
1243                        Uint64 offSet_min = (offSet%60) * _ONE_MINUTE;
1244 kumpf         1.62     String mesO = "overflow has occurred in normalization";
1245 w.white       1.43     MessageLoaderParms parmsOv("Common.CIMDateTime.UTC_OVERFLOW",
1246 kumpf         1.62         "overflow has occurred during conversion to UTC");
1247 w.white       1.43     MessageLoaderParms parmsUn("Common.CIMDateTime.UTC_UNDERFLOW",
1248 kumpf         1.62         "underflow has occurred during conversion to UTC");
1249 w.white       1.43 
1250 kumpf         1.63     char sign;   // Get the sign and UTC offset.
1251 w.white       1.43     sign = _rep->data[21];
1252                    
1253                        //if there are no wild cards in the minute postion then the entire utc offSet
1254                        //will effect the CIMDateTime value
1255                    
1256                        if (_rep->minutes.find('*') == PEG_NOT_FOUND) {
1257 david.dillard 1.54         if ( sign == '-' ) {
1258 w.white       1.43             if (_TEN_THOUSAND_YEARS < (un_normNum + (offSet_hor + offSet_min))){
1259 w.white       1.48                // cout << " this is value " << this->toString() << endl;
1260 w.white       1.43                 throw DateTimeOutOfRangeException(parmsOv);
1261                                }
1262                                normNum = un_normNum + (offSet_hor + offSet_min);
1263                            }
1264                            else{
1265                                if (un_normNum < (offSet_hor + offSet_min)) {
1266                                    throw DateTimeOutOfRangeException(parmsUn);
1267                                }
1268                                 normNum = un_normNum - (offSet_hor + offSet_min);
1269                            }
1270                        }
1271                    
1272                        //if the hours section has no wild cards but the minutes section does then only on hour
1273                        //position will be effected by the uct off Set
1274                        else if (_rep->hours.find('*') == PEG_NOT_FOUND) {
1275 david.dillard 1.54         if ( sign == '-' ) {
1276 w.white       1.43             if (_TEN_THOUSAND_YEARS < (un_normNum + (offSet_hor))){
1277                                    throw DateTimeOutOfRangeException(parmsOv);
1278                                }
1279                                 normNum = un_normNum + (offSet_hor);
1280                            }
1281                            else{
1282                                if (un_normNum < (offSet_hor)) {
1283                                    throw DateTimeOutOfRangeException(parmsUn);
1284                                }
1285                                 normNum = un_normNum - (offSet_hor);
1286                            }
1287                        }
1288                        else{ //if this block is executed then the utc offSet has no effect on CIMDateTime value
1289                            normNum = un_normNum;
1290                        }
1291                    
1292                    
1293                        CIMDateTime norm_CDT = CIMDateTime(normNum,false);
1294                    
1295                        this->_rep->copy(norm_CDT._rep);
1296                    
1297 w.white       1.43     return;
1298 kumpf         1.14 }
1299                    
1300 w.white       1.43 
1301 kumpf         1.61 /*returns true if object is an interval.  Note: This method exists only for
1302                      compatibility reasons.  It is superceded by the "const" form of the method.
1303                    */
1304                    Boolean CIMDateTime::isInterval()
1305                    {
1306                        return ((const CIMDateTime*)this)->isInterval();
1307                    }
1308 w.white       1.43 
1309                    /*returns true if object is an interval
1310                    */
1311                    Boolean CIMDateTime::isInterval() const
1312 kumpf         1.14 {
1313 kumpf         1.63     const Uint32 SIGN_OFFSET = 21;
1314 kumpf         1.14 
1315 kumpf         1.26     Boolean isInterval = strcmp(&_rep->data[SIGN_OFFSET], ":000") == 0 ;
1316 kumpf         1.14     return isInterval;
1317                    }
1318                    
1319 w.white       1.43 
1320                    /*compares caller to passed in paramiter for eqaulity
1321                    */
1322 kumpf         1.26 Boolean CIMDateTime::equal (const CIMDateTime & x) const
1323                    {
1324 w.white       1.43     if ((x.isInterval() && !this->isInterval()) || (!x.isInterval() && this->isInterval())) {
1325 david.dillard 1.54         throw TypeMismatchException();
1326 w.white       1.43     }
1327                    
1328                        CIMDateTime current = CIMDateTime((String)_rep->data);
1329                        CIMDateTime compare = CIMDateTime((String)x._rep->data);  // not sure why all this is needed but const has somthing to do with it
1330 david.dillard 1.54 
1331 w.white       1.43     Uint32 spl_pos = current.getHighestWildCardPosition(compare);
1332                    
1333                        current.insert_WildCard(spl_pos);
1334                        compare.insert_WildCard(spl_pos);
1335 david.dillard 1.54 
1336 w.white       1.43     if (current.toMicroSeconds() == compare.toMicroSeconds()) {
1337                            return true;
1338                        }
1339 david.dillard 1.54     else
1340                            return false;
1341                    
1342 kumpf         1.26 }
1343                    
1344 w.white       1.43 
1345                    
1346                    /*subtacts two CIMDateTime objects of like types
1347                    */
1348 kumpf         1.61 Sint64 CIMDateTime::getDifference(CIMDateTime startTime, CIMDateTime finishTime)
1349 david.dillard 1.54 {
1350                    
1351 w.white       1.43     CIMDateTime sta = startTime;
1352                        CIMDateTime fin = finishTime;
1353                        CIMDateTime sta_norm;
1354                        CIMDateTime fin_norm;
1355                        Uint64 startT_num;
1356                        Uint64 finishT_num;
1357                        Sint64 diff_num;
1358                    
1359                        /* the throwing of this expceptoin is only needed becasue of back wards compatability issues
1360                        (i.e. this is the way getDifferance worked before). The operator- does not behave this way.
1361                        */
1362                        if ((sta.isInterval() && (!( fin.isInterval()))) || ((!( sta.isInterval())) &&  fin.isInterval())) {
1363                            throw InvalidDateTimeFormatException();
1364                        }
1365                    
1366                        Uint32 splat_pos;
1367                        splat_pos = sta.getHighestWildCardPosition(fin);
1368 david.dillard 1.54 
1369 w.white       1.43     sta.insert_WildCard(splat_pos);
1370                        fin.insert_WildCard(splat_pos);
1371 david.dillard 1.54 
1372 w.white       1.43     startT_num = sta.toMicroSeconds();
1373                        finishT_num = fin.toMicroSeconds();
1374                    
1375                        diff_num = finishT_num - startT_num;
1376                    
1377                        return diff_num;
1378                     }
1379                    
1380                    
1381                    
1382 david.dillard 1.54 
1383                    /*  checks to make sure the format of a particular field in the DateTime string is correct.
1384 w.white       1.43     Returns
1385                            ONLY_WILD_CARDS - field contains all wild cards
1386                            SOME_WILD_CARDS - field contains some wild cards (error)
1387                            ONLY_DIGITS - field contains only digits
1388                    */
1389                    CIMDateTime::Field CIMDateTime::fieldcheck(const String & in_p, String & rep_field)
1390 kumpf         1.14 {
1391 w.white       1.43     Uint32 post;
1392                        rep_field = in_p;
1393 david.dillard 1.54 
1394 w.white       1.43     post = in_p.find("*");
1395                        if (post == PEG_NOT_FOUND) {
1396                            return ONLY_DIGITS;
1397                        }
1398                    
1399                        const String ast = "**********";
1400                        String comp = String(ast, in_p.size());   //creates a string of asteriks with the same length as in_p
1401                        if (!String::compare(in_p, comp)) {
1402                            return ONLY_WILD_CARDS;                            //fields is all astriks
1403                        }
1404                        else{
1405                            return SOME_WILD_CARDS;                //error - mix of asterisk and numbers  in field
1406                        }
1407                    
1408                    }
1409                    
1410                    
1411                    
1412                    
1413                    /* This method does not change the value of object, it only converts the
1414                        representation form one time zone to the time zone specified.
1415 w.white       1.43     @param cdt Time Stamp object that will be converted
1416 david.dillard 1.54     @param utc uct-offset in minutes that represents the time zone  to be
1417 w.white       1.43     converted to
1418 david.dillard 1.54     Returns a copy of the calling object modified to represent the same
1419 w.white       1.43     time in a different time zone.
1420                    */
1421                    void CIMDateTime::setUtcOffSet(Sint32 utc)
1422 david.dillard 1.54 {
1423 w.white       1.43     if(this->isInterval()){
1424                            return;
1425                        }
1426 kumpf         1.14 
1427 w.white       1.43     MessageLoaderParms parmsOv("Common.CIMDateTime.UTC_OVERFLOW",
1428 kumpf         1.62         "overflow has occurred during conversion to UTC");
1429 w.white       1.43     MessageLoaderParms parmsUn("Common.CIMDateTime.UTC_UNDERFLOW",
1430 kumpf         1.62         "underflow has occurred during conversion to UTC");
1431 w.white       1.43 
1432 david.dillard 1.54     // convert CIMDateTime to microseconds.
1433 w.white       1.43     Uint64 cdt_MicroSec = this->toMicroSeconds();
1434 david.dillard 1.54     Uint32 offSet = abs(utc);
1435 w.white       1.43     Uint64 offSet_hor = (offSet/60) * _ONE_HOUR;
1436                        Uint64 offSet_min = (offSet%60) * _ONE_MINUTE;
1437 david.dillard 1.54     Uint64 cdt_MicroSecSum = 0;
1438 w.white       1.43     String sgn_offset;
1439 david.dillard 1.54 
1440                        //Add (if utc is - ) or subtract (if utc is +) utc to/from DateTime.
1441 w.white       1.43     if (utc >= 0) {
1442                            if (cdt_MicroSec < (offSet_hor + offSet_min)) {
1443                                throw DateTimeOutOfRangeException(parmsOv);
1444                            }
1445                            cdt_MicroSecSum = cdt_MicroSec - (offSet_hor + offSet_min);
1446                            sgn_offset = "+";
1447                        }
1448 kumpf         1.14 
1449 w.white       1.43     else{
1450                            if (_TEN_THOUSAND_YEARS < (cdt_MicroSec + offSet_hor + offSet_min)) {
1451                                throw DateTimeOutOfRangeException(parmsUn);
1452                            }
1453                            cdt_MicroSecSum = cdt_MicroSec + (offSet_hor + offSet_min);
1454                            sgn_offset = "-";
1455                        }
1456 kumpf         1.20 
1457 david.dillard 1.54 
1458                        //Create new DateTime from sum of old DateTime and UTC and set UCT of new Date time.
1459 w.white       1.43     CIMDateTime ans = CIMDateTime(cdt_MicroSecSum, false);
1460                    
1461                        char utcBuff [5];
1462                        sprintf(utcBuff, "%03d", offSet);
1463                        String utc_str = sgn_offset.append(String(utcBuff));
1464                        Boolean res = ans._rep->set_utcOffSet(utc_str);
1465                    
1466                        if (res) {
1467 david.dillard 1.54         this->_rep->copy(ans._rep);   //  set_utcOffSet worked
1468 w.white       1.43         return;
1469 kumpf         1.20     }
1470 w.white       1.43     else{
1471                            Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2,
1472                                          "CIMDateTime::setUTCOffSet() failed");
1473 kumpf         1.28         throw InvalidDateTimeFormatException();
1474 kumpf         1.14     }
1475 w.white       1.43 }
1476                    
1477                    
1478                    
1479 david.dillard 1.54 /* finds the Wild Card in the most significant position and returns
1480 w.white       1.43     that position
1481 david.dillard 1.54     @param cDT_s gets searched along with calling object to find the
1482 w.white       1.43     wild card in the most significant
1483                        position
1484                    */
1485                    Uint32 CIMDateTime::getHighestWildCardPosition(const CIMDateTime & cDT_s)
1486                    {
1487 david.dillard 1.54 
1488 w.white       1.43     Uint32 spot_s = cDT_s.toString().find('*'); //since this return a Uint32 and PEG_NOT_FOUND=-1 can't do a
1489                        Uint32 spot_f = this->toString().find('*');  // straight compare
1490                    
1491 david.dillard 1.54 
1492                        if (spot_s == PEG_NOT_FOUND && spot_f == PEG_NOT_FOUND) {   //start time have more wild cards then finish time
1493 w.white       1.43        return PEG_NOT_FOUND;
1494                        }
1495                        else if (spot_f == PEG_NOT_FOUND) {
1496                             return spot_s;
1497                        }
1498                        else if (spot_s == PEG_NOT_FOUND) {
1499                             return spot_f;
1500 david.dillard 1.54     }
1501 w.white       1.43     else{
1502                            if (spot_f < spot_s) {
1503                                return spot_f;
1504                            }
1505                            else{
1506                                return spot_s;
1507                            }
1508                        }
1509                     }
1510                    
1511                    
1512                    
1513                    
1514                    /*inserts wild cards into CIMDateTime object.
1515                        @param index - position to start placing wild card characters
1516                        @param cdt - object to be modified
1517 david.dillard 1.54     Returns a copy of calling object with wild cards starting at
1518                        position index
1519 w.white       1.43     @exception InvalidDateTimeFormatException because of invalid index
1520 david.dillard 1.54     (see rules for wild cards)
1521 w.white       1.43 */
1522                    void CIMDateTime::insert_WildCard(Uint32 ind)
1523                    {
1524 david.dillard 1.54 
1525 w.white       1.43     Uint32 index = ind;
1526                        if (ind > 20) {
1527                           index = 21;
1528                        }
1529                    
1530                        Uint32 spot = this->toString().find('*');
1531                        if (spot == index) {
1532                            CIMDateTime cur = CIMDateTime(this->toString());
1533                            return;
1534                        }
1535 david.dillard 1.54 
1536 w.white       1.43     String splat = String("**************.******");
1537                        String cdtStr = this->toString();
1538                        String final;
1539 david.dillard 1.54     if (index != PEG_NOT_FOUND) {
1540 w.white       1.43         String str_cdtStr = cdtStr.subString(0, index);
1541                            String sub_splat = splat.subString(index, (21-index));
1542 david.dillard 1.54 
1543 w.white       1.43         //build result
1544                            String cdt_Splat = str_cdtStr.append(sub_splat);
1545                            final = cdt_Splat.append(this->_rep->utcOffSet);
1546                       }
1547                    
1548                       else{
1549                            final = splat.append(this->_rep->utcOffSet);
1550                       }
1551                    
1552                       CIMDateTime ans = CIMDateTime(final);
1553                       this->_rep->copy(ans._rep);
1554                       return;
1555 david.dillard 1.54 
1556 w.white       1.43 }
1557                    
1558                    
1559                    
1560                    CIMDateTime CIMDateTime::operator+(const CIMDateTime & cDT) const
1561                    {
1562                        CIMDateTime cur_cDT = CIMDateTime((String)(this->_rep->data));
1563                        CIMDateTime opt_cDT = cDT;
1564                        Sint32 utc;
1565 david.dillard 1.54     Boolean isInt = this->isInterval();
1566 w.white       1.43 
1567                        // only interval+interval and timeStamp+interval are allowed. Therefor second operand must be interval
1568                        if (!opt_cDT.isInterval()) {
1569 david.dillard 1.54         throw TypeMismatchException();
1570 w.white       1.43     }
1571                    
1572                        Uint32 splat_pos = cur_cDT.getHighestWildCardPosition(opt_cDT);
1573 david.dillard 1.54 
1574 w.white       1.43     Uint64 opt_num = opt_cDT.toMicroSeconds();
1575                        Uint64 cur_num = cur_cDT.toMicroSeconds();
1576                    
1577                        Uint64 ans = opt_num + cur_num;
1578                        CIMDateTime ans_cdt = CIMDateTime(ans, isInt);
1579                    
1580                        if (!isInt) {
1581                            utc = atol((_rep->utcOffSet).getCString());
1582                            ans_cdt.setUtcOffSet(utc);
1583                        }
1584                    
1585                        ans_cdt.insert_WildCard(splat_pos);
1586                    
1587                        return ans_cdt;
1588                    }
1589                    
1590                    
1591                    
1592 david.dillard 1.54 
1593 w.white       1.43 CIMDateTime & CIMDateTime::operator+=(const CIMDateTime & cDT)
1594                    {
1595                        CIMDateTime cur_cDT = CIMDateTime((String)(this->_rep->data));
1596                        CIMDateTime opt_cDT = cDT;
1597                    
1598                        CIMDateTime sum_cdt = cur_cDT + opt_cDT;
1599 david.dillard 1.54 
1600 w.white       1.43     _rep->copy(sum_cdt._rep);
1601 david.dillard 1.54 
1602 w.white       1.43      return *this;
1603                    }
1604                    
1605                    
1606                    CIMDateTime CIMDateTime::operator-(const CIMDateTime & cDT) const
1607                    {
1608                        CIMDateTime cur_cDT = CIMDateTime((String)(this->_rep->data));
1609                        CIMDateTime opt_cDT = cDT;
1610                    
1611                        CIMDateTime ans_cdt;
1612                        Sint32 utc;
1613                    
1614                        Boolean cur_isIn = this->isInterval();
1615                        Boolean opt_isIn = opt_cDT.isInterval();
1616                    
1617                        // only I-I, T-I and T-T are allowed
1618                        if (cur_isIn && !opt_isIn) {
1619 david.dillard 1.54         throw TypeMismatchException();
1620 w.white       1.43     }
1621                    
1622                        Uint64 opt_num = opt_cDT.toMicroSeconds();
1623                        Uint64 cur_num = cur_cDT.toMicroSeconds();
1624                    
1625                        if (cur_num < opt_num) {
1626                            MessageLoaderParms parmsSub("Common.Exception.DATETIME_OUT_OF_RANGE_EXCEPTION",
1627                                   "Result of subtracting two CIMDateTimes would be negative.");
1628                            throw DateTimeOutOfRangeException(parmsSub);
1629                        }
1630                    
1631                        Uint64 diff = cur_num - opt_num;
1632                    
1633                        if ((cur_isIn && opt_isIn) || (!cur_isIn && !opt_isIn)) { //don't konw how to do logical xor
1634                            ans_cdt = CIMDateTime(diff, true);
1635                        }
1636                        else{
1637                            ans_cdt = CIMDateTime(diff, false);
1638                            utc = atol((_rep->utcOffSet).getCString());
1639                            ans_cdt.setUtcOffSet(utc);
1640                        }
1641 w.white       1.43 
1642                        Uint32 splat_pos = cur_cDT.getHighestWildCardPosition(opt_cDT);
1643                        ans_cdt.insert_WildCard(splat_pos);
1644 david.dillard 1.54 
1645 w.white       1.43      return ans_cdt;
1646                    }
1647                    
1648                    
1649                    
1650                    
1651                    CIMDateTime & CIMDateTime::operator-=(const CIMDateTime & cDT)
1652                    {
1653                    
1654                        CIMDateTime cur_cDT = CIMDateTime((String)(this->_rep->data));
1655                        CIMDateTime opt_cDT = cDT;
1656                    
1657                        CIMDateTime dif_cdt = cur_cDT - opt_cDT;
1658                          _rep->copy(dif_cdt._rep);
1659                    
1660                         return *this;
1661                    }
1662                    
1663                    
1664                    
1665                    
1666 w.white       1.43 CIMDateTime CIMDateTime::operator*(Uint64 num) const
1667                    {
1668                        CIMDateTime cur_cDT = CIMDateTime((String)(this->_rep->data));
1669 david.dillard 1.54 
1670 w.white       1.43     if (!this->isInterval()){
1671                            throw TypeMismatchException();
1672                        }
1673 kumpf         1.14 
1674 w.white       1.43     Uint64 cur_num = cur_cDT.toMicroSeconds();
1675                        Uint64 prod = cur_num * num;
1676                    
1677                        CIMDateTime prod_cdt = CIMDateTime(prod, true);
1678                    
1679                        CIMDateTime dummy;
1680                        Uint32 splat_pos = cur_cDT.getHighestWildCardPosition(dummy);
1681 david.dillard 1.54 
1682 w.white       1.43     prod_cdt.insert_WildCard(splat_pos);
1683                    
1684                        return prod_cdt;
1685                    }
1686                    
1687                    
1688                    
1689                    
1690                    CIMDateTime & CIMDateTime::operator*=(Uint64 num)
1691                    {
1692 david.dillard 1.54     CIMDateTime cur_cDT = CIMDateTime((String)(this->_rep->data));
1693 w.white       1.43 
1694                        CIMDateTime prod_cdt = cur_cDT * num;
1695 david.dillard 1.54 
1696 w.white       1.43     _rep->copy(prod_cdt._rep);
1697                    
1698                         return *this;
1699                    }
1700                    
1701                    
1702                    
1703                    
1704                    CIMDateTime CIMDateTime::operator/(Uint64 num) const
1705                    {
1706 david.dillard 1.54     CIMDateTime cur_cDT = CIMDateTime((String)(this->_rep->data));
1707 w.white       1.43 
1708                        if (!(this->isInterval())){
1709 w.white       1.59         MessageLoaderParms parmsD("Common.CIMDateTime.INVALID_OPERATION_DIV_INT",
1710 w.white       1.43                                  "Can not divide a TimeStamp by an integer");
1711                            throw TypeMismatchException(parmsD);
1712                        }
1713 kumpf         1.14 
1714 w.white       1.43     if (num == 0) {
1715 w.white       1.59         MessageLoaderParms parmsZ("Common.CIMDateTime.INVALID_OPERATION_DIV_ZERO",
1716 w.white       1.43                                  "Can not divide CIMDateTime by zero");
1717                            throw Exception(parmsZ);
1718 kumpf         1.32     }
1719 david.dillard 1.54 
1720 w.white       1.43     Uint64 cur_num = cur_cDT.toMicroSeconds();
1721                        Uint64 prod = cur_num/num;
1722                    
1723                        CIMDateTime prod_cdt = CIMDateTime(prod, true);
1724 david.dillard 1.54     CIMDateTime dummy;
1725 w.white       1.43 
1726                        Uint32 splat_pos = cur_cDT.getHighestWildCardPosition(CIMDateTime(dummy));
1727                        prod_cdt.insert_WildCard(splat_pos);
1728                    
1729                        return prod_cdt;
1730                    }
1731                    
1732                    
1733                    
1734                    CIMDateTime & CIMDateTime::operator/=(Uint64 num)
1735 david.dillard 1.54 {
1736 w.white       1.43     CIMDateTime cur_cDT = CIMDateTime((String)(this->_rep->data));
1737                    
1738                        CIMDateTime ans = cur_cDT/num;
1739                        _rep->copy(ans._rep);
1740 david.dillard 1.54 
1741 w.white       1.43      return *this;
1742                    }
1743                    
1744                    
1745                    
1746                    
1747                    Uint64 CIMDateTime::operator/(const CIMDateTime & cDT) const
1748                    {
1749                        CIMDateTime cur_cDT = CIMDateTime((String)(this->_rep->data));
1750                        CIMDateTime opt_cDT = cDT;
1751                    
1752 david.dillard 1.54 
1753 w.white       1.43     if (!cur_cDT.isInterval() || !opt_cDT.isInterval()) {
1754 w.white       1.59         MessageLoaderParms parmsMM("Common.CIMDateTime.INVALID_OPERATION_DIV_TS",
1755 w.white       1.43                              "Can not divide two CIMDateTime objects if one of them is a TimeStamp");
1756 david.dillard 1.54         throw TypeMismatchException(parmsMM);
1757 w.white       1.43     }
1758                    
1759                        Uint64 opt_num = opt_cDT.toMicroSeconds();
1760                        Uint64 cur_num = cur_cDT.toMicroSeconds();
1761                    
1762                        if (opt_num == 0) {
1763 w.white       1.59         MessageLoaderParms parmsDZ("Common.CIMDateTime.INVALID_OPERATION_DIV_ZERO_CDT",
1764 w.white       1.60                              "Trying to divide a CIMDateTime object by a zero value CIMDateTime object");
1765 w.white       1.43         throw Exception(parmsDZ);
1766 kumpf         1.32     }
1767 w.white       1.43 
1768                        Uint64 ans = cur_num/opt_num;
1769                    
1770                        return ans;
1771                    }
1772                    
1773                    
1774                    
1775                    
1776                    Boolean CIMDateTime::operator<(const CIMDateTime & cDT) const
1777                    {
1778 david.dillard 1.54 
1779 w.white       1.43     CIMDateTime cur_cDT = CIMDateTime((String)(this->_rep->data));
1780                        CIMDateTime opt_cDT = cDT;
1781                    
1782                        if ((!cur_cDT.isInterval() && opt_cDT.isInterval()) || (cur_cDT.isInterval() && !opt_cDT.isInterval())) {
1783 w.white       1.59         MessageLoaderParms parms("Common.CIMDateTime.INVALID_OPERATION_COMP_DIF",
1784 w.white       1.43                              "Trying to compare CIMDateTime objects of differing types");
1785 david.dillard 1.54         throw TypeMismatchException(parms);
1786 w.white       1.43     }
1787                    
1788                        Uint32 splat_pos = cur_cDT.getHighestWildCardPosition(opt_cDT);
1789                        opt_cDT.insert_WildCard(splat_pos);
1790                        cur_cDT.insert_WildCard(splat_pos);
1791                    
1792                        Uint64 opt_num = opt_cDT.toMicroSeconds();
1793                        Uint64 cur_num = cur_cDT.toMicroSeconds();
1794 kumpf         1.20 
1795 w.white       1.43     if (cur_num < opt_num) {
1796                            return true;
1797 kumpf         1.20     }
1798 w.white       1.43     else{
1799                            return false;
1800 kumpf         1.20     }
1801 w.white       1.43 }
1802                    
1803                    
1804                    
1805                    
1806                    Boolean CIMDateTime::operator<=(const CIMDateTime & cDT) const
1807                    {
1808                        CIMDateTime cur = CIMDateTime((String)(this->_rep->data));
1809                    
1810                       if ((cur < cDT) || (cur == cDT)) {
1811                          return true;
1812                       }
1813                       else{
1814                           return false;
1815                       }
1816                    }
1817 david.dillard 1.54 
1818 kumpf         1.20 
1819                    
1820 w.white       1.43 
1821                    Boolean CIMDateTime::operator>(const CIMDateTime & cDT) const
1822                    {
1823                        CIMDateTime cur = CIMDateTime((String)(this->_rep->data));
1824                    
1825                        if ((!(cur < cDT)) && (!(cur == cDT))) {
1826                           return true;
1827 kumpf         1.20     }
1828 w.white       1.43     else{
1829                           return false;
1830 kumpf         1.20     }
1831 w.white       1.43 }
1832                    
1833                    
1834                    
1835                    
1836                    Boolean CIMDateTime::operator>=(const CIMDateTime & cDT) const
1837                    {
1838                        CIMDateTime cur = CIMDateTime((String)(this->_rep->data));
1839                    
1840                       if (!(cur < cDT)) {
1841                          return true;
1842                       }
1843                       else{
1844                          return false;
1845                       }
1846                    }
1847 kumpf         1.20 
1848 kumpf         1.14 
1849 david.dillard 1.54 
1850 w.white       1.43 Boolean CIMDateTime::operator!=(const CIMDateTime & cDT) const
1851                    {
1852                        CIMDateTime cur = CIMDateTime((String)(this->_rep->data));
1853 kumpf         1.26 
1854 w.white       1.43     if (!(cur  == cDT)) {
1855                            return true;
1856                        }
1857                        else{
1858                            return false;
1859                        }
1860 mike          1.10 }
1861                    
1862 david.dillard 1.54 
1863 w.white       1.43 
1864 mike          1.10 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2