//
//  Measurement+String.swift
//  1Weather
//
//  Created by Dmitry Stepanets on 03.03.2021.
//

import Foundation

extension Measurement {
    private static func formatter(style: Formatter.UnitStyle) -> MeasurementFormatter {
        let fmt = MeasurementFormatter()
        fmt.locale = Settings.shared.locale
        fmt.unitStyle = style
        fmt.numberFormatter.maximumFractionDigits = 0
        return fmt
    }
    
    var string:String {
        return Measurement.formatter(style: .medium).string(from: self)
    }
    
    var shortString:String {
        return Measurement.formatter(style: .short).string(from: self)
    }
    
    var longString:String {
        return Measurement.formatter(style: .long).string(from: self)
    }
}

extension Temperature {
    var localizedValue:Double {
        return self.converted(to: Settings.shared.temperatureType).value.rounded(.down)
    }
}
