Expunge improper schema use of NaiveDateTime (#91)

This commit is contained in:
liamwhite 2021-01-18 13:01:03 -05:00 committed by GitHub
parent 24b22f78be
commit 0f6a773286
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 70 additions and 73 deletions

View file

@ -27,7 +27,7 @@ defmodule Philomena.Adverts.Advert do
field :start_time, :string, virtual: true field :start_time, :string, virtual: true
field :finish_time, :string, virtual: true field :finish_time, :string, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -20,7 +20,7 @@ defmodule Philomena.ArtistLinks.ArtistLink do
field :next_check_at, :utc_datetime field :next_check_at, :utc_datetime
field :contacted_at, :utc_datetime field :contacted_at, :utc_datetime
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -15,7 +15,7 @@ defmodule Philomena.Badges.Award do
field :reason, :string field :reason, :string
field :badge_name, :string field :badge_name, :string
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -13,7 +13,7 @@ defmodule Philomena.Badges.Badge do
field :removed_image, :string, virtual: true field :removed_image, :string, virtual: true
field :image_mime_type, :string, virtual: true field :image_mime_type, :string, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -18,7 +18,7 @@ defmodule Philomena.Bans.Fingerprint do
field :until, :string, virtual: true field :until, :string, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -18,7 +18,7 @@ defmodule Philomena.Bans.Subnet do
field :until, :string, virtual: true field :until, :string, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -21,7 +21,7 @@ defmodule Philomena.Bans.User do
field :username, :string, virtual: true field :username, :string, virtual: true
field :until, :string, virtual: true field :until, :string, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -32,7 +32,7 @@ defmodule Philomena.Channels.Channel do
field :remote_stream_id, :integer field :remote_stream_id, :integer
field :thumbnail_url, :string, default: "" field :thumbnail_url, :string, default: ""
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -23,7 +23,7 @@ defmodule Philomena.Comments.Comment do
field :destroyed_content, :boolean, default: false field :destroyed_content, :boolean, default: false
field :name_at_post_time, :string field :name_at_post_time, :string
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -19,7 +19,7 @@ defmodule Philomena.Commissions.Commission do
field :will_not_create, :string field :will_not_create, :string
field :commission_items_count, :integer, default: 0 field :commission_items_count, :integer, default: 0
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -14,7 +14,7 @@ defmodule Philomena.Commissions.Item do
field :base_price, :decimal field :base_price, :decimal
field :add_ons, :string field :add_ons, :string
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -22,7 +22,7 @@ defmodule Philomena.Conversations.Conversation do
field :last_message_at, :utc_datetime field :last_message_at, :utc_datetime
field :recipient, :string, virtual: true field :recipient, :string, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -11,7 +11,7 @@ defmodule Philomena.Conversations.Message do
field :body, :string field :body, :string
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -18,7 +18,7 @@ defmodule Philomena.DnpEntries.DnpEntry do
field :instructions, :string, default: "" field :instructions, :string, default: ""
field :feedback, :string, default: "" field :feedback, :string, default: ""
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -14,7 +14,7 @@ defmodule Philomena.Donations.Donation do
field :receipt_id, :string field :receipt_id, :string
field :note, :string field :note, :string
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -14,7 +14,7 @@ defmodule Philomena.DuplicateReports.DuplicateReport do
field :reason, :string field :reason, :string
field :state, :string, default: "open" field :state, :string, default: "open"
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -23,7 +23,7 @@ defmodule Philomena.Filters.Filter do
field :spoilered_tag_list, :string, virtual: true field :spoilered_tag_list, :string, virtual: true
field :hidden_tag_list, :string, virtual: true field :hidden_tag_list, :string, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -19,7 +19,7 @@ defmodule Philomena.Forums.Forum do
field :topic_count, :integer, default: 0 field :topic_count, :integer, default: 0
field :post_count, :integer, default: 0 field :post_count, :integer, default: 0
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -20,7 +20,7 @@ defmodule Philomena.Galleries.Gallery do
field :image_count, :integer field :image_count, :integer
field :order_position_asc, :boolean field :order_position_asc, :boolean
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -11,7 +11,7 @@ defmodule Philomena.ImageFeatures.ImageFeature do
belongs_to :image, Image belongs_to :image, Image
belongs_to :user, User belongs_to :user, User
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -319,7 +319,7 @@ defmodule Philomena.Images do
end end
defp tag_change_attributes(attribution, image, tag, added, user) do defp tag_change_attributes(attribution, image, tag, added, user) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = DateTime.utc_now() |> DateTime.truncate(:second)
user_id = user_id =
case user do case user do
@ -482,7 +482,7 @@ defmodule Philomena.Images do
defp update_first_seen_at(image, time_1, time_2) do defp update_first_seen_at(image, time_1, time_2) do
min_time = min_time =
case NaiveDateTime.compare(time_1, time_2) do case DateTime.compare(time_1, time_2) do
:gt -> time_2 :gt -> time_2
_ -> time_1 _ -> time_1
end end
@ -551,7 +551,7 @@ defmodule Philomena.Images do
|> where([t], t.image_id in ^image_ids and t.tag_id in ^removed_tags) |> where([t], t.image_id in ^image_ids and t.tag_id in ^removed_tags)
|> select([t], [t.image_id, t.tag_id]) |> select([t], [t.image_id, t.tag_id])
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = DateTime.utc_now() |> DateTime.truncate(:second)
tag_change_attributes = Map.merge(tag_change_attributes, %{created_at: now, updated_at: now}) tag_change_attributes = Map.merge(tag_change_attributes, %{created_at: now, updated_at: now})
tag_attributes = %{name: "", slug: "", created_at: now, updated_at: now} tag_attributes = %{name: "", slug: "", created_at: now, updated_at: now}

View file

@ -75,7 +75,7 @@ defmodule Philomena.Images.Image do
field :tag_editing_allowed, :boolean, default: true field :tag_editing_allowed, :boolean, default: true
field :description_editing_allowed, :boolean, default: true field :description_editing_allowed, :boolean, default: true
field :commenting_allowed, :boolean, default: true field :commenting_allowed, :boolean, default: true
field :first_seen_at, :naive_datetime field :first_seen_at, :utc_datetime
field :destroyed_content, :boolean field :destroyed_content, :boolean
field :hidden_image_key, :string field :hidden_image_key, :string
field :scratchpad, :string field :scratchpad, :string
@ -92,7 +92,7 @@ defmodule Philomena.Images.Image do
field :uploaded_image, :string, virtual: true field :uploaded_image, :string, virtual: true
field :removed_image, :string, virtual: true field :removed_image, :string, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
def interaction_data(image) do def interaction_data(image) do
@ -112,7 +112,7 @@ defmodule Philomena.Images.Image do
end end
def creation_changeset(image, attrs, attribution) do def creation_changeset(image, attrs, attribution) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = DateTime.utc_now() |> DateTime.truncate(:second)
image image
|> cast(attrs, [:anonymous, :source_url, :description]) |> cast(attrs, [:anonymous, :source_url, :description])

View file

@ -72,7 +72,7 @@ defmodule Philomena.Interactions do
end end
def migrate_interactions(source, target) do def migrate_interactions(source, target) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = DateTime.utc_now() |> DateTime.truncate(:second)
source = Repo.preload(source, [:hiders, :favers, :upvoters, :downvoters]) source = Repo.preload(source, [:hiders, :favers, :upvoters, :downvoters])
new_hides = Enum.map(source.hiders, &%{image_id: target.id, user_id: &1.id, created_at: now}) new_hides = Enum.map(source.hiders, &%{image_id: target.id, user_id: &1.id, created_at: now})

View file

@ -15,7 +15,7 @@ defmodule Philomena.ModNotes.ModNote do
field :notable, :any, virtual: true field :notable, :any, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -14,7 +14,7 @@ defmodule Philomena.Notifications.Notification do
field :actor, :any, virtual: true field :actor, :any, virtual: true
field :actor_child, :any, virtual: true field :actor_child, :any, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -41,7 +41,7 @@ defmodule Philomena.PollVotes do
""" """
def create_poll_votes(user, poll, attrs) do def create_poll_votes(user, poll, attrs) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = DateTime.utc_now() |> DateTime.truncate(:second)
poll_votes = filter_options(user, poll, now, attrs) poll_votes = filter_options(user, poll, now, attrs)
Multi.new() Multi.new()

View file

@ -20,7 +20,7 @@ defmodule Philomena.Polls.Poll do
field :deletion_reason, :string, default: "" field :deletion_reason, :string, default: ""
field :until, :string, virtual: true field :until, :string, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -24,7 +24,7 @@ defmodule Philomena.Posts.Post do
field :destroyed_content, :boolean, default: false field :destroyed_content, :boolean, default: false
field :name_at_post_time, :string field :name_at_post_time, :string
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -23,7 +23,7 @@ defmodule Philomena.Reports.Report do
field :reportable, :any, virtual: true field :reportable, :any, virtual: true
field :category, :string, virtual: true field :category, :string, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -9,7 +9,7 @@ defmodule Philomena.Roles.Role do
field :resource_id, :integer field :resource_id, :integer
field :resource_type, :string field :resource_type, :string
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -19,7 +19,7 @@ defmodule Philomena.SiteNotices.SiteNotice do
field :start_time, :string, virtual: true field :start_time, :string, virtual: true
field :finish_time, :string, virtual: true field :finish_time, :string, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -15,7 +15,7 @@ defmodule Philomena.SourceChanges.SourceChange do
field :source_url, :string, source: :new_value field :source_url, :string, source: :new_value
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -9,7 +9,7 @@ defmodule Philomena.StaticPages.StaticPage do
field :slug, :string field :slug, :string
field :body, :string field :body, :string
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -15,7 +15,7 @@ defmodule Philomena.StaticPages.Version do
field :difference, :any, virtual: true field :difference, :any, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -14,7 +14,7 @@ defmodule Philomena.TagChanges do
# TODO: this is substantially similar to Images.batch_update/4. # TODO: this is substantially similar to Images.batch_update/4.
# Perhaps it should be extracted. # Perhaps it should be extracted.
def mass_revert(ids, attributes) do def mass_revert(ids, attributes) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = DateTime.utc_now() |> DateTime.truncate(:second)
tag_change_attributes = Map.merge(attributes, %{created_at: now, updated_at: now}) tag_change_attributes = Map.merge(attributes, %{created_at: now, updated_at: now})
tag_attributes = %{name: "", slug: "", created_at: now, updated_at: now} tag_attributes = %{name: "", slug: "", created_at: now, updated_at: now}

View file

@ -14,7 +14,7 @@ defmodule Philomena.TagChanges.TagChange do
field :added, :boolean field :added, :boolean
field :tag_name_cache, :string, default: "" field :tag_name_cache, :string, default: ""
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -90,7 +90,7 @@ defmodule Philomena.Tags.Tag do
field :implied_tag_list, :string, virtual: true field :implied_tag_list, :string, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -32,7 +32,7 @@ defmodule Philomena.Topics.Topic do
field :anonymous, :boolean, default: false field :anonymous, :boolean, default: false
field :hidden_from_users, :boolean, default: false field :hidden_from_users, :boolean, default: false
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -10,7 +10,7 @@ defmodule Philomena.UserFingerprints.UserFingerprint do
field :fingerprint, :string field :fingerprint, :string
field :uses, :integer, default: 0 field :uses, :integer, default: 0
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -10,7 +10,7 @@ defmodule Philomena.UserIps.UserIp do
field :ip, EctoNetwork.INET field :ip, EctoNetwork.INET
field :uses, :integer, default: 0 field :uses, :integer, default: 0
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -8,7 +8,7 @@ defmodule Philomena.UserNameChanges.UserNameChange do
belongs_to :user, User belongs_to :user, User
field :name, :string field :name, :string
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -8,7 +8,7 @@ defmodule Philomena.UserWhitelists.UserWhitelist do
belongs_to :user, User belongs_to :user, User
field :reason, :string field :reason, :string
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc false @doc false

View file

@ -321,8 +321,8 @@ defimpl Canada.Can, for: [Atom, Philomena.Users.User] do
# Edit their username # Edit their username
def can?(%User{id: id}, :change_username, %User{id: id} = user) do def can?(%User{id: id}, :change_username, %User{id: id} = user) do
time_ago = NaiveDateTime.utc_now() |> NaiveDateTime.add(-1 * 60 * 60 * 24 * 90) time_ago = DateTime.utc_now() |> DateTime.add(-1 * 60 * 60 * 24 * 90)
NaiveDateTime.diff(user.last_renamed_at, time_ago) < 0 DateTime.diff(user.last_renamed_at, time_ago) < 0
end end
# View conversations they are involved in # View conversations they are involved in

View file

@ -48,12 +48,12 @@ defmodule Philomena.Users.User do
field :password, :string, virtual: true field :password, :string, virtual: true
field :encrypted_password, :string field :encrypted_password, :string
field :hashed_password, :string, source: :encrypted_password field :hashed_password, :string, source: :encrypted_password
field :confirmed_at, :naive_datetime field :confirmed_at, :utc_datetime
field :otp_required_for_login, :boolean field :otp_required_for_login, :boolean
field :authentication_token, :string field :authentication_token, :string
field :failed_attempts, :integer field :failed_attempts, :integer
# field :unlock_token, :string # field :unlock_token, :string
field :locked_at, :naive_datetime field :locked_at, :utc_datetime
field :encrypted_otp_secret, :string field :encrypted_otp_secret, :string
field :encrypted_otp_secret_iv, :string field :encrypted_otp_secret_iv, :string
field :encrypted_otp_secret_salt, :string field :encrypted_otp_secret_salt, :string
@ -111,9 +111,9 @@ defmodule Philomena.Users.User do
field :watched_tag_list, :string, virtual: true field :watched_tag_list, :string, virtual: true
# Other stuff # Other stuff
field :last_donation_at, :naive_datetime field :last_donation_at, :utc_datetime
field :last_renamed_at, :naive_datetime field :last_renamed_at, :utc_datetime
field :deleted_at, :naive_datetime field :deleted_at, :utc_datetime
field :scratchpad, :string field :scratchpad, :string
field :secondary_role, :string field :secondary_role, :string
field :hide_default_role, :boolean, default: false field :hide_default_role, :boolean, default: false
@ -130,7 +130,7 @@ defmodule Philomena.Users.User do
# For mod stuff # For mod stuff
field :role_map, :any, virtual: true field :role_map, :any, virtual: true
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end
@doc """ @doc """
@ -212,7 +212,7 @@ defmodule Philomena.Users.User do
Confirms the account by setting `confirmed_at`. Confirms the account by setting `confirmed_at`.
""" """
def confirm_changeset(user) do def confirm_changeset(user) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = DateTime.utc_now() |> DateTime.truncate(:second)
change(user, confirmed_at: now) change(user, confirmed_at: now)
end end
@ -256,7 +256,7 @@ defmodule Philomena.Users.User do
end end
def lock_changeset(user) do def lock_changeset(user) do
locked_at = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) locked_at = DateTime.utc_now() |> DateTime.truncate(:second)
change(user, locked_at: locked_at) change(user, locked_at: locked_at)
end end
@ -353,7 +353,7 @@ defmodule Philomena.Users.User do
end end
def name_changeset(user, attrs) do def name_changeset(user, attrs) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = DateTime.utc_now() |> DateTime.truncate(:second)
user user
|> cast(attrs, [:name]) |> cast(attrs, [:name])
@ -403,7 +403,7 @@ defmodule Philomena.Users.User do
end end
def deactivate_changeset(user, moderator) do def deactivate_changeset(user, moderator) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = DateTime.utc_now() |> DateTime.truncate(:second)
change(user, deleted_at: now, deleted_by_user_id: moderator.id) change(user, deleted_at: now, deleted_by_user_id: moderator.id)
end end

