version 1.22, 2002/05/09 21:08:55
|
version 1.36, 2003/10/27 19:48:06
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%2003//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development |
|
// Company, L. P., IBM Corp., The Open Group, Tivoli Systems. |
|
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.; |
|
// IBM Corp.; EMC Corporation, The Open Group. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
// Sushma Fernandes, Hewlett Packard Company | // Sushma Fernandes, Hewlett Packard Company |
// (sushma_fernandes@hp.com) | // (sushma_fernandes@hp.com) |
// Roger Kumpf, Hewlett Packard Company (roger_kumpf@hp.com) | // Roger Kumpf, Hewlett Packard Company (roger_kumpf@hp.com) |
|
// Carol Ann Krug Graves, Hewlett-Packard Company |
|
// (carolann_graves@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/Array.h> | #include <Pegasus/Common/Array.h> |
#include <time.h> |
#include <Pegasus/Common/Linkage.h> |
#ifdef PEGASUS_INTERNALONLY |
|
#include <iostream> |
|
#endif |
|
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
/* ATTN: P3. KS Several functions should be added to this class for datetime manipulation |
class CIMDateTimeRep; |
including get and set each subcomponent (year, month, etc), test for equality, |
|
create intervals from absolutes, possibly gett current time, Note that |
|
the Java rep is probably tostring, not get string, |
|
*/ |
|
| |
/** | /** |
The CIMDateTime class represents the CIM datetime data type as a C++ class | The CIMDateTime class represents the CIM datetime data type as a C++ class |
CIMDateTime. A CIM datetime may contain a date or an interval. CIMDateTime | CIMDateTime. A CIM datetime may contain a date or an interval. CIMDateTime |
is an intrinsic CIM data type which represents the time as a formated |
is an intrinsic CIM data type that represents the time as a string with a |
fixedplength string. |
fixed length. |
| |
<PRE> | <PRE> |
A date has the following form: | A date has the following form: |
|
|
| |
Where | Where |
| |
yyyy = year (0-1999) |
yyyy = year (1-9999) |
mm = month (1-12) | mm = month (1-12) |
dd = day (1-31) | dd = day (1-31) |
hh = hour (0-23) | hh = hour (0-23) |
mm = minute (0-59) | mm = minute (0-59) |
ss = second (0-59) | ss = second (0-59) |
mmmmmm = microseconds. |
mmmmmm = microseconds |
s = '+' or '-' to represent the UTC sign. |
s = '+' or '-' to represent the Coordinated Universal Time (UTC) sign |
utc = UTC offset (same as GMT offset). |
utc = offset from Coordinated Universal Time (UTC) |
|
(same as Greenwich Mean Time(GMT) offset) |
| |
An interval has the following form: | An interval has the following form: |
| |
|
|
mmmmmm = microseconds | mmmmmm = microseconds |
</PRE> | </PRE> |
| |
Note that intervals always end in ":000" (this is how they |
Note: Intervals always end in ":000". This distinguishes intervals from dates. |
are distinguished from dates). |
|
| |
Intervals are really durations since they do not specify a start and |
CIMDateTime objects are constructed from String objects or from |
end time (as one expects when speaking about an interval). It is |
other CIMDateTime objects. Character strings must be exactly |
better to think of an interval as specifying time elapsed since |
twenty-five characters in length and conform to either the date or interval |
some event. |
format. |
|
|
CIMDateTime objects are constructed from C character strings or from |
|
other CIMDateTime objects. These character strings must be exactly |
|
twenty-five characters and conform to one of the forms idententified |
|
above. |
|
| |
CIMDateTime objects which are not explicitly initialized will be |
CIMDateTime objects that are not explicitly initialized will be |
implicitly initialized with the null time interval: |
implicitly initialized with a zero time interval: |
| |
00000000000000.000000:000 | 00000000000000.000000:000 |
| |
Instances can be tested for nullness with the isNull() method. |
|
*/ | */ |
class PEGASUS_COMMON_LINKAGE CIMDateTime | class PEGASUS_COMMON_LINKAGE CIMDateTime |
{ | { |
public: | public: |
| |
/** Create a new CIMDateTime object with NULL DateTime definition. |
/** Creates a new CIMDateTime object with a zero interval value. |
*/ | */ |
CIMDateTime(); | CIMDateTime(); |
| |
/** CIMDateTime - Creat a CIM CIMDateTime instance from a string |
/** Creates a new CIMDateTime object from a string constant representing |
constant representing the CIM DateTime formatted datetime |
the CIM DateTime-formatted datetime. |
See the class documentation for CIMDateTime for the defintion of the |
See the class documentation for CIMDateTime for the definition of the |
input string for absolute and interval datetime. | input string for absolute and interval datetime. |
@param str String object containing the CIM DateTime formatted string |
@param str String object containing the CIM DateTime-formatted string. |
|
This must contain twenty-five characters. |
*/ | */ |
CIMDateTime(const char* str); |
CIMDateTime(const String & str); |
| |
/** CIMDateTime Create a CIMDateTime instance from another |
/** Creates a CIMDateTime object from another CIMDateTime object. |
CIMDateTime object |
@param x Specifies the name of the CIMDateTime object to copy. |
@param x CIMDateTime object to be copied. |
|
*/ | */ |
CIMDateTime(const CIMDateTime& x); | CIMDateTime(const CIMDateTime& x); |
| |
/** DateTime Destructor. */ |
/** CIMDateTime destructor. */ |
~CIMDateTime(); | ~CIMDateTime(); |
| |
/** Assign one DateTime object to another |
/** Assigns one instance of the CIMDateTime object to another. |
@param - The DateTime Object to assign |
@param x The CIMDateTime Object to assign to the CIMDateTime object. |
<pre> |
For example, you can assign the d1 CIMDateTime instance to the d2 |
|
CIMDateTime instance. |
|
<PRE> |
CIMDateTime d1; | CIMDateTime d1; |
CIMDateTime d2 = "00000000000000.000000:000"; | CIMDateTime d2 = "00000000000000.000000:000"; |
d1 = d1; |
d1 = d2; |
</pre> |
|
*/ |
|
CIMDateTime& operator=(const CIMDateTime& x); |
|
|
|
/** CIMDateTime isNull method - Tests for an all zero date time. Note that |
|
today this function checks for absolute datetime == zero, not interval. |
|
<PRE> |
|
CIMDateTime dt; |
|
dt.clear(); |
|
assert(dt.isNull()); |
|
</PRE> | </PRE> |
@return This method returns true of the contents are |
Therefore, d1 is assigned the same "00000000000000.000000:000" value as d2. |
"00000000000000.000000:000". Else it returns false |
|
*/ | */ |
Boolean isNull() const; |
CIMDateTime& operator=(const CIMDateTime& x); |
| |
/** getString - Returns the string representing the DateTime value of the |
/** Returns a string representing the DateTime value of the |
CIMDateTime Object. |
CIMDateTime object. |
ATTN: P3 KS. This simply returns a string whether the datetime is a |
@return String representing the DateTime value. |
real value or the NULL value. It is up to the user to test. Should |
*/ |
this be modified so we do something like an interupt on NULL? |
String toString () const; |
*/ |
|
const char* getString() const; |
/** Sets the date and time in the CIMDateTime object from |
|
the input parameter. |
/** method set - Sets the date time. Creates the CIMDateTime instance from |
@param str String constant containing the datetime |
the input string constant which must be |
in the datetime format. This must conform the to formatting rules specified |
in the datetime format. |
in the CIMDateTime class description. For example, the following sets |
|
the date to December 24, 1999 and time to 12:00 P.M. |
| |
<PRE> | <PRE> |
CIMDateTime dt; | CIMDateTime dt; |
dt.set("19991224120000.000000+360"); | dt.set("19991224120000.000000+360"); |
</PRE> | </PRE> |
| |
@return On format error, CIMDateTime set throws the exception |
@exception InvalidDateTimeFormatException because the date and time is not |
BadDateTimeFormat |
formatted correctly. See the CIMDateTime class decscription for the |
@exception Throws exception BadDateTimeFormat on format error. |
formatting rules. |
*/ | */ |
void set(const char* str); |
void set(const String & str); |
| |
/** clear - Clears the datetime class instance. The date time is set to our |
/** Clears the datetime class object. The date time is set to |
defintion of NULL, absolute zero date time. |
a zero interval value. |
*/ | */ |
void clear(); | void clear(); |
| |
/** |
/** Receives the current time as CIMDateTime. The time is returned as the local time. |
Get current time as CIMDateTime. The time returned is always in UTC format. |
@return CIMDateTime object containing the current date and time. |
|
|
@return CIMDateTime Contains the current datetime as a CIMDateTime object. |
|
|
|
Note: Original code was taken from OperationSystem::getLocalDateTime() |
|
*/ | */ |
static CIMDateTime getCurrentDateTime(); | static CIMDateTime getCurrentDateTime(); |
| |
/** |
/** Computes the difference in microseconds between two CIMDateTime dates or |
Get the difference between two CIMDateTimes. This function computes the |
two CIMDateTime intervals. |
difference between two datetimes or between two intervals. The result |
@param startTime Contains the start datetime. |
is truncated and returned as the number of seconds. |
@param finishTime Contains the finish datetime. |
|
@return Integer that contains the difference between the two datetime values |
@param startTime Contains the start time. |
in microseconds. |
|
@exception InvalidDateTimeFormatException If one argument uses the interval |
@param finishTime Contains the finish time. |
format and the other uses the string format. |
|
@exception DateTimeOutOfRangeException If datetime is outside the allowed |
@return difference Difference between the two datetimes in seconds. |
range. |
|
|
|
Note: The behavior on HP-UX and Windows platform is to throw an exception |
|
when the dates are out of range. Red Hat Linux platform normalizes the |
|
dates when they are outside their legal interval and will not throw an |
|
exception. |
|
|
|
Allowed Date Range: |
|
The mktime (3C) man page on HP-UX does not document the allowed range. |
|
The approximate range of dates allowed on HP-UX is between |
|
1901 and 2038. |
| |
@throws BadFormat |
On Windows platform, the approximate range is between 1970 to 2038. |
| |
|
On Red Hat Linux platform the approximate range is between 1901 and 2038. |
*/ | */ |
static Sint64 getDifference(CIMDateTime startTime, CIMDateTime finishTime); | static Sint64 getDifference(CIMDateTime startTime, CIMDateTime finishTime); |
| |
/** |
/** Checks whether the datetime is an interval. |
Checks whether the datetime is an interval. |
@return True if the datetime is an interval; otherwise, false. |
|
|
@return isInterval True if the datetime is an interval, else false |
|
*/ | */ |
Boolean isInterval(); | Boolean isInterval(); |
| |
private: |
/** Compares the CIMDateTime object to another CIMDateTime object for |
|
equality. |
enum { FORMAT_LENGTH = 25 }; |
@param x CIMDateTime object to be compared. |
|
@return true if the two CIMDateTime objects are equal; otherwise, false. |
char _rep[FORMAT_LENGTH + 1]; |
*/ |
|
Boolean equal (const CIMDateTime & x) const; |
#ifdef PEGASUS_INTERNALONLY |
|
// |
|
// Length of the string required to store only the date and time without |
|
// the UTC sign and UTC offset. |
|
// Format is yyyymmddhhmmss. |
|
// Note : The size does not include the null byte. |
|
// |
|
enum { DATE_TIME_LENGTH = 14 }; |
|
|
|
// |
|
// Length of the string required to store the formatted date and time |
|
// Format is yyyy:mm:dd:hh:mm:ss. |
|
// |
|
enum { FORMATTED_DATE_TIME = 20 }; |
|
| |
Boolean _set(const char* str); |
private: |
| |
|
CIMDateTimeRep* _rep; |
|
Boolean _set(const String & dateTimeStr); |
|
}; |
/** | /** |
This function extracts the different components of the date and time |
Add documentation here. |
from the string passed and assigns it to the tm structure. |
|
|
|
@param dateTimeStr Contains the string to be assigned. |
|
|
|
@param tm Contains the tm structure to be updated. |
|
*/ | */ |
static void formatDateTime(char* dateTime, tm* tm); |
|
#endif |
|
|
|
/** CIMDateTime - ATTN: Friend operator Test for CIMDateTime |
|
equality |
|
*/ |
|
PEGASUS_COMMON_LINKAGE friend Boolean operator==( |
|
const CIMDateTime& x, |
|
const CIMDateTime& y); |
|
}; |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator==( | PEGASUS_COMMON_LINKAGE Boolean operator==( |
|
/** |
|
Add documentation here. |
|
*/ |
const CIMDateTime& x, | const CIMDateTime& x, |
|
/** |
|
Add documentation here. |
|
*/ |
const CIMDateTime& y); | const CIMDateTime& y); |
| |
#ifdef PEGASUS_INTERNALONLY |
|
PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<( |
|
PEGASUS_STD(ostream)& os, |
|
const CIMDateTime& x); |
|
#endif |
|
|
|
#define PEGASUS_ARRAY_T CIMDateTime | #define PEGASUS_ARRAY_T CIMDateTime |
# include "ArrayInter.h" |
# include <Pegasus/Common/ArrayInter.h> |
#undef PEGASUS_ARRAY_T | #undef PEGASUS_ARRAY_T |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |