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 was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
NSDate(MGLAdditions) turns seconds into nanoseconds #8264
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.
Activity
1ec5 commentedon Mar 3, 2017
MGLDurationInSecondsFromTimeInterval()has quite a bit of history:secondsAsDuration()as a way to convert afloat(measuring seconds) into anstd::chrono::steady_clock::duration(measured in nanoseconds). It made sense to say “seconds” becausefloatdoesn’t specify any units.durationInSeconds(), since the return type should come before the argument type in a function name.MGLDurationInSeconds().NSTimeIntervaland return anmbgl::Duration, making the function more type-safe. “In seconds” became redundant, sinceNSTimeIntervalis always measured in seconds.MGLDurationInSecondsFromTimeInterval()to indicate the argument type explicitly.Not to point any blame – the naming made sense at the time, but it’s a good thing that we can finally remove “in seconds”!
jfirebaugh commentedon Mar 6, 2017
#8276 addressed the above issues but introduced others (https://github.com/mapbox/mapbox-gl-native/pull/8276/files#r104329402). Keeping this open until those are resolved.
jfirebaugh commentedon Mar 9, 2017
Fixed in #8290.