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

feat: Add current date in UTC to PromptBuilder #8233

Merged
merged 16 commits into from
Sep 9, 2024
Merged

Conversation

medsriha
Copy link
Member

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

@medsriha medsriha requested review from a team as code owners August 15, 2024 00:23
@medsriha medsriha requested review from dfokina and silvanocerza and removed request for a team August 15, 2024 00:23
@github-actions github-actions bot added topic:tests type:documentation Improvements on the docs labels Aug 15, 2024
@coveralls
Copy link
Collaborator

coveralls commented Aug 15, 2024

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 Coverage Status
Change from base Build 10737503702: 0.04%
Covered Lines: 7084
Relevant Lines: 7845

💛 - Coveralls

@shadeMe shadeMe enabled auto-merge (squash) August 21, 2024 09:28
@silvanocerza
Copy link
Contributor

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.

@sjrl
Copy link
Contributor

sjrl commented Sep 6, 2024

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?

@medsriha
Copy link
Member Author

medsriha commented Sep 6, 2024

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.

@medsriha medsriha requested a review from sjrl September 6, 2024 16:31
Comment on lines +80 to +81
# Default Add when no operator is provided
operator = "+" if isinstance(node, nodes.Add) else "-"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this read "# Default Minus when ..." since the else statement is "-"?

Copy link
Contributor

@sjrl sjrl left a comment

Choose a reason for hiding this comment

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

@medsriha thanks for the work on this! This looks good to me. What do you think @silvanocerza ?

@shadeMe shadeMe merged commit 7595592 into main Sep 9, 2024
19 checks passed
@shadeMe shadeMe deleted the current_date_template branch September 9, 2024 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants