Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timestamps in videos list #61

Merged
merged 1 commit into from
Dec 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions apps/cf_atom_feed/lib/videos.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,28 @@ defmodule CF.AtomFeed.Videos do

defp render_entry(video) do
video_link = FrontendRouter.video_url(video.hash_id)
insert_datetime = video_datetime(video)

video_link
|> Entry.new(insert_datetime, video.title)
|> Entry.new(video.inserted_at, video.title)
|> Entry.link(video_link)
|> Entry.published(insert_datetime)
|> Entry.published(video.inserted_at)
|> Entry.content(entry_content(video))
|> Entry.build()
end

defp entry_content(%{speakers: []}) do
""
end

defp entry_content(video) do
"""
Speakers: #{Enum.map_join(video.speakers, ", ", &render_speaker/1)}
"""
Enum.map_join(video.speakers, ", ", &render_speaker/1)
end

defp render_speaker(speaker = %{full_name: name}),
do: "[#{name}](#{FrontendRouter.speaker_url(speaker)})"

defp video_datetime(%{inserted_at: naive_datetime}),
do: DateTime.from_naive!(naive_datetime, "Etc/UTC")

defp last_update([video | _]),
do: video_datetime(video)
do: video.inserted_at

defp last_update(_),
do: DateTime.utc_now()
Expand Down
2 changes: 1 addition & 1 deletion apps/db/lib/db_schema/video.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule DB.Schema.Video do
many_to_many(:speakers, Speaker, join_through: VideoSpeaker, on_delete: :delete_all)
has_many(:statements, Statement, on_delete: :delete_all)

timestamps()
timestamps(type: :utc_datetime)
end

# Define valid providers
Expand Down