You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
MGLDurationInSecondsFromTimeInterval() converts an NSTimeInterval (measured in seconds) into an mbgl::Duration (measured in nanoseconds), but MGLTimeIntervalFromDurationInSeconds() reinterprets an mbgl::Duration (measured in nanoseconds) as an NSTimeInterval without changing its value. As a result, these functions don’t round-trip and -[MGLStyle transitionDuration] and -[MGLStyle transitionDelay] return the wrong values. We should fix MGLTimeIntervalFromDurationInSeconds() to convert back into seconds. This page has examples for working with duration. We should also add a unit test to ensure round-tripping.
Additionally, the functions’ names incorrectly imply that mbgl::Duration is measured in seconds. They should be renamed MGLDurationFromTimeInterval() and MGLTimeIntervalFromDuration(), respectively.
Finally, #5980 declared and defined these functions within @interface and @implementation blocks, as though they were category methods, but they aren’t even methods in the first place. The NSDate(MGLAdditions) category should be removed, because these functions have nothing to do with NSDate. (These functions should remain in NSDate+MGLAdditions.h, because they relate to NSTimeInterval, which is declared in NSDate.h.)
MGLDurationInSecondsFromTimeInterval() has quite a bit of history:
cutting-room-floor/mapbox-gl-cocoa@08c15ca introduced secondsAsDuration() as a way to convert a float (measuring seconds) into an std::chrono::steady_clock::duration (measured in nanoseconds). It made sense to say “seconds” because float doesn’t specify any units.
Fix static analyzer warnings #3006 renamed it durationInSeconds(), since the return type should come before the argument type in a function name.
Cleanup std::chrono usage #3576 changed it to accept an NSTimeInterval and return an mbgl::Duration, making the function more type-safe. “In seconds” became redundant, since NSTimeInterval is always measured in seconds.
MGLDurationInSecondsFromTimeInterval()
converts anNSTimeInterval
(measured in seconds) into anmbgl::Duration
(measured in nanoseconds), butMGLTimeIntervalFromDurationInSeconds()
reinterprets anmbgl::Duration
(measured in nanoseconds) as anNSTimeInterval
without changing its value. As a result, these functions don’t round-trip and-[MGLStyle transitionDuration]
and-[MGLStyle transitionDelay]
return the wrong values. We should fixMGLTimeIntervalFromDurationInSeconds()
to convert back into seconds. This page has examples for working withduration
. We should also add a unit test to ensure round-tripping.Additionally, the functions’ names incorrectly imply that
mbgl::Duration
is measured in seconds. They should be renamedMGLDurationFromTimeInterval()
andMGLTimeIntervalFromDuration()
, respectively.Finally, #5980 declared and defined these functions within
@interface
and@implementation
blocks, as though they were category methods, but they aren’t even methods in the first place. TheNSDate(MGLAdditions)
category should be removed, because these functions have nothing to do with NSDate. (These functions should remain in NSDate+MGLAdditions.h, because they relate toNSTimeInterval
, which is declared in NSDate.h.)/cc @fabian-guerra @incanus
The text was updated successfully, but these errors were encountered: