Double.swift 471 B

1234567891011121314151617181920
  1. //
  2. // Double.swift
  3. // Mastodon
  4. //
  5. // Created by sxiaojian on 2021/3/8.
  6. //
  7. import Foundation
  8. extension Double {
  9. func asString(style: DateComponentsFormatter.UnitsStyle) -> String {
  10. let formatter = DateComponentsFormatter()
  11. formatter.allowedUnits = [.minute, .second]
  12. formatter.unitsStyle = style
  13. formatter.zeroFormattingBehavior = .pad
  14. guard let formattedString = formatter.string(from: self) else { return "" }
  15. return formattedString
  16. }
  17. }