Skip to content

Commit 9a2c7bb

Browse files
author
Dimitri van Heesch
committed
Merge pull request #477 from infinity0/master
Bug 751984 - Use UTC timezone when displaying QDateTimes parsed from SOURCE_DATE_EPOCH
2 parents ab96c07 + 5801460 commit 9a2c7bb

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

qtools/qdatetime.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,29 @@ void QDateTime::setTime_t( uint secsSince1Jan1970UTC )
11571157
}
11581158

11591159

1160+
/*!
1161+
Sets the UTC date and time given the number of seconds that have passed
1162+
since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
1163+
1164+
Note that Microsoft Windows supports only a limited range of values for
1165+
\a secsSince1Jan1970UTC.
1166+
*/
1167+
1168+
void QDateTime::setTimeUtc_t( uint secsSince1Jan1970UTC )
1169+
{
1170+
time_t tmp = (time_t) secsSince1Jan1970UTC;
1171+
tm *tM = gmtime( &tmp );
1172+
if ( !tM ) {
1173+
d.jd = QDate::greg2jul( 1970, 1, 1 );
1174+
t.ds = 0;
1175+
return;
1176+
}
1177+
d.jd = QDate::greg2jul( tM->tm_year + 1900, tM->tm_mon + 1, tM->tm_mday );
1178+
t.ds = MSECS_PER_HOUR*tM->tm_hour + MSECS_PER_MIN*tM->tm_min +
1179+
1000*tM->tm_sec;
1180+
}
1181+
1182+
11601183
/*!
11611184
Returns the datetime as a string.
11621185

qtools/qdatetime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class Q_EXPORT QDateTime
173173
void setDate( const QDate &date ) { d=date; }
174174
void setTime( const QTime &time ) { t=time; }
175175
void setTime_t( uint secsSince1Jan1970UTC );
176+
void setTimeUtc_t( uint secsSince1Jan1970UTC );
176177

177178
QString toString() const;
178179

src/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2582,7 +2582,7 @@ QCString dateToString(bool includeTime)
25822582
}
25832583
else // all ok, replace current time with epoch value
25842584
{
2585-
current.setTime_t((ulong)epoch); // TODO: add support for 64bit epoch value
2585+
current.setTimeUtc_t((ulong)epoch); // TODO: add support for 64bit epoch value
25862586
}
25872587
}
25882588
return theTranslator->trDateTime(current.date().year(),

0 commit comments

Comments
 (0)