Fixed missing seconds in time format.

Added new basic class for date/time format.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5825 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-11-15 21:35:37 +00:00
parent 8a3973de81
commit 968f72f303
20 changed files with 195 additions and 77 deletions

View File

@ -42,7 +42,7 @@
#include "channels/ShareKey.h" #include "channels/ShareKey.h"
#include "notifyqt.h" #include "notifyqt.h"
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
#include "rshare.h" #include "util/DateTime.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include <retroshare/rsforums.h> #include <retroshare/rsforums.h>
@ -1522,17 +1522,14 @@ static QString buildReplyHeader(const ForumMsgInfo &msgInfo)
link.createMessage(msgInfo.srcId, ""); link.createMessage(msgInfo.srcId, "");
QString from = link.toHtml(); QString from = link.toHtml();
QDateTime qtime;
qtime.setTime_t(msgInfo.ts);
QString header = QString("<span>-----%1-----").arg(QApplication::translate("ForumsDialog", "Original Message")); QString header = QString("<span>-----%1-----").arg(QApplication::translate("ForumsDialog", "Original Message"));
header += QString("<br><font size='3'><strong>%1: </strong>%2</font><br>").arg(QApplication::translate("ForumsDialog", "From"), from); header += QString("<br><font size='3'><strong>%1: </strong>%2</font><br>").arg(QApplication::translate("ForumsDialog", "From"), from);
header += QString("<br><font size='3'><strong>%1: </strong>%2</font><br>").arg(QApplication::translate("ForumsDialog", "Sent"), Rshare::customLongDate(msgInfo.ts)); header += QString("<br><font size='3'><strong>%1: </strong>%2</font><br>").arg(QApplication::translate("ForumsDialog", "Sent"), DateTime::formatLongDateTime(msgInfo.ts));
header += QString("<font size='3'><strong>%1: </strong>%2</font></span><br>").arg(QApplication::translate("ForumsDialog", "Subject"), QString::fromStdWString(msgInfo.title)); header += QString("<font size='3'><strong>%1: </strong>%2</font></span><br>").arg(QApplication::translate("ForumsDialog", "Subject"), QString::fromStdWString(msgInfo.title));
header += "<br>"; header += "<br>";
header += QApplication::translate("ForumsDialog", "On %1, %2 wrote:").arg(qtime.toString(Qt::DefaultLocaleShortDate), from); header += QApplication::translate("ForumsDialog", "On %1, %2 wrote:").arg(DateTime::formatDateTime(msgInfo.ts), from);
return header; return header;
} }
@ -1846,14 +1843,14 @@ void ForumsFillThread::run()
else else
qtime.setTime_t(tit->ts); qtime.setTime_t(tit->ts);
text = qtime.toString(Qt::DefaultLocaleShortDate); text = DateTime::formatDateTime(qtime);
sort = qtime.toString("yyyyMMdd_hhmmss"); sort = qtime.toString("yyyyMMdd_hhmmss");
if (useChildTS) if (useChildTS)
{ {
qtime.setTime_t(tit->ts); qtime.setTime_t(tit->ts);
text += " / "; text += " / ";
text += qtime.toString(Qt::DefaultLocaleShortDate); text += DateTime::formatDateTime(qtime);
sort += "_" + qtime.toString("yyyyMMdd_hhmmss"); sort += "_" + qtime.toString("yyyyMMdd_hhmmss");
} }
item->setText(COLUMN_THREAD_DATE, text); item->setText(COLUMN_THREAD_DATE, text);
@ -1963,14 +1960,14 @@ void ForumsFillThread::run()
else else
qtime.setTime_t(mit->ts); qtime.setTime_t(mit->ts);
text = qtime.toString(Qt::DefaultLocaleShortDate); text = DateTime::formatDateTime(qtime);
sort = qtime.toString("yyyyMMdd_hhmmss"); sort = qtime.toString("yyyyMMdd_hhmmss");
if (useChildTS) if (useChildTS)
{ {
qtime.setTime_t(mit->ts); qtime.setTime_t(mit->ts);
text += " / "; text += " / ";
text += qtime.toString(Qt::DefaultLocaleShortDate); text += DateTime::formatDateTime(qtime);
sort += "_" + qtime.toString("yyyyMMdd_hhmmss"); sort += "_" + qtime.toString("yyyyMMdd_hhmmss");
} }
child->setText(COLUMN_THREAD_DATE, text); child->setText(COLUMN_THREAD_DATE, text);