View file

@ -28,7 +28,7 @@ defmodule PhilomenaWeb.AdvertUpdater do
# Read impression counts from mailbox # Read impression counts from mailbox
{impressions, clicks} = receive_all() {impressions, clicks} = receive_all()
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = DateTime.utc_now() |> DateTime.truncate(:second)
# Create insert statements for Ecto # Create insert statements for Ecto
impressions = Enum.map(impressions, &impressions_insert_all(&1, now)) impressions = Enum.map(impressions, &impressions_insert_all(&1, now))

View file

@ -46,7 +46,7 @@ defmodule PhilomenaWeb.StatsUpdater do
images_in_galleries: images_in_galleries images_in_galleries: images_in_galleries
) )
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = DateTime.utc_now() |> DateTime.truncate(:second)
static_page = %{ static_page = %{
title: "Statistics", title: "Statistics",
@ -139,7 +139,7 @@ defmodule PhilomenaWeb.StatsUpdater do
response_time = response_time =
closed_reports closed_reports
|> Enum.reduce(0, &(&2 + NaiveDateTime.diff(&1.updated_at, &1.created_at, :second))) |> Enum.reduce(0, &(&2 + DateTime.diff(&1.updated_at, &1.created_at, :second)))
|> Kernel./(safe_length(closed_reports) * 3600) |> Kernel./(safe_length(closed_reports) * 3600)
|> trunc() |> trunc()

View file

@ -17,7 +17,7 @@
</a> </a>
]]> ]]>
</description> </description>
<pubDate><%= NaiveDateTime.to_iso8601(image.created_at) %></pubDate> <pubDate><%= DateTime.to_iso8601(image.created_at) %></pubDate>
<link><%= Routes.image_url(@conn, :show, image) %></link> <link><%= Routes.image_url(@conn, :show, image) %></link>
<guid><%= Routes.image_url(@conn, :show, image) %></guid> <guid><%= Routes.image_url(@conn, :show, image) %></guid>
</item> </item>

