-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
filter: add new time_delta filter #9831
base: main
Are you sure you want to change the base?
Conversation
9700872
to
7b5c05f
Compare
This comment was marked as outdated.
This comment was marked as outdated.
nice |
* Calculate datetime string based upon time delta provided by user Signed-off-by: Abhijeet Kasurde <[email protected]>
Whilst I appreciate the idea very much, the name Additionally, I think forcing this to use string representation is limiting. We can have datetime objects and time delta objects, as shown in: Therefore, I reckon it would be interesting to:
I mean those in addition to the current code, which is clearly quite useful. WDYT? |
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.
Thanks for your contribution! I agree with @russoz that the name should be adjusted; I was thinking as well that this filter allows to compute the difference between two timestamps, and not to modify a timestamp.
raise AnsibleFilterError('time_delta accepts datetime in string format') | ||
date_format = "%Y-%m-%d %H:%M:%S" | ||
if 'date_format' in kwargs: | ||
date_format = kwargs.get('date_format') |
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.
I think this should be validated to be a string.
'minutes': kwargs.get('minutes', 0), | ||
'hours': kwargs.get('hours', 0), | ||
'weeks': kwargs.get('weeks', 0), | ||
} |
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 would be good to validate the above to be integers if supplied as options. Also you should check whether kwargs
has more arguments than the ones we use (and fail if there are more).
f'Failed to parse provided string into datetime format "{date_format}" provided.' | ||
) | ||
|
||
return str(source_date + timedelta(**delta)) |
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.
Shouldn't date_format
be used to format the timestamp?
SUMMARY
provided by user
Signed-off-by: Abhijeet Kasurde [email protected]
ISSUE TYPE