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: allow decimal places for seconds setting in NOW replacement #416

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pabloge
Copy link
Member

@pabloge pabloge commented Feb 28, 2025

The NOW replacement with format is extended to allow setting the number of decimal places to be used when using %f. E.g.:

Tag Transformation result
[NOW(%Y-%m-%dT%H:%M:%S.%fZ)] 2025-02-27T17:09:51.986024Z
[NOW(%Y-%m-%dT%H:%M:%S.%3fZ)] 2025-02-27T17:09:51.986Z
[NOW(%Y-%m-%dT%H:%M:%S.%12fZ)] 2025-02-27T17:09:51.986024000000Z

@pabloge pabloge requested a review from a team February 28, 2025 09:41
def test_replace_param_now_with_format_and_decimals_limit():
param = replace_param('[NOW(%Y-%m-%dT%H:%M:%S.%3fZ)]')
param_till_dot = param[:param.find('.')]
assert param_till_dot == datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')
Copy link
Contributor

Choose a reason for hiding this comment

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

estos tests funcionan siempre (la pregunta aplica a todos, incluidos los anteriores)? el now del replace param y esta llamada pueden caer en un segundo distinto y fallará el test no?
creo que sería mejor mockear datetime.datetime.utcnow

Copy link
Member Author

Choose a reason for hiding this comment

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

Sí, lo pensé cuando los metí, pero he visto que tardan del orden de microsegundos en ejecutarse y en la práctica no fallan nunca.

Con todo, si quieres, se puede meter lo que dices, pero casi preferiría que fuera en otra PR y aquí seguir una aproximación más continuista para no meter más cambios.

Copy link
Member Author

Choose a reason for hiding this comment

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

Como curiosidad, los que sí fallaban siempre entre las 00:00 y la 01:00 o entre las 00:00 y las 02:00 (según la época del año) cuando se ejecutaban en una máquina con hora española, eran los que usaban today(), porque tiene en cuenta la zona horaria, mientras nuestros replacements usan UTC.

No preguntéis cómo me di cuenta 😆



def test_replace_param_today_offset():
param = replace_param('[TODAY - 1 DAYS]', language='es')
assert param == datetime.datetime.strftime(
datetime.datetime.today() - datetime.timedelta(days=1), '%d/%m/%Y')
datetime.datetime.utcnow() - datetime.timedelta(days=1), '%d/%m/%Y')
Copy link
Contributor

Choose a reason for hiding this comment

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

este método está deprecado hace tiempo en python, la recomendación es usar
.now(datetime.timezone.utc)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ídem, también me fijé y también lo vi como un cambio que se podría hacer de manera generalizada en otra PR si queremos seguir la recomendación.

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