diff options
author | Jake Petroules <jake.petroules@qt.io> | 2017-01-05 16:28:53 -0800 |
---|---|---|
committer | Jake Petroules <jake.petroules@qt.io> | 2017-01-23 21:55:22 +0000 |
commit | 4b507e8257243e36f40089d57099c2d668c5884d (patch) | |
tree | 23a75ff6ec67aa970d3bafdf0f029ca33a08feab /src/corelib/kernel/qcore_foundation.mm | |
parent | decab46c235bf9be355879f285022e92e88aa6b1 (diff) |
Add conversion functions for QTimeZone and CFTimeZone/NSTimeZone
Change-Id: I3a2e18d69577296bf612e13e40414bce1daa6a71
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qcore_foundation.mm')
-rw-r--r-- | src/corelib/kernel/qcore_foundation.mm | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcore_foundation.mm b/src/corelib/kernel/qcore_foundation.mm index f5ccd1c1f2..8b6be9b08e 100644 --- a/src/corelib/kernel/qcore_foundation.mm +++ b/src/corelib/kernel/qcore_foundation.mm @@ -46,6 +46,13 @@ #include <QtCore/qbytearray.h> #include <QtCore/qrect.h> +#if QT_CONFIG(timezone) && !defined(QT_NO_SYSTEMLOCALE) +#include <QtCore/qtimezone.h> +#include <QtCore/private/qtimezoneprivate_p.h> +#include <QtCore/private/qcore_mac_p.h> +#endif + +#import <CoreFoundation/CoreFoundation.h> #import <Foundation/Foundation.h> #if defined(QT_PLATFORM_UIKIT) @@ -422,6 +429,67 @@ NSDate *QDateTime::toNSDate() const // ---------------------------------------------------------------------------- +#if QT_CONFIG(timezone) && !defined(QT_NO_SYSTEMLOCALE) +/*! + \since 5.9 + + Constructs a new QTimeZone containing a copy of the CFTimeZone \a timeZone. + + \sa toCFTimeZone() +*/ +QTimeZone QTimeZone::fromCFTimeZone(CFTimeZoneRef timeZone) +{ + if (!timeZone) + return QTimeZone(); + return QTimeZone(QString::fromCFString(CFTimeZoneGetName(timeZone)).toLatin1()); +} + +/*! + \since 5.9 + + Creates a CFTimeZone from a QTimeZone. The caller owns the CFTimeZone object + and is responsible for releasing it. + + \sa fromCFTimeZone() +*/ +CFTimeZoneRef QTimeZone::toCFTimeZone() const +{ +#ifndef QT_NO_DYNAMIC_CAST + Q_ASSERT(dynamic_cast<const QMacTimeZonePrivate *>(d.data())); +#endif + const QMacTimeZonePrivate *p = static_cast<const QMacTimeZonePrivate *>(d.data()); + return reinterpret_cast<CFTimeZoneRef>([p->nsTimeZone() copy]); +} + +/*! + \since 5.9 + + Constructs a new QTimeZone containing a copy of the NSTimeZone \a timeZone. + + \sa toNSTimeZone() +*/ +QTimeZone QTimeZone::fromNSTimeZone(const NSTimeZone *timeZone) +{ + if (!timeZone) + return QTimeZone(); + return QTimeZone(QString::fromNSString(timeZone.name).toLatin1()); +} + +/*! + \since 5.9 + + Creates an NSTimeZone from a QTimeZone. The NSTimeZone object is autoreleased. + + \sa fromNSTimeZone() +*/ +NSTimeZone *QTimeZone::toNSTimeZone() const +{ + return [static_cast<NSTimeZone *>(toCFTimeZone()) autorelease]; +} +#endif + +// ---------------------------------------------------------------------------- + /*! \since 5.8 |