View File

@ -50,6 +50,7 @@
#include "settings/rsharesettings.h" #include "settings/rsharesettings.h"
#include "util/misc.h" #include "util/misc.h"
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
#include "util/DateTime.h"
#include "chat/CreateLobbyDialog.h" #include "chat/CreateLobbyDialog.h"
#include "FriendRecommendDialog.h" #include "FriendRecommendDialog.h"
@ -706,7 +707,7 @@ void FriendsDialog::setChatInfo(QString info, QColor color)
ui.msgText->clear(); ui.msgText->clear();
nbLines = 1; nbLines = 1;
} }
ui.msgText->append("<font color='grey'>" + QTime::currentTime().toString(Qt::DefaultLocaleShortDate) + "</font> - <font color='" + color.name() + "'><i>" + info + "</i></font>"); ui.msgText->append("<font color='grey'>" + DateTime::formatTime(QTime::currentTime()) + "</font> - <font color='" + color.name() + "'><i>" + info + "</i></font>");
} }
void FriendsDialog::on_actionClear_Chat_History_triggered() void FriendsDialog::on_actionClear_Chat_History_triggered()

View File

@ -34,6 +34,7 @@
#include "common/TagDefs.h" #include "common/TagDefs.h"
#include "common/PeerDefs.h" #include "common/PeerDefs.h"
#include "common/RSItemDelegate.h" #include "common/RSItemDelegate.h"
#include "util/DateTime.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include <retroshare/rsmsgs.h> #include <retroshare/rsmsgs.h>
@ -1051,14 +1052,11 @@ void MessagesDialog::insertMessages()
//if the mail is on same date show only time. //if the mail is on same date show only time.
if (qdatetime.daysTo(QDateTime::currentDateTime()) == 0) if (qdatetime.daysTo(QDateTime::currentDateTime()) == 0)
{ {
QTime qtime = qdatetime.time(); item[COLUMN_DATE]->setData(DateTime::formatTime(qdatetime.time()), Qt::DisplayRole);
QVariant varTime(qtime);
item[COLUMN_DATE]->setData(varTime, Qt::DisplayRole);
} }
else else
{ {
QVariant varDateTime(qdatetime); item[COLUMN_DATE]->setData(DateTime::formatDateTime(qdatetime), Qt::DisplayRole);
item[COLUMN_DATE]->setData(varDateTime, Qt::DisplayRole);
} }
// for sorting // for sorting
item[COLUMN_DATE]->setData(qdatetime, ROLE_SORT); item[COLUMN_DATE]->setData(qdatetime, ROLE_SORT);

View File

@ -19,7 +19,7 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
****************************************************************/ ****************************************************************/
#include "ChannelDetails.h" #include "ChannelDetails.h"
#include "rshare.h" #include "util/DateTime.h"
#include <retroshare/rsiface.h> #include <retroshare/rsiface.h>
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
@ -95,7 +95,7 @@ void ChannelDetails::loadChannel()
// Set Last Channel Post Date // Set Last Channel Post Date
if (ci.lastPost) { if (ci.lastPost) {
ui.postline->setText(Rshare::customLongDate(ci.lastPost)); ui.postline->setText(DateTime::formatLongDateTime(ci.lastPost));
} }
// Set Channel ID // Set Channel ID

View File

