mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
fix datetime parsing
This commit is contained in:
parent
9b87f9a07a
commit
8b79f5808f
4 changed files with 7 additions and 7 deletions
|
@ -5,7 +5,7 @@ defmodule PhilomenaWeb.CommentController do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
def index(conn, params) do
|
def index(conn, params) do
|
||||||
cq = params["cq"] || "created_at.gt:1 week ago"
|
cq = params["cq"] || "created_at.gte:1 week ago"
|
||||||
|
|
||||||
{:ok, query} = Query.compile(conn.assigns.current_user, cq)
|
{:ok, query} = Query.compile(conn.assigns.current_user, cq)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ h1 Comments
|
||||||
|
|
||||||
= form_for :comments, Routes.comment_path(@conn, :index), [method: "get", class: "hform", enforce_utf8: false], fn f ->
|
= form_for :comments, Routes.comment_path(@conn, :index), [method: "get", class: "hform", enforce_utf8: false], fn f ->
|
||||||
.field
|
.field
|
||||||
= text_input f, :cq, name: :cq, value: @conn.params["cq"] || "created_at.gt:1 week ago", class: "input hform__text", placeholder: "Search comments", autocapitalize: "none"
|
= text_input f, :cq, name: :cq, value: @conn.params["cq"] || "created_at.gte:1 week ago", class: "input hform__text", placeholder: "Search comments", autocapitalize: "none"
|
||||||
= submit "Search", class: "hform__button button", data: [disable_with: false]
|
= submit "Search", class: "hform__button button", data: [disable_with: false]
|
||||||
|
|
||||||
.fieldlabel
|
.fieldlabel
|
||||||
|
|
|
@ -91,10 +91,10 @@ defmodule Search.DateParser do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp relative_datetime([count, scale]) do
|
defp relative_datetime([count, scale]) do
|
||||||
now = NaiveDateTime.utc_now()
|
now = DateTime.utc_now()
|
||||||
|
|
||||||
lower = NaiveDateTime.add(now, count * -scale, :second)
|
lower = DateTime.add(now, count * -scale, :second)
|
||||||
upper = NaiveDateTime.add(now, (count - 1) * -scale, :second)
|
upper = DateTime.add(now, (count - 1) * -scale, :second)
|
||||||
|
|
||||||
[lower, upper]
|
[lower, upper]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue