-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Pgx_value_ptime with ptime converters #114
Conversation
This is failing in Circle with the error:
I'm not sure why this is, opam seems to show Ptime 0.8.5 as available. |
I wonder if our build script is missing an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks great, thanks!
Let me try to figure out what's going on with CircleCI..
let to_time' text = | ||
(* | ||
The time string can come in various forms depending on whether the | ||
Postgres timestamp used includes the time zone: | ||
|
||
Without timezone | ||
2016-06-07 15:37:46 | ||
2016-06-07 15:37:46.962425 | ||
|
||
With timezone | ||
2016-06-07 15:37:46-04 | ||
2016-06-07 15:37:46.962425-04 | ||
|
||
For the first one we need to indicate that it's a UTC time by appending | ||
a 'Z'. For the second one we need to append the minutes to the timezone. | ||
*) | ||
let open Re in | ||
let tz = seq [ alt [ char '-'; char '+' ]; digit; digit ] in | ||
let utctz = seq [ char 'Z'; eol ] |> compile in | ||
let localtz = seq [ tz; char ':'; digit; digit; eol ] |> compile in | ||
let localtz_no_min = seq [ tz; eol ] |> compile in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth pre-compiling the regexes as globals so we don't have to recompile them on each call. I'm not sure how slow that is in OCaml though so maybe it doesn't matter either way?
let to_time' text = | |
(* | |
The time string can come in various forms depending on whether the | |
Postgres timestamp used includes the time zone: | |
Without timezone | |
2016-06-07 15:37:46 | |
2016-06-07 15:37:46.962425 | |
With timezone | |
2016-06-07 15:37:46-04 | |
2016-06-07 15:37:46.962425-04 | |
For the first one we need to indicate that it's a UTC time by appending | |
a 'Z'. For the second one we need to append the minutes to the timezone. | |
*) | |
let open Re in | |
let tz = seq [ alt [ char '-'; char '+' ]; digit; digit ] in | |
let utctz = seq [ char 'Z'; eol ] |> compile in | |
let localtz = seq [ tz; char ':'; digit; digit; eol ] |> compile in | |
let localtz_no_min = seq [ tz; eol ] |> compile in | |
let to_time' = | |
(* | |
The time string can come in various forms depending on whether the | |
Postgres timestamp used includes the time zone: | |
Without timezone | |
2016-06-07 15:37:46 | |
2016-06-07 15:37:46.962425 | |
With timezone | |
2016-06-07 15:37:46-04 | |
2016-06-07 15:37:46.962425-04 | |
For the first one we need to indicate that it's a UTC time by appending | |
a 'Z'. For the second one we need to append the minutes to the timezone. | |
*) | |
let open Re in | |
let tz = seq [ alt [ char '-'; char '+' ]; digit; digit ] in | |
let utctz = seq [ char 'Z'; eol ] |> compile in | |
let localtz = seq [ tz; char ':'; digit; digit; eol ] |> compile in | |
let localtz_no_min = seq [ tz; eol ] |> compile in | |
fun text -> |
Looks like we needed |
Oops, thanks for figuring that out; I should've looked more closely and noticed the missing |
No worries :) |
Oh I just noticed your comment asked for feedback on the code. I think it looked pretty good to me. One part I'm wondering about is if we could avoid the regexes somehow by using functions built into ptime, but I took a quick look and didn't see any. We might want to consider some performance optimizations around it, like pre-compiling the regexes or trying the regexes in sequence instead of in parallel (so we won't need to run all of them in most cases), but we can do improvements to the internals like that in separate commits if/when the performance matters. Overall, I thought the PR looked great. |
Thanks for reviewing! This was a nice issue for learning more about how to use |
This change addresses issue arenadotio#97 by introducing a new package called Pgx_value_ptime. This package is analogous to Pgx_value_core, but uses Ptime for date/date-time processing instead of Core. The tests for Pgx_value_ptime are pretty much the same as those for Pgx_value_core, although I did add some extra tests for dates.
This change addresses Issue #97 by introducing a new package called
Pgx_value_ptime
. This package is analogous toPgx_value_core
, but uses Ptime for date/date-time processing instead ofCore
.The tests for
Pgx_value_ptime
are pretty much the same as those forPgx_value_core
, although I did add some extra tests for dates.As I mentioned in the issue, I'm new to both this code base and OCaml in general, so please let me know if any of the code here isn't idiomatic and/or doesn't solve the problem the way you had in mind.