Skip to content
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

Adds filters for datetime functions. #258

Merged
merged 8 commits into from
Dec 10, 2018
Merged

Adds filters for datetime functions. #258

merged 8 commits into from
Dec 10, 2018

Conversation

mattcoley
Copy link
Collaborator

@mattcoley mattcoley commented Nov 27, 2018

Adds plus_time, minus_time, and between_times filters to operate on datetime objects/timestamp. Examples: date|plus_time('1', 'days') will give you a date 1 day in the future; begin|between_times(end, 'minutes') will give you the number of minutes between those two dates.

I also added a strtotime to convert a string and datetime format to a datetime object. For example, "2018-07-14T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp will output 1531558890000

Fixes #56

@codecov-io
Copy link

codecov-io commented Nov 27, 2018

Codecov Report

Merging #258 into master will increase coverage by 0.06%.
The diff coverage is 72.83%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #258      +/-   ##
============================================
+ Coverage     71.89%   71.95%   +0.06%     
- Complexity     1408     1437      +29     
============================================
  Files           221      226       +5     
  Lines          4433     4514      +81     
  Branches        705      717      +12     
============================================
+ Hits           3187     3248      +61     
- Misses         1004     1014      +10     
- Partials        242      252      +10
Impacted Files Coverage Δ Complexity Δ
.../com/hubspot/jinjava/lib/filter/FilterLibrary.java 100% <ø> (ø) 4 <0> (ø) ⬇️
...va/com/hubspot/jinjava/lib/fn/FunctionLibrary.java 81.25% <100%> (+1.25%) 2 <0> (ø) ⬇️
...hubspot/jinjava/lib/filter/BetweenTimesFilter.java 62.5% <62.5%> (ø) 5 <5> (?)
...om/hubspot/jinjava/lib/filter/MinusTimeFilter.java 66.66% <66.66%> (ø) 4 <4> (?)
...hubspot/jinjava/lib/filter/StringToTimeFilter.java 71.42% <71.42%> (ø) 4 <4> (?)
...ain/java/com/hubspot/jinjava/lib/fn/Functions.java 84.55% <77.77%> (+1.21%) 36 <2> (+3) ⬆️
...com/hubspot/jinjava/lib/filter/BaseDateFilter.java 77.77% <77.77%> (ø) 8 <8> (?)
...com/hubspot/jinjava/lib/filter/PlusTimeFilter.java 80% <80%> (ø) 5 <5> (?)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a96efc...7c8ac35. Read the comment docs.

@boulter
Copy link
Contributor

boulter commented Nov 27, 2018

Do these have any precedent in Jinja? I would prefer to keep it as compatible as possible. If not, perhaps these could filters could be named with a little more descriptively like plus_time, minus_time and between_times.

@mattcoley
Copy link
Collaborator Author

The recommended way in jinja is with python commands. We could encourage developers to use Java methods like plusDays() but those seem like the only options.

@mattcoley mattcoley requested a review from boulter November 28, 2018 20:13
Copy link
Contributor

@boulter boulter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Can you document the temporal unit values in each filter's docs?

@mattcoley
Copy link
Collaborator Author

I changed this to support all ChronoUnit enum values and added a link at the top of each class.

@mattcoley mattcoley merged commit 1abcc1b into master Dec 10, 2018
@mattcoley mattcoley deleted the date-filters branch December 10, 2018 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants