2023-04-25 17:56:57 -07:00
|
|
|
//
|
|
|
|
|
// Float.swift
|
|
|
|
|
// Meshtastic
|
|
|
|
|
//
|
|
|
|
|
// Copyright(c) Garth Vander Houwen 4/25/23.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
|
|
extension Float {
|
|
|
|
|
|
|
|
|
|
func formattedTemperature() -> String {
|
|
|
|
|
let temperature = Measurement<UnitTemperature>(value: Double(self), unit: .celsius)
|
2024-02-17 20:26:09 -08:00
|
|
|
let mf = MeasurementFormatter()
|
|
|
|
|
mf.numberFormatter.maximumFractionDigits = 0
|
|
|
|
|
return mf.string(from: temperature)
|
2023-04-25 17:56:57 -07:00
|
|
|
}
|
2024-07-12 01:28:56 -07:00
|
|
|
func shortFormattedTemperature() -> String {
|
|
|
|
|
let temperature = Measurement<UnitTemperature>(value: Double(self), unit: .celsius)
|
|
|
|
|
let mf = MeasurementFormatter()
|
|
|
|
|
mf.unitStyle = .short
|
|
|
|
|
mf.numberFormatter.maximumFractionDigits = 0
|
|
|
|
|
return mf.string(from: temperature)
|
|
|
|
|
}
|
2023-04-25 17:56:57 -07:00
|
|
|
func localeTemperature() -> Double {
|
|
|
|
|
let temperature = Measurement<UnitTemperature>(value: Double(self), unit: .celsius)
|
|
|
|
|
let locale = NSLocale.current as NSLocale
|
|
|
|
|
let localeUnit = locale.object(forKey: NSLocale.Key(rawValue: "kCFLocaleTemperatureUnitKey"))
|
|
|
|
|
var format: UnitTemperature = .celsius
|
|
|
|
|
|
|
|
|
|
if localeUnit! as? String == "Fahrenheit" {
|
|
|
|
|
format = .fahrenheit
|
|
|
|
|
}
|
|
|
|
|
return temperature.converted(to: format).value
|
|
|
|
|
}
|
|
|
|
|
}
|