@ -105,6 +105,7 @@
#include "ChatStyle.h" #include "ChatStyle.h"
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include "util/DateTime.h"
#include <retroshare/rsinit.h> #include <retroshare/rsinit.h>
@ -323,8 +324,8 @@ QString ChatStyle::formatMessage(enumFormatMessage type, const QString &name, co
#endif #endif
QString formatMsg = style.replace("%name%", name) QString formatMsg = style.replace("%name%", name)
.replace("%date%", timestamp.date().toString(Qt::DefaultLocaleShortDate)) .replace("%date%", DateTime::formatDate(timestamp.date()))
.replace("%time%", timestamp.time().toString(Qt::DefaultLocaleShortDate)) .replace("%time%", DateTime::formatTime(timestamp.time()))
#ifdef COLORED_NICKNAMES #ifdef COLORED_NICKNAMES
.replace("%color%", color.name()) .replace("%color%", color.name())
#endif #endif

View File

@ -40,7 +40,7 @@
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include "gui/common/AvatarDefs.h" #include "gui/common/AvatarDefs.h"
#include "gui/MainWindow.h" #include "gui/MainWindow.h"
#include "rshare.h" #include "util/DateTime.h"
static QMap<std::string, ConfCertDialog*> instances; static QMap<std::string, ConfCertDialog*> instances;
@ -165,7 +165,7 @@ void ConfCertDialog::load()
ui.loc->setText(QString::fromUtf8(detail.location.c_str())); ui.loc->setText(QString::fromUtf8(detail.location.c_str()));
// Dont Show a timestamp in RS calculate the day // Dont Show a timestamp in RS calculate the day
ui.lastcontact->setText(Rshare::customLongDate(detail.lastConnect)); ui.lastcontact->setText(DateTime::formatLongDateTime(detail.lastConnect));
/* set retroshare version */ /* set retroshare version */
std::map<std::string, std::string>::iterator vit; std::map<std::string, std::string>::iterator vit;

View File

@ -32,6 +32,7 @@
#include "util/misc.h" #include "util/misc.h"
#include "gui/RetroShareLink.h" #include "gui/RetroShareLink.h"
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
#include "util/DateTime.h"
#include <retroshare/rschannels.h> #include <retroshare/rschannels.h>
@ -188,7 +189,7 @@ void ChanMsgItem::updateItemStatic()
msgLabel->setText(RsHtml().formatText(NULL, QString::fromStdWString(cmi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); msgLabel->setText(RsHtml().formatText(NULL, QString::fromStdWString(cmi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
msgFrame->setVisible(!cmi.msg.empty()); msgFrame->setVisible(!cmi.msg.empty());
datetimelabel->setText(Rshare::customLongDate(cmi.ts)); datetimelabel->setText(DateTime::formatLongDateTime(cmi.ts));
filelabel->setText(QString("(%1 %2) %3").arg(cmi.count).arg(tr("Files")).arg(misc::friendlyUnit(cmi.size))); filelabel->setText(QString("(%1 %2) %3").arg(cmi.count).arg(tr("Files")).arg(misc::friendlyUnit(cmi.size)));

View File

@ -27,9 +27,9 @@
#include "retroshare-gui/RsAutoUpdatePage.h" #include "retroshare-gui/RsAutoUpdatePage.h"
#include "gui/msgs/MessageComposer.h" #include "gui/msgs/MessageComposer.h"
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
#include "util/DateTime.h"
#include "gui/common/AvatarDefs.h" #include "gui/common/AvatarDefs.h"
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
#include "rshare.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
@ -138,7 +138,7 @@ void ChatMsgItem::insertChat(const std::string &message)
std::cerr << "ChatMsgItem::insertChat(): " << msg << std::endl; std::cerr << "ChatMsgItem::insertChat(): " << msg << std::endl;
#endif #endif
timestampLabel->setText(Rshare::customLongDate(QDateTime::currentDateTime())); timestampLabel->setText(DateTime::formatLongDateTime(QDateTime::currentDateTime()));
QString formatMsg = QString::fromUtf8(message.c_str()); QString formatMsg = QString::fromUtf8(message.c_str());

View File

@ -32,10 +32,10 @@
#include "gui/forums/CreateForumMsg.h" #include "gui/forums/CreateForumMsg.h"
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
#include "util/DateTime.h"
#include "gui/common/AvatarDefs.h" #include "gui/common/AvatarDefs.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include "gui/ForumsDialog.h" #include "gui/ForumsDialog.h"
#include "rshare.h"
//#include "gui/settings/rsharesettings.h" //#include "gui/settings/rsharesettings.h"
/**** /****
@ -161,7 +161,7 @@ void ForumMsgItem::updateItemStatic()
prevSubLabel->setText(link.toHtml()); prevSubLabel->setText(link.toHtml());
prevMsgLabel->setText(RsHtml().formatText(NULL, ForumsDialog::messageFromInfo(msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); prevMsgLabel->setText(RsHtml().formatText(NULL, ForumsDialog::messageFromInfo(msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
timestamplabel->setText(Rshare::customLongDate(msg.ts)); timestamplabel->setText(DateTime::formatLongDateTime(msg.ts));
nextFrame->hide(); nextFrame->hide();
} }
@ -183,7 +183,7 @@ void ForumMsgItem::updateItemStatic()
nextSubLabel->setText(link.toHtml()); nextSubLabel->setText(link.toHtml());
nextMsgLabel->setText(RsHtml().formatText(NULL, ForumsDialog::messageFromInfo(msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); nextMsgLabel->setText(RsHtml().formatText(NULL, ForumsDialog::messageFromInfo(msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
timestamplabel->setText(Rshare::customLongDate(msg.ts)); timestamplabel->setText(DateTime::formatLongDateTime(msg.ts));
prevSHLabel->setText(tr("In Reply to") + ": "); prevSHLabel->setText(tr("In Reply to") + ": ");

View File

@ -27,12 +27,13 @@
#include "SubFileItem.h" #include "SubFileItem.h"
#include "gui/msgs/MessageComposer.h" #include "gui/msgs/MessageComposer.h"
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
#include "util/DateTime.h"
#include "gui/common/AvatarDefs.h" #include "gui/common/AvatarDefs.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include <retroshare/rsmsgs.h> #include <retroshare/rsmsgs.h>
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include "rshare.h"
/**** /****
* #define DEBUG_ITEM 1 * #define DEBUG_ITEM 1
****/ ****/
@ -92,9 +93,7 @@ void MsgItem::updateItemStatic()
srcName = QString::fromUtf8(rsPeers->getPeerName(mi.srcId).c_str()); srcName = QString::fromUtf8(rsPeers->getPeerName(mi.srcId).c_str());
} }
{ timestampLabel->setText(DateTime::formatLongDateTime(mi.ts));
timestampLabel->setText(Rshare::customLongDate(mi.ts));
}
if (!mIsHome) if (!mIsHome)
{ {

View File

@ -28,7 +28,7 @@
#include "gui/msgs/MessageComposer.h" #include "gui/msgs/MessageComposer.h"
#include "gui/common/StatusDefs.h" #include "gui/common/StatusDefs.h"
#include "gui/common/AvatarDefs.h" #include "gui/common/AvatarDefs.h"
#include "rshare.h" #include "util/DateTime.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
@ -118,7 +118,7 @@ void PeerItem::updateItemStatic()
{ {
/* set peer name */ /* set peer name */
peerNameLabel->setText(QString::fromUtf8(details.name.c_str())); peerNameLabel->setText(QString::fromUtf8(details.name.c_str()));
lastLabel-> setText(Rshare::customLongDate(details.lastConnect)); lastLabel-> setText(DateTime::formatLongDateTime(details.lastConnect));
/* expanded Info */ /* expanded Info */
nameLabel->setText(QString::fromUtf8(details.name.c_str())); nameLabel->setText(QString::fromUtf8(details.name.c_str()));

View File

@ -31,12 +31,12 @@
#include "gui/connect/ConfCertDialog.h" #include "gui/connect/ConfCertDialog.h"
#include "gui/connect/ConnectFriendWizard.h" #include "gui/connect/ConnectFriendWizard.h"
#include "gui/common/AvatarDefs.h" #include "gui/common/AvatarDefs.h"
#include "util/DateTime.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include <retroshare/rsmsgs.h> #include <retroshare/rsmsgs.h>
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include "rshare.h"
/***** /*****
* #define DEBUG_ITEM 1 * #define DEBUG_ITEM 1
@ -145,7 +145,7 @@ void SecurityItem::updateItemStatic()
titleLabel->setText(title); titleLabel->setText(title);
QDateTime currentTime = QDateTime::currentDateTime(); QDateTime currentTime = QDateTime::currentDateTime();
timeLabel->setText(Rshare::customLongDate(currentTime.toTime_t())); timeLabel->setText(DateTime::formatLongDateTime(currentTime.toTime_t()));
if (mIsHome) if (mIsHome)
{ {

View File

@ -19,7 +19,7 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
****************************************************************/ ****************************************************************/
#include "ForumDetails.h" #include "ForumDetails.h"
#include "rshare.h" #include "util/DateTime.h"
#include <retroshare/rsiface.h> #include <retroshare/rsiface.h>
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
@ -90,7 +90,7 @@ void ForumDetails::loadDialog()
// Set Last Post Date // Set Last Post Date
if (fi.lastPost) { if (fi.lastPost) {
ui.postline->setText(Rshare::customLongDate(fi.lastPost)); ui.postline->setText(DateTime::formatLongDateTime(fi.lastPost));
} }
// Set Forum ID // Set Forum ID

View File

@ -33,10 +33,10 @@
#include <QItemDelegate> #include <QItemDelegate>
#include <QDateTime> #include <QDateTime>
#include <QFileInfo> #include <QFileInfo>
#include <QTextStream>
#include <algorithm> #include <algorithm>
#include "rshare.h"
#include "MessageComposer.h" #include "MessageComposer.h"
#include <retroshare/rsiface.h> #include <retroshare/rsiface.h>
@ -55,6 +55,7 @@
#include "gui/common/Emoticons.h" #include "gui/common/Emoticons.h"
#include "textformat.h" #include "textformat.h"
#include "util/misc.h" #include "util/misc.h"
#include "util/DateTime.h"
#include "TagsMenu.h" #include "TagsMenu.h"
#include "gui/common/TagDefs.h" #include "gui/common/TagDefs.h"
#include "gui/connect/ConfCertDialog.h" #include "gui/connect/ConfCertDialog.h"
@ -947,9 +948,6 @@ QString MessageComposer::buildReplyHeader(const MessageInfo &msgInfo)
} }
} }
QDateTime qtime;
qtime.setTime_t(msgInfo.ts);
QString header = QString("<span>-----%1-----").arg(tr("Original Message")); QString header = QString("<span>-----%1-----").arg(tr("Original Message"));
header += QString("<br><font size='3'><strong>%1: </strong>%2</font><br>").arg(tr("From"), from); header += QString("<br><font size='3'><strong>%1: </strong>%2</font><br>").arg(tr("From"), from);
header += QString("<font size='3'><strong>%1: </strong>%2</font><br>").arg(tr("To"), to); header += QString("<font size='3'><strong>%1: </strong>%2</font><br>").arg(tr("To"), to);
@ -958,11 +956,11 @@ QString MessageComposer::buildReplyHeader(const MessageInfo &msgInfo)
header += QString("<font size='3'><strong>%1: </strong>%2</font><br>").arg(tr("Cc"), cc); header += QString("<font size='3'><strong>%1: </strong>%2</font><br>").arg(tr("Cc"), cc);
} }
header += QString("<br><font size='3'><strong>%1: </strong>%2</font><br>").arg(tr("Sent"), Rshare::customLongDate(qtime)); header += QString("<br><font size='3'><strong>%1: </strong>%2</font><br>").arg(tr("Sent"), DateTime::formatLongDateTime(msgInfo.ts));
header += QString("<font size='3'><strong>%1: </strong>%2</font></span><br>").arg(tr("Subject"), QString::fromStdWString(msgInfo.title)); header += QString("<font size='3'><strong>%1: </strong>%2</font></span><br>").arg(tr("Subject"), QString::fromStdWString(msgInfo.title));
header += "<br>"; header += "<br>";
header += tr("On %1, %2 wrote:").arg(qtime.toString(Qt::DefaultLocaleShortDate), from); header += tr("On %1, %2 wrote:").arg(DateTime::formatDateTime(msgInfo.ts), from);
return header; return header;
} }

