Reduce reliance on Timex and use native time API where feasible#5712
Merged
Reduce reliance on Timex and use native time API where feasible#5712
Timex and use native time API where feasible#5712Conversation
macobo
reviewed
Sep 9, 2025
f4bef41 to
7641eda
Compare
Timex and use native time API where feasible
aerosol
reviewed
Sep 9, 2025
| case report["rows"] do | ||
| [%{"dimensionValues" => [%{"value" => date_str}]}] -> | ||
| Timex.parse!(date_str, "%Y%m%d", :strftime) |> NaiveDateTime.to_date() | ||
| Plausible.Times.parse!(date_str, "%Y%m%d", :strftime) |> NaiveDateTime.to_date() |
91d2301 to
1bed7d1
Compare
1bed7d1 to
d8c3c99
Compare
|
aerosol
approved these changes
Sep 10, 2025
| with %Date{} = from <- Keyword.get(opts, :from), | ||
| %Date{} = to <- Keyword.get(opts, :to), | ||
| true <- abs(Timex.diff(from, to, :months)) > 12 do | ||
| true <- abs(Plausible.Times.diff(from, to, :month)) > 12 do |
Member
There was a problem hiding this comment.
wtf, DateTime.diff has no :month? :(
Contributor
Author
There was a problem hiding this comment.
Yeah, unfortunately day is the highest possible unit when diffing.
RobertJoonas
pushed a commit
that referenced
this pull request
Sep 10, 2025
) * Replace usages of `Timex.to_unix` with native API * Wrap call to `Timex.is_valid_timezone?` * Wrap calls to `Timex.today(tz)` * Replace `Timex.today()` with `Date.utc_today()` * Replace `Timex.now()` with `DateTime.utc_now()` * Replace `Timex.compare` with `Date.compare` * Wrap `Timex.diff` calls * Replace `Timex.Timezone.convert` with `DateTime.shift_zone!` * Wrap `Timex.parse!` * Replace `Timex.to_date` with native API calls * Replace `Timex.beginning|end_of...` with native API calls for Date * Wrap `Timex.beginning|end_of...` for DateTimes and Dates for years * Replace `Timex.format(!)` with native API calls * Replace `Timex.to_naive_datetime` with native API calls * Wrap time humanizing routines using Timex * Remove unnecessary `use Timex` instances * Replace `Timex.shift` with native API calls * Make `QueryParser.parse_date` handle gaps and ambiguities gracefully * Replace `Timex.now(tz)` with `DateTime.now!(tz)` * Use a more suitable Date function for comparison (h/t @aerosol)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Changes
This PR replaces uses of
Timexwith native date and time APIs and moves all the remainingTimexreferences behindPlausible.TimesandPlausible.Timezones. All cases where either:gapor:ambiguoustime computation result can occur are handled gracefully (the wrappedTimexend_ofandbeginning_offunctions handle that internally already).TODO
TimesandTimezonesto see if tests cover them at leastTests