Skip to content

Commit

Permalink
docs: change to normal comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nunom27 committed Sep 16, 2024
1 parent ab66945 commit 4041396
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 74 deletions.
49 changes: 24 additions & 25 deletions lib/atomic_web/components/calendar/month.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,31 @@ defmodule AtomicWeb.Components.CalendarMonth do
"""
end

@doc """
Generates a list of days for the calendar month, including days from the previous and next months to fill the 6x7 grid.
# Generates a list of days for the calendar month, including days from the previous and next months to fill the 6x7 grid.

Check warning on line 75 in lib/atomic_web/components/calendar/month.ex

View workflow job for this annotation

GitHub Actions / Code Quality (26.x, 1.14.x)

Line is too long (max is 120, was 123).
#
# Example
#
# iex> generate_days_list(~D[2024-09-01], ~D[2024-09-30])
# [
# ~D[2024-08-26],
# ~D[2024-08-27],
# ~D[2024-08-28],
# ~D[2024-08-29],
# ~D[2024-08-30],
# ~D[2024-08-31],
# ~D[2024-09-01],
# ~D[2024-09-02],
# ...,
# ~D[2024-09-29],
# ~D[2024-09-30],
# ~D[2024-10-01],
# ~D[2024-10-02],
# ~D[2024-10-03],
# ~D[2024-10-04],
# ~D[2024-10-05],
# ~D[2024-10-06]
# ]

## Example
iex> generate_days_list(~D[2024-09-01], ~D[2024-09-30])
[
~D[2024-08-26],
~D[2024-08-27],
~D[2024-08-28],
~D[2024-08-29],
~D[2024-08-30],
~D[2024-08-31],
~D[2024-09-01],
~D[2024-09-02],
...,
~D[2024-09-29],
~D[2024-09-30],
~D[2024-10-01],
~D[2024-10-02],
~D[2024-10-03],
~D[2024-10-04],
~D[2024-10-05],
~D[2024-10-06]
]
"""
defp generate_days_list(beginning_of_month, end_of_month) do
days_from_last_month = Timex.weekday(beginning_of_month, :monday)

Expand Down
82 changes: 39 additions & 43 deletions lib/atomic_web/components/calendar/week.ex
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,14 @@ defmodule AtomicWeb.Components.CalendarWeek do
hours * 12 + div(minutes, 5) + 2
end

@doc """
Calculates the number of grid rows the activity should span based on the time difference between the start and finish.
Each row spans a 5-minute interval.
# Each row spans a 5-minute interval.
# Calculates the number of grid rows the activity should span based on the time difference between the start and finish.

Check warning on line 167 in lib/atomic_web/components/calendar/week.ex

View workflow job for this annotation

GitHub Actions / Code Quality (26.x, 1.14.x)

Line is too long (max is 120, was 122).
#
# Example
#
# iex> calc_time(~N[2024-09-11 09:00:00], ~N[2024-09-11 10:00:00])
# 12

## Example
iex> calc_time(~N[2024-09-11 09:00:00], ~N[2024-09-11 10:00:00])
12
"""
defp calc_time(start, finish) do
time_diff = (NaiveDateTime.diff(finish, start) / 60) |> trunc()

Expand All @@ -182,22 +181,21 @@ defmodule AtomicWeb.Components.CalendarWeek do
end
end

@doc """
Calculates the total number of overlapping activities with the current activity on the same day.
## Example
# Calculates the total number of overlapping activities with the current activity on the same day.
#
# Example
#
# iex> activities = [
# ...> %{start: ~N[2024-09-11 09:00:00], finish: ~N[2024-09-11 10:00:00]},
# ...> %{start: ~N[2024-09-11 09:30:00], finish: ~N[2024-09-11 10:30:00]}
# ...> ]
# ...>
# ...> calc_total_overlaps(
# ...> %{start: ~N[2024-09-11 09:00:00], finish: ~N[2024-09-11 10:00:00]},
# ...> activities
# ...> )
# 1