View File

@ -41,6 +41,7 @@
#include "util/misc.h" #include "util/misc.h"
#include "util/printpreview.h" #include "util/printpreview.h"
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
#include "util/DateTime.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include <retroshare/rsfiles.h> #include <retroshare/rsfiles.h>
@ -533,11 +534,7 @@ void MessageWidget::fill(const std::string &msgId)
ui.bccText->clear(); ui.bccText->clear();
} }
{ ui.dateText->setText(DateTime::formatDateTime(msgInfo.ts));
QDateTime qtime;
qtime.setTime_t(msgInfo.ts);
ui.dateText->setText(qtime.toString(Qt::DefaultLocaleShortDate));
}
std::string ownId = rsPeers->getOwnId(); std::string ownId = rsPeers->getOwnId();

View File

@ -271,6 +271,7 @@ HEADERS += rshare.h \
gui/im_history/IMHistoryItemPainter.h \ gui/im_history/IMHistoryItemPainter.h \
lang/languagesupport.h \ lang/languagesupport.h \
util/stringutil.h \ util/stringutil.h \
util/DateTime.h \
util/win32.h \ util/win32.h \
util/RetroStyleLabel.h \ util/RetroStyleLabel.h \
util/dllexport.h \ util/dllexport.h \
@ -571,6 +572,7 @@ SOURCES += main.cpp \
gui/xprogressbar.cpp \ gui/xprogressbar.cpp \
lang/languagesupport.cpp \ lang/languagesupport.cpp \
util/stringutil.cpp \ util/stringutil.cpp \
util/DateTime.cpp \
util/win32.cpp \ util/win32.cpp \
util/RetroStyleLabel.cpp \ util/RetroStyleLabel.cpp \
util/WidgetBackgroundImage.cpp \ util/WidgetBackgroundImage.cpp \

