diff options
author | Jake Petroules <jake.petroules@petroules.com> | 2014-09-26 05:32:30 -0400 |
---|---|---|
committer | Jake Petroules <jake.petroules@petroules.com> | 2014-10-07 18:54:21 +0200 |
commit | 1cc079c29b68d08b5c83c5a323fb0512cb7bb0db (patch) | |
tree | 32939c10c820175d57e17e4b3b8ab0819d8cf976 /src/corelib/tools/qdatetime_mac.mm | |
parent | 10e3ce9e169d9c38c9cfd15a8729fa091694bf60 (diff) |
Add Objective-C specific type converters to QDateTime
This patch adds the Objective-C NSDate/CDateRef converters to
QDateTime
[ChangeLog][QtCore][Objective-C] Added NSDate/CDateRef converters for
QDateTime
Task-number: QTBUG-37116
Change-Id: I937ea927083a2767b5b17f10a48bf453c9ff8b01
Reviewed-by: Jake Petroules <jake.petroules@petroules.com>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Diffstat (limited to 'src/corelib/tools/qdatetime_mac.mm')
-rw-r--r-- | src/corelib/tools/qdatetime_mac.mm | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/corelib/tools/qdatetime_mac.mm b/src/corelib/tools/qdatetime_mac.mm new file mode 100644 index 0000000000..c8a1d22928 --- /dev/null +++ b/src/corelib/tools/qdatetime_mac.mm @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Petroules Corporation. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdatetime.h" + +#import <Foundation/Foundation.h> + +QT_BEGIN_NAMESPACE + +QDateTime QDateTime::fromCFDate(CFDateRef date) +{ + if (!date) + return QDateTime(); + return QDateTime::fromMSecsSinceEpoch(static_cast<qint64>((CFDateGetAbsoluteTime(date) + + kCFAbsoluteTimeIntervalSince1970) * 1000)); +} + +CFDateRef QDateTime::toCFDate() const +{ + return CFDateCreate(kCFAllocatorDefault, (static_cast<CFAbsoluteTime>(toMSecsSinceEpoch()) + / 1000) - kCFAbsoluteTimeIntervalSince1970); +} + +QDateTime QDateTime::fromNSDate(const NSDate *date) +{ + if (!date) + return QDateTime(); + return QDateTime::fromMSecsSinceEpoch(static_cast<qint64>([date timeIntervalSince1970] * 1000)); +} + +NSDate *QDateTime::toNSDate() const +{ + return [NSDate + dateWithTimeIntervalSince1970:static_cast<NSTimeInterval>(toMSecsSinceEpoch()) / 1000]; +} + +QT_END_NAMESPACE |