feat: Add current date in UTC to PromptBuilder
Related Issues
- fixes #issue-number
Proposed Changes:
Feature: Added a utc_now function in the PromptBuilder so the current date can be displayed inside the Template.
This function returns the current date and time in UTC format as a string. The default format is %Y-%m-%d %H:%M:%S.%f, but users can specify their own format as long as it's ISO compatible. The function has also been added as a global in the Jinja2 environment, so it can be accessed directly from the template. Input validation has been implemented to ensure that the date format is valid.
How did you test it?
Added unit tests to ensure the utc_now function returns correct UTC timestamps in various formats and handles invalid date formats.
Checklist
- I have read the contributors guidelines and the code of conduct
- I have updated the related issue with new insights and changes
- I added unit tests and updated the docstrings
- I've used one of the conventional commit types for my PR title:
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:. - I documented my code
- I ran pre-commit hooks and fixed any issue
Pull Request Test Coverage Report for Build 10766224472
Details
- 0 of 0 changed or added relevant lines in 0 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage increased (+0.04%) to 90.3%
| Totals | |
|---|---|
| Change from base Build 10737503702: | 0.04% |
| Covered Lines: | 7084 |
| Relevant Lines: | 7845 |
💛 - Coveralls
Looks good to me but can we maybe use a syntax similar to what this extension does? I think it's more versatile and will make it easier to add functionalities in the future.
Hey @silvanocerza I think that sounds like a good idea! Unfortunately, that's a bit more involved and @medsriha and I wouldn't have time to implement that right now. Would it be better to close this PR and open a new issue?
Looks good to me but can we maybe use a syntax similar to what this extension does? I think it's more versatile and will make it easier to add functionalities in the future.
This version uses the same syntax as in this extension by leveraging arrow. The default date format is %Y-%m-%d %H:%M:%S. For example, you can use {% now 'UTC' %} to display the current date in UTC. Use {% now 'UTC' + 'hours=2' %} to add 2 hours to the current date, or {% now 'UTC' + 'hours=2', '%H' %} to display the number of hours after adding 2 hours to the current date.
I'll update the release note if this looks good to @silvanocerza and @sjrl. Also, this will probably require adding documentation to educate on the syntax.