improve accuracy of timestamps
This commit is contained in:
parent
7096e6abeb
commit
da717013de
@ -1,3 +1,6 @@
|
||||
# v0.1.20
|
||||
- Improve accuracy of timestamps
|
||||
|
||||
# v0.1.19
|
||||
- Add backlinks
|
||||
- Fix visibility issues with multiple users
|
||||
|
@ -28,9 +28,10 @@ config :memex, MemexWeb.Endpoint,
|
||||
config :memex, Memex.Application, automigrate: false
|
||||
|
||||
config :memex, :generators,
|
||||
migration: true,
|
||||
binary_id: true,
|
||||
sample_binary_id: "11111111-1111-1111-1111-111111111111"
|
||||
migration: true,
|
||||
sample_binary_id: "11111111-1111-1111-1111-111111111111",
|
||||
timestamp_type: :utc_datetime_usec
|
||||
|
||||
# Configures the mailer
|
||||
#
|
||||
|
@ -11,13 +11,13 @@ defmodule Memex.Accounts.Invite do
|
||||
field :name, :string
|
||||
field :token, :string
|
||||
field :uses_left, :integer, default: nil
|
||||
field :disabled_at, :naive_datetime
|
||||
field :disabled_at, :utc_datetime_usec
|
||||
|
||||
belongs_to :created_by, User
|
||||
|
||||
has_many :users, User
|
||||
|
||||
timestamps()
|
||||
timestamps(type: :utc_datetime_usec)
|
||||
end
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
@ -25,12 +25,12 @@ defmodule Memex.Accounts.Invite do
|
||||
name: String.t(),
|
||||
token: token(),
|
||||
uses_left: integer() | nil,
|
||||
disabled_at: NaiveDateTime.t(),
|
||||
disabled_at: DateTime.t(),
|
||||
created_by: User.t() | nil | Association.NotLoaded.t(),
|
||||
created_by_id: User.id() | nil,
|
||||
users: [User.t()] | Association.NotLoaded.t(),
|
||||
inserted_at: NaiveDateTime.t(),
|
||||
updated_at: NaiveDateTime.t()
|
||||
inserted_at: DateTime.t(),
|
||||
updated_at: DateTime.t()
|
||||
}
|
||||
@type new_invite :: %__MODULE__{}
|
||||
@type id :: UUID.t()
|
||||
|
@ -123,7 +123,7 @@ defmodule Memex.Accounts.Invites do
|
||||
end
|
||||
|
||||
defp decrement_invite_changeset(%Invite{uses_left: 1} = invite) do
|
||||
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
now = DateTime.utc_now()
|
||||
invite |> Invite.update_changeset(%{uses_left: 0, disabled_at: now})
|
||||
end
|
||||
|
||||
|
@ -21,7 +21,7 @@ defmodule Memex.Accounts.User do
|
||||
field :email, :string
|
||||
field :password, :string, virtual: true
|
||||
field :hashed_password, :string
|
||||
field :confirmed_at, :naive_datetime
|
||||
field :confirmed_at, :utc_datetime_usec
|
||||
field :role, Ecto.Enum, values: [:admin, :user], default: :user
|
||||
field :locale, :string
|
||||
|
||||
@ -29,7 +29,7 @@ defmodule Memex.Accounts.User do
|
||||
|
||||
belongs_to :invite, Invite
|
||||
|
||||
timestamps()
|
||||
timestamps(type: :utc_datetime_usec)
|
||||
end
|
||||
|
||||
@type t :: %User{
|
||||
@ -37,14 +37,14 @@ defmodule Memex.Accounts.User do
|
||||
email: String.t(),
|
||||
password: String.t(),
|
||||
hashed_password: String.t(),
|
||||
confirmed_at: NaiveDateTime.t(),
|
||||
confirmed_at: DateTime.t(),
|
||||
role: role(),
|
||||
locale: String.t() | nil,
|
||||
created_invites: [Invite.t()] | Association.NotLoaded.t(),
|
||||
invite: Invite.t() | nil | Association.NotLoaded.t(),
|
||||
invite_id: Invite.id() | nil,
|
||||
inserted_at: NaiveDateTime.t(),
|
||||
updated_at: NaiveDateTime.t()
|
||||
inserted_at: DateTime.t(),
|
||||
updated_at: DateTime.t()
|
||||
}
|
||||
@type new_user :: %User{}
|
||||
@type id :: UUID.t()
|
||||
@ -166,7 +166,7 @@ defmodule Memex.Accounts.User do
|
||||
"""
|
||||
@spec confirm_changeset(t() | changeset()) :: changeset()
|
||||
def confirm_changeset(user_or_changeset) do
|
||||
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
now = DateTime.utc_now()
|
||||
user_or_changeset |> change(confirmed_at: now)
|
||||
end
|
||||
|
||||
|
@ -32,7 +32,7 @@ defmodule Memex.Accounts.UserToken do
|
||||
sent_to: String.t(),
|
||||
user: User.t() | Association.NotLoaded.t(),
|
||||
user_id: User.id() | nil,
|
||||
inserted_at: NaiveDateTime.t()
|
||||
inserted_at: DateTime.t()
|
||||
}
|
||||
@type new_user_token :: %__MODULE__{}
|
||||
@type id :: UUID.t()
|
||||
|
@ -25,7 +25,7 @@ defmodule Memex.Contexts.Context do
|
||||
|
||||
field :user_id, :binary_id
|
||||
|
||||
timestamps()
|
||||
timestamps(type: :utc_datetime_usec)
|
||||
end
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
@ -35,8 +35,8 @@ defmodule Memex.Contexts.Context do
|
||||
tags_string: String.t() | nil,
|
||||
visibility: :public | :private | :unlisted,
|
||||
user_id: User.id(),
|
||||
inserted_at: NaiveDateTime.t(),
|
||||
updated_at: NaiveDateTime.t()
|
||||
inserted_at: DateTime.t(),
|
||||
updated_at: DateTime.t()
|
||||
}
|
||||
@type id :: UUID.t()
|
||||
@type slug :: String.t()
|
||||
|
@ -24,7 +24,7 @@ defmodule Memex.Notes.Note do
|
||||
|
||||
field :user_id, :binary_id
|
||||
|
||||
timestamps()
|
||||
timestamps(type: :utc_datetime_usec)
|
||||
end
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
@ -34,8 +34,8 @@ defmodule Memex.Notes.Note do
|
||||
tags_string: String.t() | nil,
|
||||
visibility: :public | :private | :unlisted,
|
||||
user_id: User.id(),
|
||||
inserted_at: NaiveDateTime.t(),
|
||||
updated_at: NaiveDateTime.t()
|
||||
inserted_at: DateTime.t(),
|
||||
updated_at: DateTime.t()
|
||||
}
|
||||
@type id :: UUID.t()
|
||||
@type slug :: String.t()
|
||||
|
@ -28,7 +28,7 @@ defmodule Memex.Pipelines.Pipeline do
|
||||
|
||||
has_many :steps, Step, preload_order: [asc: :position]
|
||||
|
||||
timestamps()
|
||||
timestamps(type: :utc_datetime_usec)
|
||||
end
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
@ -38,8 +38,8 @@ defmodule Memex.Pipelines.Pipeline do
|
||||
tags_string: String.t() | nil,
|
||||
visibility: :public | :private | :unlisted,
|
||||
user_id: User.id(),
|
||||
inserted_at: NaiveDateTime.t(),
|
||||
updated_at: NaiveDateTime.t()
|
||||
inserted_at: DateTime.t(),
|
||||
updated_at: DateTime.t()
|
||||
}
|
||||
@type id :: UUID.t()
|
||||
@type slug :: String.t()
|
||||
|
@ -22,7 +22,7 @@ defmodule Memex.Pipelines.Steps.Step do
|
||||
belongs_to :pipeline, Pipeline
|
||||
field :user_id, :binary_id
|
||||
|
||||
timestamps()
|
||||
timestamps(type: :utc_datetime_usec)
|
||||
end
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
@ -32,8 +32,8 @@ defmodule Memex.Pipelines.Steps.Step do
|
||||
pipeline: Pipeline.t() | Ecto.Association.NotLoaded.t(),
|
||||
pipeline_id: Pipeline.id(),
|
||||
user_id: User.id(),
|
||||
inserted_at: NaiveDateTime.t(),
|
||||
updated_at: NaiveDateTime.t()
|
||||
inserted_at: DateTime.t(),
|
||||
updated_at: DateTime.t()
|
||||
}
|
||||
@type id :: UUID.t()
|
||||
@type changeset :: Changeset.t(t())
|
||||
|
@ -89,14 +89,14 @@ defmodule MemexWeb.CoreComponents do
|
||||
attr :datetime, :any, required: true, doc: "A `DateTime` struct or nil"
|
||||
|
||||
@doc """
|
||||
Phoenix.Component for a <time> element that renders the naivedatetime in the
|
||||
Phoenix.Component for a <time> element that renders the DateTime in the
|
||||
user's local timezone
|
||||
"""
|
||||
def datetime(assigns)
|
||||
|
||||
@spec cast_datetime(NaiveDateTime.t() | nil) :: String.t()
|
||||
defp cast_datetime(%NaiveDateTime{} = datetime) do
|
||||
datetime |> DateTime.from_naive!("Etc/UTC") |> DateTime.to_iso8601(:extended)
|
||||
@spec cast_datetime(DateTime.t() | nil) :: String.t()
|
||||
defp cast_datetime(%DateTime{} = datetime) do
|
||||
datetime |> DateTime.to_iso8601(:extended)
|
||||
end
|
||||
|
||||
defp cast_datetime(_datetime), do: ""
|
||||
|
@ -93,7 +93,7 @@ defmodule MemexWeb.InviteLive.Index do
|
||||
%{"id" => id},
|
||||
%{assigns: %{current_user: current_user}} = socket
|
||||
) do
|
||||
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
now = DateTime.utc_now()
|
||||
|
||||
socket =
|
||||
Invites.get_invite!(id, current_user)
|
||||
|
41
priv/repo/migrations/20250405012314_set_utc_datetime.exs
Normal file
41
priv/repo/migrations/20250405012314_set_utc_datetime.exs
Normal file
@ -0,0 +1,41 @@
|
||||
defmodule Memex.Repo.Migrations.SetUtcDatetime do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:users) do
|
||||
modify :confirmed_at, :utc_datetime_usec, from: :naive_datetime
|
||||
modify :inserted_at, :utc_datetime_usec, from: :naive_datetime
|
||||
modify :updated_at, :utc_datetime_usec, from: :naive_datetime
|
||||
end
|
||||
|
||||
alter table(:users_tokens) do
|
||||
modify :inserted_at, :utc_datetime_usec, from: :naive_datetime
|
||||
end
|
||||
|
||||
alter table(:invites) do
|
||||
modify :disabled_at, :utc_datetime_usec, from: :naive_datetime
|
||||
modify :inserted_at, :utc_datetime_usec, from: :naive_datetime
|
||||
modify :updated_at, :utc_datetime_usec, from: :naive_datetime
|
||||
end
|
||||
|
||||
alter table(:contexts) do
|
||||
modify :inserted_at, :utc_datetime_usec, from: :naive_datetime
|
||||
modify :updated_at, :utc_datetime_usec, from: :naive_datetime
|
||||
end
|
||||
|
||||
alter table(:notes) do
|
||||
modify :inserted_at, :utc_datetime_usec, from: :naive_datetime
|
||||
modify :updated_at, :utc_datetime_usec, from: :naive_datetime
|
||||
end
|
||||
|
||||
alter table(:pipelines) do
|
||||
modify :inserted_at, :utc_datetime_usec, from: :naive_datetime
|
||||
modify :updated_at, :utc_datetime_usec, from: :naive_datetime
|
||||
end
|
||||
|
||||
alter table(:steps) do
|
||||
modify :inserted_at, :utc_datetime_usec, from: :naive_datetime
|
||||
modify :updated_at, :utc_datetime_usec, from: :naive_datetime
|
||||
end
|
||||
end
|
||||
end
|
@ -42,8 +42,8 @@ defmodule MemexWeb.ExportControllerTest do
|
||||
"content" => note.content,
|
||||
"tags" => note.tags,
|
||||
"visibility" => note.visibility |> to_string(),
|
||||
"inserted_at" => note.inserted_at |> NaiveDateTime.to_iso8601(),
|
||||
"updated_at" => note.updated_at |> NaiveDateTime.to_iso8601()
|
||||
"inserted_at" => note.inserted_at |> DateTime.to_iso8601(),
|
||||
"updated_at" => note.updated_at |> DateTime.to_iso8601()
|
||||
}
|
||||
|
||||
ideal_context = %{
|
||||
@ -51,8 +51,8 @@ defmodule MemexWeb.ExportControllerTest do
|
||||
"content" => context.content,
|
||||
"tags" => context.tags,
|
||||
"visibility" => context.visibility |> to_string(),
|
||||
"inserted_at" => context.inserted_at |> NaiveDateTime.to_iso8601(),
|
||||
"updated_at" => context.updated_at |> NaiveDateTime.to_iso8601()
|
||||
"inserted_at" => context.inserted_at |> DateTime.to_iso8601(),
|
||||
"updated_at" => context.updated_at |> DateTime.to_iso8601()
|
||||
}
|
||||
|
||||
ideal_pipeline = %{
|
||||
@ -60,15 +60,15 @@ defmodule MemexWeb.ExportControllerTest do
|
||||
"description" => pipeline.description,
|
||||
"tags" => pipeline.tags,
|
||||
"visibility" => pipeline.visibility |> to_string(),
|
||||
"inserted_at" => pipeline.inserted_at |> NaiveDateTime.to_iso8601(),
|
||||
"updated_at" => pipeline.updated_at |> NaiveDateTime.to_iso8601(),
|
||||
"inserted_at" => pipeline.inserted_at |> DateTime.to_iso8601(),
|
||||
"updated_at" => pipeline.updated_at |> DateTime.to_iso8601(),
|
||||
"steps" => [
|
||||
%{
|
||||
"title" => step.title,
|
||||
"content" => step.content,
|
||||
"position" => step.position,
|
||||
"inserted_at" => step.inserted_at |> NaiveDateTime.to_iso8601(),
|
||||
"updated_at" => step.updated_at |> NaiveDateTime.to_iso8601()
|
||||
"inserted_at" => step.inserted_at |> DateTime.to_iso8601(),
|
||||
"updated_at" => step.updated_at |> DateTime.to_iso8601()
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -80,8 +80,8 @@ defmodule MemexWeb.ExportControllerTest do
|
||||
"id" => current_user.id,
|
||||
"locale" => current_user.locale,
|
||||
"role" => to_string(current_user.role),
|
||||
"inserted_at" => current_user.inserted_at |> NaiveDateTime.to_iso8601(),
|
||||
"updated_at" => current_user.updated_at |> NaiveDateTime.to_iso8601()
|
||||
"inserted_at" => current_user.inserted_at |> DateTime.to_iso8601(),
|
||||
"updated_at" => current_user.updated_at |> DateTime.to_iso8601()
|
||||
}
|
||||
|
||||
json_resp = conn |> json_response(200)
|
||||
|
Loading…
x
Reference in New Issue
Block a user