From 13b22067187c9f764f4875c7e971d82204d3d345 Mon Sep 17 00:00:00 2001 From: Tilen Gimpelj <66419530+Tiggax@users.noreply.github.com> Date: Mon, 13 Feb 2023 16:29:22 +0100 Subject: [PATCH] Updateed the temp.nu for 0.60.0+ (#377) --- before_v0.60/temp.nu | 94 -------------------------------------------- helpers/temp.nu | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 94 deletions(-) delete mode 100644 before_v0.60/temp.nu create mode 100644 helpers/temp.nu diff --git a/before_v0.60/temp.nu b/before_v0.60/temp.nu deleted file mode 100644 index 574f599..0000000 --- a/before_v0.60/temp.nu +++ /dev/null @@ -1,94 +0,0 @@ -# Convert Fahrenheit to Celcius -def "temp f-to-c" [ - fahren:number # Degrees Fahrenheit - ] { - # (100°F − 32) × 5/9 = 37.778°C - - let celcius = (($fahren - 32) * 5 / 9) - $"($fahren) °F is ($celcius) °C" -} - -# Convert Fahrenheit to Kelvin -def "temp f-to-k" [ - fahren:number # Degrees Fahrenheit - ] { - # (100°F − 32) × 5/9 + 273.15 = 310.928K - - let kelvin = (($fahren - 32) * 5 / 9 + 273.15) - $"($fahren) °F is ($kelvin) °K" -} - -# Convert Celcius to Fahrenheit -def "temp c-to-f" [ - celcius:number # Degrees Celcius - ] { - # (100°C × 9/5) + 32 = 212°F - - let fahren = (($celcius * 9 / 5) + 32) - $"($celcius) °C is ($fahren) °F" -} - -# Convert Celcius to Kelvin -def "temp c-to-k" [ - celcius:number # Degrees Celcius - ] { - # 100°C + 273.15 = 373.15K - - let kelvin = ($celcius + 273.15) - $"($celcius) °C is ($kelvin) °K" -} - -# Convert Kelvin to Fahrenheit -def "temp k-to-f" [ - kelvin:number # Degrees Fahrenheit - ] { - # (100K − 273.15) × 9/5 + 32 = -279.7°F - - let fahren = (($kelvin - 273.15) * 9 / 5 + 32) - $"($kelvin) °K is ($fahren) °F" -} - -# Convert Kelvin to Celcius -def "temp k-to-c" [ - kelvin:number # Degrees Celcius - ] { - # 100K − 273.15 = -173.1°C - - let celcius = ($kelvin - 273.15) - $"($kelvin) °K is ($celcius) °C" -} - -def temp [] { - $"temperature conversions(char nl)" - char nl - $"Usage:(char nl)" - $" > temp ...args {flags}(char nl)" - char nl - $"Subcommands:(char nl)" - $" temp f-to-c - converts Fahrenheit to Celcius(char nl)" - $" temp f-to-k - converts Fahrenheit to Kelvin(char nl)" - $" temp c-to-f - converts Celcius to Fahrenheit(char nl)" - $" temp c-to-k - converts Celcius to Kelvin(char nl)" - $" temp k-to-f - converts Kelvin to Fahrenheit(char nl)" - $" temp k-to-c - converts Kelvin to Celcius(char nl)" - char nl - $"Parameters:(char nl)" - $" ...args: optionally convert by column paths(char nl)" - char nl - $"Flags:(char nl)" - $" -h, --help: Display this help message(char nl)" - char nl -} - -temp f-to-c 100 -char nl -temp f-to-k 100 -char nl -temp c-to-f 100 -char nl -temp c-to-k 100 -char nl -temp k-to-f 100 -char nl -temp k-to-c 100 -char nl diff --git a/helpers/temp.nu b/helpers/temp.nu new file mode 100644 index 0000000..7d7e27b --- /dev/null +++ b/helpers/temp.nu @@ -0,0 +1,72 @@ + +# Convert Fahrenheit to Celcius +export def f-to-c [ + fahren: number # Degrees Fahrenheit + --round(-r): int = 2 # Digits of precision to round to + ] { + # (100°F − 32) × 5/9 = 37.778°C + let $n = if ($fahren | describe) == "float" {$fahren} else {$fahren | into decimal } + let celcius = ((( $n - 32.) * 5 / 9. ) | math round -p $round ) + $"($fahren) °F is ($celcius) °C" +} + +# Convert Fahrenheit to Kelvin +export def f-to-k [ + fahren: number # Degrees Fahrenheit + --round(-r): int = 2 # Digits of precision to round to + ] { + # (100°F − 32) × 5/9 + 273.15 = 310.928K + + let $n = if ($fahren | describe) == "float" {$fahren} else {$fahren | into decimal } + let kelvin = ((($n - 32) * 5 / 9 + 273.15)| math round -p $round ) + $"($fahren) °F is ($kelvin) °K" +} + +# Convert Celcius to Fahrenheit +export def c-to-f [ + celcius: number # Degrees Celcius + --round(-r): int = 2 # Digits of precision to round to + ] { + # (100°C × 9/5) + 32 = 212°F + + let $n = if ($celcius | describe) == "float" {$celcius} else {$celcius | into decimal } + let fahren = ((($n * 9 / 5) + 32) | math round -p $round ) + $"($celcius) °C is ($fahren) °F" +} + +# Convert Celcius to Kelvin +export def c-to-k [ + celcius: number # Degrees Celcius + --round(-r): int = 2 # Digits of precision to round to + ] { + # 100°C + 273.15 = 373.15K + + + let $n = if ($celcius | describe) == "float" {$celcius} else {$celcius | into decimal } + let kelvin = (($n + 273.15) | math round -p $round ) + $"($celcius) °C is ($kelvin) °K" +} + +# Convert Kelvin to Fahrenheit +export def k-to-f [ + kelvin:number # Degrees Fahrenheit + --round(-r): int = 2 # Digits of precision to round to + ] { + # (100K − 273.15) × 9/5 + 32 = -279.7°F + + let $n = if ($kelvin | describe) == "float" {$kelvin} else {$kelvin | into decimal } + let fahren = ((($n - 273.15) * 9 / 5 + 32) | math round -p $round ) + $"($kelvin) °K is ($fahren) °F" +} + +# Convert Kelvin to Celcius +export def k-to-c [ + kelvin:number # Degrees Celcius + --round(-r): int = 2 # Digits of precision to round to + ] { + # 100K − 273.15 = -173.1°C + + let $n = if ($kelvin | describe) == "float" {$kelvin} else {$kelvin | into decimal } + let celcius = (($n - 273.15) | math round -p $round ) + $"($kelvin) °K is ($celcius) °C" +}