View file

@ -208,7 +208,7 @@ defmodule PhilomenaWeb.UserAuth do
defp signed_in_path(_conn), do: "/" defp signed_in_path(_conn), do: "/"
defp update_usages(conn, user) do defp update_usages(conn, user) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = DateTime.utc_now() |> DateTime.truncate(:second)
conn = fetch_cookies(conn) conn = fetch_cookies(conn)
UserIpUpdater.cast(user.id, conn.remote_ip, now) UserIpUpdater.cast(user.id, conn.remote_ip, now)

View file

@ -31,10 +31,9 @@ defmodule PhilomenaWeb.AppView do
} }
def pretty_time(time) do def pretty_time(time) do
now = NaiveDateTime.utc_now() now = DateTime.utc_now()
seconds = NaiveDateTime.diff(now, time, :second) seconds = DateTime.diff(now, time, :second)
relation = if seconds < 0, do: "from now", else: "ago" relation = if seconds < 0, do: "from now", else: "ago"
time = time |> DateTime.from_naive!("Etc/UTC")
words = distance_of_time_in_words(now, time) words = distance_of_time_in_words(now, time)
@ -45,7 +44,7 @@ defmodule PhilomenaWeb.AppView do
end end
def distance_of_time_in_words(time_2, time_1) do def distance_of_time_in_words(time_2, time_1) do
seconds = abs(NaiveDateTime.diff(time_2, time_1, :second)) seconds = abs(DateTime.diff(time_2, time_1, :second))
minutes = div(seconds, 60) minutes = div(seconds, 60)
hours = div(minutes, 60) hours = div(minutes, 60)
days = div(hours, 24) days = div(hours, 24)

