X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Futil.h;h=0db903e4679105471a94e64599b521b140b719ce;hp=61530a0961e5bab0e5ae074578c55724068c83ce;hb=ee8b9f55860e340c1600188fddcfd557c7489f66;hpb=b06a827aea68b050bf23c37e0162189a94595ee9 diff --git a/src/common/util.h b/src/common/util.h index 61530a09..0db903e4 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -79,3 +79,27 @@ QByteArray prettyDigest(const QByteArray &digest); * @return String with current date/time substituted in via formatting codes */ QString formatCurrentDateTimeInString(const QString &formatStr); + +/** + * Try to localize a given date/time in seconds from Unix epoch, pass through string if invalid + * + * Allows compatibility with date/time fields that may or may not be in Unix epoch format, + * localizing if possible, leaving alone if not. + * + * @param possibleEpochDate Date/time that might be in seconds since Unix epoch format + * @param dateFormat Desired format of the date/time string + * @param useUTC If true, use UTC timezone, otherwise use local time + * @return Localized date/time if parse succeeded, otherwise the source string + */ +QString tryFormatUnixEpoch(const QString &possibleEpochDate, + Qt::DateFormat dateFormat = Qt::DateFormat::TextDate, + bool useUTC = false); + + +/** + * Format the given date/time in ISO 8601 format with timezone offset + * + * @param dateTime Date/time of interest + * @return Date/time in ISO 8601 format with timezone offset + */ +QString formatDateTimeToOffsetISO(const QDateTime &dateTime);