summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/timeconversion.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/library/backend/timeconversion.cpp b/library/backend/timeconversion.cpp
index ef7762d..3c25922 100644
--- a/library/backend/timeconversion.cpp
+++ b/library/backend/timeconversion.cpp
@@ -120,68 +120,69 @@ QCString TimeConversion::toISO8601( const QDateTime &dt )
QCString str;
str.sprintf("%04d%02d%02dT%02d%02d%02dZ",
(utc->tm_year + 1900), utc->tm_mon+1, utc->tm_mday,
utc->tm_hour, utc->tm_min, utc->tm_sec );
return str;
}
QDateTime TimeConversion::fromISO8601( const QCString &s )
{
#if defined(_OS_WIN32) || defined (Q_OS_WIN32) || defined (Q_OS_WIN64)
_tzset();
#else
tzset();
#endif
- struct tm *thetime = new tm;
+ struct tm thetime;
QCString str = s.copy();
str.replace(QRegExp("-"), "" );
str.replace(QRegExp(":"), "" );
str.stripWhiteSpace();
str = str.lower();
int i = str.find( "t" );
QCString date;
QCString timestr;
if ( i != -1 ) {
date = str.left( i );
timestr = str.mid( i+1 );
} else {
date = str;
}
// qDebug("--- parsing ISO time---");
- thetime->tm_year = 100;
- thetime->tm_mon = 0;
- thetime->tm_mday = 0;
- thetime->tm_hour = 0;
- thetime->tm_min = 0;
- thetime->tm_sec = 0;
+ memset( &thetime, 0, sizeof(tm) );
+ thetime.tm_year = 100;
+ thetime.tm_mon = 0;
+ thetime.tm_mday = 0;
+ thetime.tm_hour = 0;
+ thetime.tm_min = 0;
+ thetime.tm_sec = 0;
// qDebug("date = %s", date.data() );
switch( date.length() ) {
case 8:
- thetime->tm_mday = date.right( 2 ).toInt();
+ thetime.tm_mday = date.right( 2 ).toInt();
case 6:
- thetime->tm_mon = date.mid( 4, 2 ).toInt() - 1;
+ thetime.tm_mon = date.mid( 4, 2 ).toInt() - 1;
case 4:
- thetime->tm_year = date.left( 4 ).toInt();
- thetime->tm_year -= 1900;
+ thetime.tm_year = date.left( 4 ).toInt();
+ thetime.tm_year -= 1900;
break;
default:
break;
}
int tzoff = 0;
bool inLocalTime = FALSE;
if ( timestr.find( 'z' ) == (int)timestr.length() - 1 )
// UTC
timestr = timestr.left( timestr.length() -1 );
else {
int plus = timestr.find( "+" );
int minus = timestr.find( "-" );
if ( plus != -1 || minus != -1 ) {
// have a timezone offset
plus = (plus != -1) ? plus : minus;
@@ -193,45 +194,45 @@ QDateTime TimeConversion::fromISO8601( const QCString &s )
switch( off.length() ) {
case 5:
tzoffmin = off.mid(3).toInt();
case 3:
tzoffhour = off.left(3).toInt();
default:
break;
}
tzoff = 60*tzoffhour + tzoffmin;
} else
inLocalTime = TRUE;
}
// get the time:
switch( timestr.length() ) {
case 6:
- thetime->tm_sec = timestr.mid( 4 ).toInt();
+ thetime.tm_sec = timestr.mid( 4 ).toInt();
case 4:
- thetime->tm_min = timestr.mid( 2, 2 ).toInt();
+ thetime.tm_min = timestr.mid( 2, 2 ).toInt();
case 2:
- thetime->tm_hour = timestr.left( 2 ).toInt();
+ thetime.tm_hour = timestr.left( 2 ).toInt();
default:
break;
}
int tzloc = 0;
time_t tmp = time( 0 );
if ( !inLocalTime ) {
// have to get the offset between gmt and local time
struct tm *lt = localtime( &tmp );
tzloc = mktime( lt );
struct tm *ut = gmtime( &tmp );
tzloc -= mktime( ut );
}
// qDebug("time: %d %d %d, tzloc=%d, tzoff=%d", thetime->tm_hour, thetime->tm_min, thetime->tm_sec,
// tzloc, tzoff );
- tmp = mktime( thetime );
+ tmp = mktime( &thetime );
tmp += 60*(-tzloc + tzoff);
- delete thetime;
+
return fromUTC( tmp );
}