View File

@ -57,8 +57,7 @@ QMap<QString, QString> Rshare::_args; /**< List of command-line arguments. */
QString Rshare::_style; /**< The current GUI style. */ QString Rshare::_style; /**< The current GUI style. */
QString Rshare::_language; /**< The current language. */ QString Rshare::_language; /**< The current language. */
QString Rshare::_stylesheet; /**< The current GUI stylesheet. */ QString Rshare::_stylesheet; /**< The current GUI stylesheet. */
QString Rshare::_datetimeformat; /**< The format of dates in feed items etc. */ QString Rshare::_dateformat; /**< The format of dates in feed items etc. */
QLocale Rshare::_locale; /**< The locale. */
Log Rshare::_log; Log Rshare::_log;
bool Rshare::useConfigDir; bool Rshare::useConfigDir;
QString Rshare::configDir; QString Rshare::configDir;
@ -356,31 +355,21 @@ Rshare::setLocale(QString languageCode)
return retVal; return retVal;
} }
/** return custom formatted date */
QString Rshare::customLongDate(uint fromTime)
{
return customLongDate(QDateTime::fromTime_t(fromTime));
}
QString Rshare::customLongDate(const QDateTime &fromTime)
{
if (_datetimeformat.isEmpty()) {
return fromTime.toString(Qt::ISODate);
} else {
return _locale.toString(fromTime, _datetimeformat);
}
}
/** customize date format for feeds etc. */ /** customize date format for feeds etc. */
void Rshare::customizeDateFormat() void Rshare::customizeDateFormat()
{ {
_locale = QLocale(); // set to default locale QLocale locale = QLocale(); // set to default locale
/* get long date format without weekday */ /* get long date format without weekday */
QString dateformat = _locale.dateFormat(QLocale::LongFormat); _dateformat = locale.dateFormat(QLocale::LongFormat);
dateformat.replace(QRegExp("^dddd,*[^ ]* *('[^']+' )*"), ""); _dateformat.replace(QRegExp("^dddd,*[^ ]* *('[^']+' )*"), "");
dateformat.replace(QRegExp(",* *dddd"), ""); _dateformat.replace(QRegExp(",* *dddd"), "");
dateformat = dateformat.trimmed(); _dateformat = _dateformat.trimmed();
_datetimeformat = dateformat + " " + _locale.timeFormat(QLocale::ShortFormat); }
/** Get custom date format (defaultlongformat) */
QString Rshare::customDateFormat()
{
return _dateformat;
} }
/** Sets the GUI style RetroShare will use. If one was specified on the /** Sets the GUI style RetroShare will use. If one was specified on the

View File

@ -75,9 +75,9 @@ public:
static bool setLanguage(QString languageCode = QString()); static bool setLanguage(QString languageCode = QString());
/** Sets the current locale. */ /** Sets the current locale. */
static bool setLocale(QString languageCode = QString()); static bool setLocale(QString languageCode = QString());
/** Returns custom formatted date */ /** Get custom date format (defaultlongformat) */
static QString customLongDate(uint fromTime); static QString customDateFormat();
static QString customLongDate(const QDateTime &fromTime);
/** Sets the current GUI style. */ /** Sets the current GUI style. */
static bool setStyle(QString styleKey = QString()); static bool setStyle(QString styleKey = QString());
/** Sets the current GUI stylesheet. */ /** Sets the current GUI stylesheet. */
@ -169,8 +169,7 @@ private:
static QString _style; /**< The current GUI style. */ static QString _style; /**< The current GUI style. */
static QString _stylesheet; /**< The current GUI stylesheet. */ static QString _stylesheet; /**< The current GUI stylesheet. */
static QString _language; /**< The current language. */ static QString _language; /**< The current language. */
static QString _datetimeformat; /**< The format for dates in feed items etc. */ static QString _dateformat; /**< The format for dates in feed items etc. */
static QLocale _locale; /**< The locale (object). */
static Log _log; /**< Logs debugging messages to file or stdout. */ static Log _log; /**< Logs debugging messages to file or stdout. */
static bool useConfigDir; static bool useConfigDir;

