Skip to content

Commit d304a2e

Browse files
Stop using MSEC_PER_SEC without directly including relevant headers.
And stop doing time math by hand, use duration_cast. Fixes project-chip#33793
1 parent d84f13e commit d304a2e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/darwin/Framework/CHIP/MTRConversion.h

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#import <Foundation/Foundation.h>
2121

22+
#include <chrono>
2223
#include <lib/core/CASEAuthTag.h>
2324
#include <lib/core/CHIPError.h>
2425
#include <lib/core/Optional.h>
@@ -40,6 +41,12 @@ inline NSDate * MatterEpochSecondsAsDate(uint32_t matterEpochSeconds)
4041
return [NSDate dateWithTimeIntervalSince1970:(chip::kChipEpochSecondsSinceUnixEpoch + (NSTimeInterval) matterEpochSeconds)];
4142
}
4243

44+
template <typename Rep, typename Period>
45+
inline NSTimeInterval DurationToTimeInterval(std::chrono::duration<Rep, Period> duration)
46+
{
47+
return std::chrono::duration<NSTimeInterval>(duration).count();
48+
}
49+
4350
/**
4451
* Returns whether the conversion could be performed. Will return false if the
4552
* passed-in date is our of the range representable as a Matter epoch-s value.

src/darwin/Framework/CHIP/MTRDeviceConnectionBridge.mm

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#import "MTRDeviceConnectionBridge.h"
1919
#import "MTRBaseDevice_Internal.h"
20+
#import "MTRConversion.h"
2021
#import "MTRError_Internal.h"
2122

2223
void MTRDeviceConnectionBridge::OnConnected(
@@ -31,7 +32,7 @@
3132
{
3233
NSNumber * retryDelay;
3334
if (failureInfo.requestedBusyDelay.HasValue()) {
34-
retryDelay = @(static_cast<double>(failureInfo.requestedBusyDelay.Value().count()) / MSEC_PER_SEC);
35+
retryDelay = @(DurationToTimeInterval(failureInfo.requestedBusyDelay.Value()));
3536
}
3637
auto * object = static_cast<MTRDeviceConnectionBridge *>(context);
3738
object->mCompletionHandler(nil, chip::NullOptional, [MTRError errorForCHIPErrorCode:failureInfo.error], retryDelay);

0 commit comments

Comments
 (0)