Skip to content

Commit

Permalink
Stop using MSEC_PER_SEC without directly including relevant headers.
Browse files Browse the repository at this point in the history
And stop doing time math by hand, use duration_cast.

Fixes #33793
  • Loading branch information
bzbarsky-apple committed Jun 7, 2024
1 parent d84f13e commit d304a2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/darwin/Framework/CHIP/MTRConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#import <Foundation/Foundation.h>

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

template <typename Rep, typename Period>
inline NSTimeInterval DurationToTimeInterval(std::chrono::duration<Rep, Period> duration)
{
return std::chrono::duration<NSTimeInterval>(duration).count();
}

/**
* Returns whether the conversion could be performed. Will return false if the
* passed-in date is our of the range representable as a Matter epoch-s value.
Expand Down
3 changes: 2 additions & 1 deletion src/darwin/Framework/CHIP/MTRDeviceConnectionBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#import "MTRDeviceConnectionBridge.h"
#import "MTRBaseDevice_Internal.h"
#import "MTRConversion.h"
#import "MTRError_Internal.h"

void MTRDeviceConnectionBridge::OnConnected(
Expand All @@ -31,7 +32,7 @@
{
NSNumber * retryDelay;
if (failureInfo.requestedBusyDelay.HasValue()) {
retryDelay = @(static_cast<double>(failureInfo.requestedBusyDelay.Value().count()) / MSEC_PER_SEC);
retryDelay = @(DurationToTimeInterval(failureInfo.requestedBusyDelay.Value()));
}
auto * object = static_cast<MTRDeviceConnectionBridge *>(context);
object->mCompletionHandler(nil, chip::NullOptional, [MTRError errorForCHIPErrorCode:failureInfo.error], retryDelay);
Expand Down

0 comments on commit d304a2e

Please sign in to comment.