View File

@ -0,0 +1,81 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2012, RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QDateTime>
#include "DateTime.h"
#include "rshare.h"
QString DateTime::formatLongDate(time_t dateValue)
{
return formatLongDate(QDateTime::fromTime_t(dateValue).date());
}
QString DateTime::formatLongDate(const QDate &dateValue)
{
QString customDateFormat = Rshare::customDateFormat();
if (customDateFormat.isEmpty()) {
return dateValue.toString(Qt::ISODate);
} else {
return QLocale().toString(dateValue, customDateFormat);
}
}
QString DateTime::formatLongDateTime(time_t datetimeValue)
{
return formatLongDateTime(QDateTime::fromTime_t(datetimeValue));
}
QString DateTime::formatLongDateTime(const QDateTime &datetimeValue)
{
return formatLongDate(datetimeValue.date()) + " " + formatTime(datetimeValue.time());
}
QString DateTime::formatDateTime(time_t datetimeValue)
{
return formatDateTime(QDateTime::fromTime_t(datetimeValue));
}
QString DateTime::formatDateTime(const QDateTime &datetimeValue)
{
return formatDate(datetimeValue.date()) + " " + formatTime(datetimeValue.time());
}
QString DateTime::formatDate(time_t dateValue)
{
return formatDate(QDateTime::fromTime_t(dateValue).date());
}
QString DateTime::formatDate(const QDate &dateValue)
{
return dateValue.toString(Qt::SystemLocaleShortDate);
}
QString DateTime::formatTime(time_t timeValue)
{
return formatTime(QDateTime::fromTime_t(timeValue).time());
}
QString DateTime::formatTime(const QTime &timeValue)
{
return timeValue.toString(Qt::SystemLocaleShortDate);
}

View File

@ -0,0 +1,55 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 20120, RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef _DATETIME_H
#define _DATETIME_H
#include <QString>
class QDateTime;
class QDate;
class QTime;
class DateTime
{
public:
/* format long date and time e.g. "September 30, 2012" */
static QString formatLongDate(time_t dateValue);
static QString formatLongDate(const QDate &dateValue);
/* format long date and time e.g. "September 30, 2012 01:05 PM" */
static QString formatLongDateTime(time_t datetimeValue);
static QString formatLongDateTime(const QDateTime &datetimeValue);
/* format date e.g. "9/30/12", "30.09.12" */
static QString formatDate(time_t dateValue);
static QString formatDate(const QDate &dateValue);
/* format time e.g. "13:05:12" */
static QString formatTime(time_t timeValue);
static QString formatTime(const QTime &timeValue);
/* format date and time (see formatDate & formatTime) */
static QString formatDateTime(time_t datetimeValue);
static QString formatDateTime(const QDateTime &datetimeValue);
};
#endif