View file

@ -2,6 +2,6 @@ defmodule PhilomenaWeb.BanView do
use PhilomenaWeb, :view use PhilomenaWeb, :view
def active?(ban) do def active?(ban) do
ban.enabled and NaiveDateTime.diff(ban.valid_until, NaiveDateTime.utc_now()) > 0 ban.enabled and DateTime.diff(ban.valid_until, DateTime.utc_now()) > 0
end end
end end

View file

@ -124,8 +124,6 @@ defmodule PhilomenaWeb.ImageView do
end end
def image_container_data(conn, image, size) do def image_container_data(conn, image, size) do
time = DateTime.from_naive!(image.created_at, "Etc/UTC")
[ [
image_id: image.id, image_id: image.id,
image_tags: Jason.encode!(Enum.map(image.tags, & &1.id)), image_tags: Jason.encode!(Enum.map(image.tags, & &1.id)),
@ -137,7 +135,7 @@ defmodule PhilomenaWeb.ImageView do
upvotes: image.upvotes_count, upvotes: image.upvotes_count,
downvotes: image.downvotes_count, downvotes: image.downvotes_count,
comment_count: image.comments_count, comment_count: image.comments_count,
created_at: DateTime.to_iso8601(time), created_at: DateTime.to_iso8601(image.created_at),
source_url: image.source_url, source_url: image.source_url,
uris: Jason.encode!(thumb_urls(image, can?(conn, :show, image))), uris: Jason.encode!(thumb_urls(image, can?(conn, :show, image))),
width: image.image_width, width: image.image_width,

View file

@ -17,8 +17,8 @@ defmodule PhilomenaWeb.Profile.AliasView do
def previously_banned?(_user), do: true def previously_banned?(_user), do: true
defp younger_than_time_offset?(%{created_at: created_at}, time_offset) do defp younger_than_time_offset?(%{created_at: created_at}, time_offset) do
time_ago = NaiveDateTime.utc_now() |> NaiveDateTime.add(-time_offset, :second) time_ago = DateTime.utc_now() |> DateTime.add(-time_offset, :second)
NaiveDateTime.diff(created_at, time_ago) >= 0 DateTime.diff(created_at, time_ago) >= 0
end end
end end