iex> activities = [
...> %{start: ~N[2024-09-11 09:00:00], finish: ~N[2024-09-11 10:00:00]},
...> %{start: ~N[2024-09-11 09:30:00], finish: ~N[2024-09-11 10:30:00]}
...> ]
...>
...> calc_total_overlaps(
...> %{start: ~N[2024-09-11 09:00:00], finish: ~N[2024-09-11 10:00:00]},
...> activities
...> )
1
"""
def calc_total_overlaps(current_activity, activities) do
current_interval =
Timex.Interval.new(from: current_activity.start, until: current_activity.finish)
Expand All @@ -212,26 +210,24 @@ defmodule AtomicWeb.Components.CalendarWeek do
|> length()
end

@doc """
Calculates the left offset percentage for positioning an activity on the calendar grid.
The left offset is determined by the number of overlapping activities prior to the current one.
## Example
iex> activities = [
...> %{start: ~N[2024-09-11 09:00:00], finish: ~N[2024-09-11 10:00:00]},
...> %{start: ~N[2024-09-11 09:30:00], finish: ~N[2024-09-11 10:30:00]}
...> ]
...>
...> calc_left_amount(
...> %{start: ~N[2024-09-11 09:30:00], finish: ~N[2024-09-11 10:30:00]},
...> activities,
...> 2
...> )
50.0
"""
# Calculates the left offset percentage for positioning an activity on the calendar grid.
#
# The left offset is determined by the number of overlapping activities prior to the current one.
#
#
# Example
#
# iex> activities = [
# ...> %{start: ~N[2024-09-11 09:00:00], finish: ~N[2024-09-11 10:00:00]},
# ...> %{start: ~N[2024-09-11 09:30:00], finish: ~N[2024-09-11 10:30:00]}
# ...> ]
# ...>
# ...> calc_left_amount(
# ...> %{start: ~N[2024-09-11 09:30:00], finish: ~N[2024-09-11 10:30:00]},
# ...> activities,
# ...> 2
# ...> )
# 50.0
defp calc_left_amount(current_activity, activities, activity_total_overlaps) do
current_interval =
Timex.Interval.new(from: current_activity.start, until: current_activity.finish)
Expand Down
12 changes: 6 additions & 6 deletions lib/atomic_web/live/calendar_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<time datetime={@beginning_of_month}><%= Timex.format!(@beginning_of_month, "{Mshort} {YYYY}") %></time>
<% else %>
<%= if date_to_month(@beginning_of_week) == date_to_month(@end_of_week) do %>
<time datetime={@beginning_of_week}><%= Timex.format!(@beginning_of_week, "{Mshort} {YYYY}") %></time>
<time datetime={@beginning_of_week}><%= Timex.format!(@beginning_of_week, "{Mshort} {YYYY}") %></time>
<% else %>
<%= if date_to_year(@beginning_of_week) == date_to_year(@end_of_week) do %>
<time datetime={@beginning_of_week}><%= Timex.format!(@beginning_of_week, "{Mshort}") %> - <%= Timex.format!(@end_of_week, "{Mshort} {YYYY}") %></time>
<% else %>
<%= if date_to_year(@beginning_of_week) == date_to_year(@end_of_week) do %>
<time datetime={@beginning_of_week}><%= Timex.format!(@beginning_of_week, "{Mshort}") %> - <%= Timex.format!(@end_of_week, "{Mshort} {YYYY}") %></time>
<% else %>
<time datetime={@beginning_of_week}><%= Timex.format!(@beginning_of_week, "{Mshort} {YYYY}") %> - <%= Timex.format!(@end_of_week, "{Mshort} {YYYY}") %></time>
<% end %>
<time datetime={@beginning_of_week}><%= Timex.format!(@beginning_of_week, "{Mshort} {YYYY}") %> - <%= Timex.format!(@end_of_week, "{Mshort} {YYYY}") %></time>
<% end %>
<% end %>
<% end %>
</span>
Expand Down

0 comments on commit 4041396

Please sign in to comment.