-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f6d371
commit 45f6b22
Showing
7 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule WomenInTechVic.Utils do | ||
@moduledoc """ | ||
Holds helper functions that can be used across the project | ||
""" | ||
|
||
@doc false | ||
@spec utc_timestamp_to_pacific!(DateTime.t()) :: DateTime.t() | ||
def utc_timestamp_to_pacific!(timestamp) do | ||
DateTime.shift_zone!(timestamp, "America/Vancouver", Tzdata.TimeZoneDatabase) | ||
end | ||
|
||
@doc "formats a given timestamp into a Weekday, Date, Time, Timezone format" | ||
@spec format_timestamp(DateTime.t()) :: String.t() | ||
def format_timestamp(timestamp) do | ||
Calendar.strftime(timestamp, "%a, %d %B %Y %I:%M %p, %Z") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
defmodule WomenInTechVicWeb.PageController do | ||
use WomenInTechVicWeb, :controller | ||
|
||
alias WomenInTechVic.Content | ||
alias WomenInTechVic.Content.Event | ||
alias WomenInTechVic.{Content, Utils} | ||
|
||
def home(conn, _params) do | ||
online_event = | ||
%{online: true, order_by: :scheduled_at, limit: 1} | ||
|> Content.all_events() | ||
|> case do | ||
[] -> "No event scheduled" | ||
[event] -> event | ||
[event] -> prep_event_for_display(event) | ||
end | ||
|
||
# The home page is often custom made, | ||
# so skip the default app layout. | ||
render(conn, :home, layout: false, event: online_event) | ||
end | ||
|
||
defp prep_event_for_display(%Event{scheduled_at: scheduled_at} = event) do | ||
event | ||
|> Map.from_struct() | ||
|> Map.put(:scheduled_at, format_scheduled_at(scheduled_at)) | ||
end | ||
|
||
defp format_scheduled_at(scheduled_at) do | ||
scheduled_at | ||
|> Utils.utc_timestamp_to_pacific!() | ||
|> Utils.format_timestamp() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule WomenInTechVic.UtilsTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias WomenInTechVic.Utils | ||
|
||
@timestamp ~U[2024-08-08 15:03:30.357348Z] | ||
|
||
describe "utc_timestamp_to_pacific/1" do | ||
test "turns utc timestamp into pacific time stamp" do | ||
assert %DateTime{} = datetime = Utils.utc_timestamp_to_pacific!(@timestamp) | ||
assert "America/Vancouver" === datetime.time_zone | ||
end | ||
end | ||
|
||
describe "format_timestamp/1" do | ||
test "turns timestamp into weekday - date -time - timezone format" do | ||
assert "Thu, 08 August 2024 03:03 PM, UTC" === Utils.format_timestamp(@timestamp) | ||
|
||
assert "Thu, 08 August 2024 08:03 AM, PDT" = | ||
Utils.format_timestamp(Utils.utc_timestamp_to_pacific!(@timestamp)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters