-
Notifications
You must be signed in to change notification settings - Fork 64
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
base: master
Are you sure you want to change the base?
feat: allow decimal places for seconds setting in NOW replacement #416
Conversation
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') |
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.
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
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.
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.
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.
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') |
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.
este método está deprecado hace tiempo en python, la recomendación es usar
.now(datetime.timezone.utc)
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.
Í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.
The NOW replacement with format is extended to allow setting the number of decimal places to be used when using
%f
. E.g.: