3 carson.hovey 1.2 // 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 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 gs.keenan 1.1 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
13 // 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 // 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 //
19 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
20 // 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 // 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 // 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 //
30 // Author: Sushma Fernandes, Hewlett Packard Company (sushma_fernandes@hp.com)
31 //
32 gs.keenan 1.1 //%////////////////////////////////////////////////////////////////////////////
33
34
35 ///////////////////////////////////////////////////////////////////////////////
36 //
37 // DateTime
38 //
39 ///////////////////////////////////////////////////////////////////////////////
40
41 #include <Pegasus/Common/CIMDateTime.h>
42
43 #include <sys/time.h>
44 #include <cstring>
45
46 typedef struct Timestamp {
47 char year[4];
48 char month[2];
49 char day[2];
50 char hour[2];
51 char minutes[2];
52 char seconds[2];
53 gs.keenan 1.1 char dot;
54 char microSeconds[6];
55 char plusOrMinus;
56 char utcOffset[3];
57 char padding[3];
58 } Timestamp_t;
59
60 PEGASUS_USING_STD;
61
62 PEGASUS_NAMESPACE_BEGIN
63
64 //
65 // Returns the local time.
66 // Note: Original code was taken from OperatingSystem::getLocalDateTime ()
67 //
68 CIMDateTime CIMDateTime::getCurrentDateTime()
69 {
70 CIMDateTime currentDateTime;
71 int year;
72 Timestamp_t dateTime;
73 char mTmpString[80];
74 gs.keenan 1.1 time_t mSysTime;
75 struct timeval tv;
76 struct tm* tmval;
77
78 // Get the system date and time
79 mSysTime = time(NULL);
80
81 // Get the localtime
82 tmval = localtime(&mSysTime);
83 gettimeofday(&tv,NULL);
84
85 // Initialize the year
86 year = 1900;
87
88 // Format the date
89 sprintf((char *)&dateTime,"%04d%02d%02d%02d%02d%02d.%06d+%03d",
90 year + tmval->tm_year,
91 tmval->tm_mon + 1,
92 tmval->tm_mday,
93 tmval->tm_hour,
94 tmval->tm_min,
95 gs.keenan 1.1 tmval->tm_sec,
96 0,
97 0);
98
99 // Set the UTC Sign
100 if (tmval->tm_gmtoff > 0)
101 {
102 dateTime.plusOrMinus = '-';
103 }
104 else
105 {
106 dateTime.plusOrMinus = '+';
107 }
108
109 currentDateTime.clear();
110 strcpy(mTmpString, (char *)&dateTime);
111 currentDateTime.set(mTmpString);
112
113 return currentDateTime;
114 }
115
116 gs.keenan 1.1 PEGASUS_NAMESPACE_END
117
118
119
|