~ubuntu-branches/ubuntu/trusty/sblim-sfcb/trusty-proposed

« back to all changes in this revision

Viewing changes to datetime.c

  • Committer: Bazaar Package Importer
  • Author(s): Thierry Carrez
  • Date: 2009-06-08 12:04:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090608120449-byfplk09rqz8rtg6
Tags: 1.3.3-0ubuntu1
* New upstream release.
* debian/rules: Removed rpath hacks, SFCB default build handles that now.
* Removed 1934753-remove-assignment.diff, now upstream.
* Refreshed patch cim-schema-location.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
 
93
93
CMPIUint64 chars2bin(const char *string, CMPIStatus * rc)
94
94
{
 
95
/**
 
96
 * \brief chars2bin(): Converts a string time to microseconds since epoch.
 
97
 *
 
98
 * includes the offset in the result, but uses the local timezone
 
99
 * and DST settings. string is of the form:
 
100
 *   yyyymmddhhmmss mmmmmmsutc 
 
101
 *   20050503104354.000000:000
 
102
 *   20080813104354.000000+500
 
103
 * the : indicates that it is an interval.
 
104
*/
95
105
   CMPIUint64 msecs,secs;
96
106
   CMPIBoolean interval;
97
107
   char *str;
 
108
   int offset=0;
98
109
 
99
110
   str = strdup(string);
100
111
   interval = (str[21] == ':');
 
112
   if ((str[21] == '+') ||  (str[21] == '-')) {
 
113
      // If we found an offset in the timestamp
 
114
      // convert it to seconds, and save it
 
115
      offset= atoi(str+21) * 60ULL;
 
116
   }
101
117
 
102
 
// 0000000000111111111122222  
103
 
// 0123456789012345678901234
104
 
// yyyymmddhhmmss mmmmmmsutc 
105
 
// 20050503104354.000000:000
106
118
   
107
119
   str[21] = 0;
108
120
   msecs = strtoull(str+15,NULL,10);
136
148
 
137
149
      msecs=msecs+(secs*1000000ULL);
138
150
      msecs += (CMPIUint64) mktime(&tmp) * 1000000ULL;
 
151
      // Add in the offset
 
152
      msecs -= offset * 1000000ULL;
139
153
   }
140
154
 
141
155
   free(str);
145
159
 
146
160
static void bin2chars(CMPIUint64 msecs, CMPIBoolean interval, CMPIStatus * rc, char *str_time)
147
161
{
 
162
/** /brief bin2chars(): Converts microseconds since epoch to a string time.
 
163
 *
 
164
 *  Uses the current timezone as the basis for the conversion, but will determine
 
165
 *  if DST was in effect at the time in the input.
 
166
*/
148
167
   time_t secs = msecs / 1000000ULL;
149
168
   unsigned long usecs = msecs % 1000000ULL;
150
169
 
179
198
      tzset();
180
199
 
181
200
      snprintf(us_utc_time, 11, "%6.6ld%+4.3ld",
182
 
               usecs, (daylight != 0) * 60 - timezone / 60);
 
201
               usecs, (tm_time.tm_isdst != 0) * 60 - timezone / 60);
183
202
 
184
203
      strftime(str_time, 26, "%Y%m%d%H%M%S.", &tm_time);
185
204