Skip to content

Commit

Permalink
Feature/1866 sorting time (#190)
Browse files Browse the repository at this point in the history
* sort assignments in overviews against name

* sort locations on index page

* use local formatted timestamp in logs
  • Loading branch information
mabiede authored Aug 10, 2023
1 parent 364318e commit 0be0353
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
3 changes: 3 additions & 0 deletions pool/app/assignment/repo/repo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ module Sql = struct
~default:id_fragment
(Format.asprintf "%s AND %s" id_fragment)
|> select_sql
~joins:
{sql|JOIN user_users ON pool_assignments.contact_uuid = user_users.uuid|sql}
|> Format.asprintf "%s\n ORDER BY user_users.name, user_users.given_name"
|> Caqti_type.string ->* RepoEntity.t
;;

Expand Down
4 changes: 3 additions & 1 deletion pool/app/logger/logger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ let pp_exec_header tags src =
let user = tags >>= Logs.Tag.find tag_user |> value in
let database_label = tags >>= Logs.Tag.find tag_database |> value in
let src = Logs.Src.name src in
let now = Ptime_clock.now () |> Ptime.to_rfc3339 in
let now =
Ptime_clock.now () |> Utils.Ptime.formatted_date_time_with_seconds
in
Fmt.pf
ppf
"%s [%a][%a][%a][%a][%a]: "
Expand Down
2 changes: 1 addition & 1 deletion pool/app/pool_common/pool_common.mli
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ module Utils : sig
val ptime_to_sexp : Ptime.t -> Sexplib0.Sexp.t
val formatted_date_time : Ptime.t -> string
val formatted_date : Ptime.t -> string
val formatted_time : Ptime.t -> string
val formatted_time : ?with_seconds:bool -> Ptime.t -> string
val formatted_timespan : Ptime.span -> string
val timespan_to_minutes : Ptime.span -> string
val parse_time : string -> (Ptime.t, Message.error) result
Expand Down
4 changes: 3 additions & 1 deletion pool/app/pool_location/repo/repo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ module Sql = struct

let find_all_request =
let open Caqti_request.Infix in
"" |> Format.asprintf "%s\n%s" select_sql |> Caqti_type.unit ->* t
{sql|ORDER BY pool_locations.name|sql}
|> Format.asprintf "%s\n%s" select_sql
|> Caqti_type.unit ->* t
;;

let find_all pool =
Expand Down
32 changes: 19 additions & 13 deletions pool/app/utils/utils_ptime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ let date_to_human date =
Format.asprintf "%s.%s.%d" (decimal day) (decimal month) year
;;

let time_to_human time =
let _, ((h, m, _), _) = time in
Format.asprintf "%s:%s" (decimal h) (decimal m)
let time_to_human ?(with_seconds = false) time =
let _, ((h, m, s), _) = time in
let seconds =
if with_seconds then Format.asprintf ":%s" (decimal s) else ""
in
Format.asprintf "%s:%s%s" (decimal h) (decimal m) seconds
;;

(* Public functions *)
Expand All @@ -28,20 +31,23 @@ let to_local_date date =
|> CCOption.get_exn_or "Invalid ptime provided"
;;

let formatted_date_time (date : Ptime.t) =
let date = date |> to_local_date in
Format.asprintf
"%s %s"
(date_to_human (Ptime.to_date date))
(time_to_human (Ptime.to_date_time date))
;;

let formatted_date ptime =
ptime |> to_local_date |> Ptime.to_date |> date_to_human
;;

let formatted_time ptime =
ptime |> to_local_date |> Ptime.to_date_time |> time_to_human
let formatted_time ?with_seconds ptime =
ptime |> to_local_date |> Ptime.to_date_time |> time_to_human ?with_seconds
;;

let formatted_date_time (date : Ptime.t) =
Format.asprintf "%s %s" (formatted_date date) (formatted_time date)
;;

let formatted_date_time_with_seconds (date : Ptime.t) =
Format.asprintf
"%s %s"
(formatted_date date)
(formatted_time ~with_seconds:true date)
;;

let formatted_timespan timespan =
Expand Down

0 comments on commit 0be0353

Please sign in to comment.