Calculates the delta of 2 laptimes
The package can be installed by adding hotlap
to your list of dependencies in mix.exs
:
def deps do
[
{:hotlap, "~> 1.0.0"}
]
end
# create laptime struct
laptime = %Hotlap.Laptime{minutes: 1, seconds: 22, milliseconds: 455}
# => %Hotlap.Laptime{minutes: 1, seconds: 22, milliseconds: 455}
# create from string
{:ok, laptime} = Hotlap.Laptime.create("01:22.455")
# => %Hotlap.Laptime{minutes: 1, seconds: 22, milliseconds: 455}
# convert to milliseconds
laptime_milliseconds = Hotlap.LaptimeConverter.to_milliseconds(laptime)
# => 82455
# compare two laptimes
{:ok, target_laptime} = Hotlap.Laptime.create("01:22.455")
{:ok, current_laptime} = Hotlap.Laptime.create("01:22.899")
delta = Hotlap.compare(target_laptime, current_laptime)
# => %Hotlap.Delta{minutes: 0, seconds: 0, milliseconds: 455, status: :behind}
# string representation
IO.puts "Target: #{target_laptime}" # => 01:22.455
IO.puts "Current: #{current_laptime}" # => 01:22.899
IO.puts "Delta: #{delta}" # => +0.444
This module is published under the MIT license