Commit 1af0fea6 authored by Miro Knejp's avatar Miro Knejp

Obj-C Date conversion didn't use POSIX_EPOCH in fromCpp()

parent 25911e25
//
// Copyright 2014 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#pragma once
#include <chrono>
namespace djinni {
std::chrono::system_clock::time_point convert_date(const double seconds_since_epoch);
} // namespace djinni
//
// Copyright 2014 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "DJIDate.h"
namespace djinni {
std::chrono::system_clock::time_point convert_date(const double seconds_since_epoch) {
static const auto POSIX_EPOCH = std::chrono::system_clock::from_time_t(0);
const std::chrono::duration<double> converted_date(seconds_since_epoch);
const auto converted_system_date = std::chrono::duration_cast<std::chrono::system_clock::duration>(converted_date);
return POSIX_EPOCH + converted_system_date;
}
} // namespace djinni
......@@ -8,13 +8,12 @@
#pragma once
#import <Foundation/Foundation.h>
#include <chrono>
#include <cstdint>
#include <string>
#include <vector>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include "DJIDate.h"
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
......@@ -120,12 +119,16 @@ struct Date {
using Boxed = Date;
static CppType toCpp(ObjcType date) {
return ::djinni::convert_date([date timeIntervalSince1970]);
using namespace std::chrono;
static const auto POSIX_EPOCH = system_clock::from_time_t(0);
auto timeIntervalSince1970 = duration<double>([date timeIntervalSince1970]);
return POSIX_EPOCH + duration_cast<system_clock::duration>(timeIntervalSince1970);
}
static ObjcType fromCpp(const CppType& date) {
using namespace std::chrono;
return [NSDate dateWithTimeIntervalSince1970:duration_cast<duration<double>>(date.time_since_epoch()).count()];
static const auto POSIX_EPOCH = system_clock::from_time_t(0);
return [NSDate dateWithTimeIntervalSince1970:duration_cast<duration<double>>(date - POSIX_EPOCH).count()];
}
};
......
......@@ -24,7 +24,6 @@
"sources": [
"objc/DJIWeakPtrWrapper.mm",
"objc/DJIError.mm",
"objc/DJIDate.mm",
],
"include_dirs": [
"objc",
......
......@@ -53,7 +53,6 @@
A24850301AF96EBC00AFE907 /* DBRecordWithNestedDerivings.mm in Sources */ = {isa = PBXBuildFile; fileRef = A24850241AF96EBC00AFE907 /* DBRecordWithNestedDerivings.mm */; };
A24850311AF96EBC00AFE907 /* DBSetRecord.mm in Sources */ = {isa = PBXBuildFile; fileRef = A24850251AF96EBC00AFE907 /* DBSetRecord.mm */; };
A278D45319BA3601006FD937 /* test_helpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A278D45219BA3601006FD937 /* test_helpers.cpp */; };
A2A162D21AF190D200C0B00A /* DJIDate.mm in Sources */ = {isa = PBXBuildFile; fileRef = A2A162D11AF190D200C0B00A /* DJIDate.mm */; };
A2CB54B419BA6E6000A9E600 /* DJIError.mm in Sources */ = {isa = PBXBuildFile; fileRef = A2CB54B319BA6E6000A9E600 /* DJIError.mm */; };
CFFD588B1B019E79001E10B6 /* DBClientInterface+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = CFFD58871B019E79001E10B6 /* DBClientInterface+Private.mm */; };
CFFD588C1B019E79001E10B6 /* DBClientInterface+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = CFFD58871B019E79001E10B6 /* DBClientInterface+Private.mm */; };
......@@ -131,8 +130,6 @@
A238CA861AF84B7100CDDCE5 /* DBRecordWithDerivings+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBRecordWithDerivings+Private.mm"; sourceTree = "<group>"; };
A238CA881AF84B7100CDDCE5 /* DBRecordWithNestedDerivings+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBRecordWithNestedDerivings+Private.mm"; sourceTree = "<group>"; };
A238CA8A1AF84B7100CDDCE5 /* DBSetRecord+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBSetRecord+Private.mm"; sourceTree = "<group>"; };
A239F3771AF400C600DF27C8 /* DJIDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DJIDate.h; sourceTree = "<group>"; };
A239F3781AF400C600DF27C8 /* DJIDate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DJIDate.mm; sourceTree = "<group>"; };
A239F3791AF400C600DF27C8 /* DJIMarshal+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DJIMarshal+Private.h"; sourceTree = "<group>"; };
A24249191AF192E0003BF8F0 /* DBAssortedIntegers+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBAssortedIntegers+Private.h"; sourceTree = "<group>"; };
A242491A1AF192E0003BF8F0 /* DBAssortedIntegers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBAssortedIntegers.h; sourceTree = "<group>"; };
......@@ -200,8 +197,6 @@
A24850241AF96EBC00AFE907 /* DBRecordWithNestedDerivings.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBRecordWithNestedDerivings.mm; sourceTree = "<group>"; };
A24850251AF96EBC00AFE907 /* DBSetRecord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBSetRecord.mm; sourceTree = "<group>"; };
A278D45219BA3601006FD937 /* test_helpers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_helpers.cpp; sourceTree = "<group>"; };
A2A162D01AF190D200C0B00A /* DJIDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DJIDate.h; sourceTree = "<group>"; };
A2A162D11AF190D200C0B00A /* DJIDate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DJIDate.mm; sourceTree = "<group>"; };
A2CB54B319BA6E6000A9E600 /* DJIError.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DJIError.mm; sourceTree = "<group>"; };
A2CCB9411AF80DFC00E6230A /* DBClientInterface+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBClientInterface+Private.h"; sourceTree = "<group>"; };
CFFD58871B019E79001E10B6 /* DBClientInterface+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBClientInterface+Private.mm"; sourceTree = "<group>"; };
......@@ -242,11 +237,7 @@
6536CD6919A6C82200DD7715 /* objc-support-lib */ = {
isa = PBXGroup;
children = (
A239F3771AF400C600DF27C8 /* DJIDate.h */,
A239F3781AF400C600DF27C8 /* DJIDate.mm */,
A239F3791AF400C600DF27C8 /* DJIMarshal+Private.h */,
A2A162D01AF190D200C0B00A /* DJIDate.h */,
A2A162D11AF190D200C0B00A /* DJIDate.mm */,
A2CB54B319BA6E6000A9E600 /* DJIError.mm */,
6536CD6A19A6C82200DD7715 /* DJIError.h */,
6536CD6B19A6C82200DD7715 /* DJIWeakPtrWrapper+Private.h */,
......@@ -531,7 +522,6 @@
A248502C1AF96EBC00AFE907 /* DBMapRecord.mm in Sources */,
6536CD7419A6C96C00DD7715 /* DBClientInterfaceImpl.mm in Sources */,
A24850301AF96EBC00AFE907 /* DBRecordWithNestedDerivings.mm in Sources */,
A2A162D21AF190D200C0B00A /* DJIDate.mm in Sources */,
CFFD58B11B041BD9001E10B6 /* DBConstantsInterface.mm in Sources */,
CFFD58B31B041BD9001E10B6 /* DBConstantsInterface+Private.mm in Sources */,
A248502F1AF96EBC00AFE907 /* DBRecordWithDerivings.mm in Sources */,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment