Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Itinerary

exercises/itinerary.livemd

Itinerary

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Home Report An Issue Time ConvertingTimeline

Itinerary

You are building a day planning application. Users will provide the time it takes to complete an activity in minutes and you will determine if there is enough time to fit the activity between two DateTimes.

Example Solution

defmodule Itinerary do
  def has_time?(start, finish, minutes) do
    DateTime.diff(finish, start) >= minutes * 60
  end
end

Implement the Itinerary module as documented.

defmodule Itinerary do
  @doc """
  Given a number of minutes, determine if there is enough time 
  between two `DateTimes` to fit an activity lasting a number of minutes.

  ## Examples

    iex> Itinerary.has_time?(~U[2020-01-01 12:00:00Z], ~U[2020-01-01 12:01:00Z], 1)
    true
    
    iex> Itinerary.has_time?(~U[2020-01-01 12:00:00Z], ~U[2020-01-01 12:10:00Z], 10)
    true

    iex> Itinerary.has_time?(~U[2020-01-01 07:00:00Z], ~U[2020-01-01 08:00:00Z], 60)
    true

    iex> Itinerary.has_time?(~U[2020-01-01 12:00:00Z], ~U[2020-01-01 12:30:00Z], 31)
    false

    iex> Itinerary.has_time?(~U[2020-01-01 07:00:00Z], ~U[2020-01-01 08:00:00Z], 61)
    false
    
  """
  def has_time?(start, finish, minutes) do
    total_available_time = DateTime.diff(finish, start, :minute)

    minutes <= total_available_time
  end
end

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish Itinerary exercise"
$ git push

We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation

Home Report An Issue Time ConvertingTimeline