@@ -299,6 +299,10 @@ func timeStampToString(from timestamp: TimeInterval?) -> String {
299299 return formatter. string ( from: date)
300300}
301301
302+ func pluralize( _ count: Int , _ identifier: String ) -> String {
303+ return " \( count) \( identifier) \( count == 1 ? " " : " s " ) "
304+ }
305+
302306func timeLeftString( until timestamp: TimeInterval ? , asString: Bool = true ) -> String {
303307 guard let timestamp = timestamp else {
304308 return " Unknown "
@@ -328,26 +332,26 @@ func timeLeftString(until timestamp: TimeInterval?, asString: Bool = true) -> St
328332 if asString {
329333 var components : [ String ] = [ ]
330334 if years > 0 {
331- components. append ( " \ ( years) year\( years == 1 ? " " : " s " ) " )
335+ components. append ( pluralize ( years, " year " ) )
332336 }
333337 if months > 0 {
334- components. append ( " \ ( months) month\( months == 1 ? " " : " s " ) " )
338+ components. append ( pluralize ( months, " month " ) )
335339 }
336340 if weeks > 0 {
337- components. append ( " \ ( weeks) week\( weeks == 1 ? " " : " s " ) " )
341+ components. append ( pluralize ( weeks, " week " ) )
338342 }
339343 if days > 0 {
340- components. append ( " \ ( days) day\( days == 1 ? " " : " s " ) " )
344+ components. append ( pluralize ( days, " day " ) )
341345 }
342346 if hours > 0 {
343- components. append ( " \ ( hours) hour\( hours == 1 ? " " : " s " ) " )
347+ components. append ( pluralize ( hours, " hour " ) )
344348 }
345349 if minutes > 0 {
346- components. append ( " \ ( minutes) minute\( minutes == 1 ? " " : " s " ) " )
350+ components. append ( pluralize ( minutes, " minute " ) )
347351 }
348352 if components. isEmpty {
349353 // If seconds is the only option
350- components. append ( " \ ( seconds) second\( seconds == 1 ? " " : " s " ) " )
354+ components. append ( pluralize ( seconds, " second " ) )
351355 }
352356 return components. joined ( separator: " , " )
353357 } else {
0 commit comments