From cb2dd0b75e3a153ed091680d48ad9dfc5e163f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wei=C3=9F?= Date: Wed, 5 May 2021 13:12:37 +0200 Subject: [PATCH] Improve SecondsFormatter. --- Formatters/SecondsFormatter.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Formatters/SecondsFormatter.m b/Formatters/SecondsFormatter.m index d0f3a8799..05a244f99 100644 --- a/Formatters/SecondsFormatter.m +++ b/Formatters/SecondsFormatter.m @@ -31,11 +31,17 @@ unsigned minutes = 0; unsigned seconds = 0; - if(nil == object || NO == [object isKindOfClass:[NSNumber class]] || isnan([object doubleValue])) { - return @""; + if (nil == object || NO == [object isKindOfClass:[NSNumber class]]) { + // Docs state: “Returns nil if object is not of the correct class.” + return nil; } - value = (unsigned)([object doubleValue]); + float floatValue = [object floatValue]; + + if (isnan(floatValue)) { return @"NaN"; } + if (isinf(floatValue)) { return @"Inf"; } + + value = (unsigned)(floatValue); seconds = value % 60; minutes = value / 60;