Skip to content

Commit

Permalink
Improve output of autoscaleFormatted() when Duration is exactly 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Mar 25, 2024
1 parent b163b88 commit a2768b1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/HandySwift/Extensions/DurationExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ extension Duration {
/// - For a duration of 25 hours, the output will be `"1d 1h"`, scaling up to days and hours.
/// - For a duration of 2 days and 0 hours, the output will be `"2d"` as it omits the zero hour part.
///
/// - Returns: A formatted string representing the duration. If the duration is less than a second, it returns `"???"`.
/// - Returns: A formatted string representing the duration. If the duration is less than a second, it returns `"???"`. For zero returns `"0s"`.
public func autoscaleFormatted() -> String {
guard self != .zero else { return "0s" }

var leftoverTimeInterval = self.timeInterval
let fullDays = Int(leftoverTimeInterval.days)

Expand Down

0 comments on commit a2768b1

Please sign in to comment.