Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
4915 Переглядів

Hi everyone,

I'm trying to separate overtime and contract hours in the attendance module, but it seems that dates are saved in UTC in the database. Is it possible to use pytz to convert datetimes to the user timezone?


When trying:

for rec in records:
  context_tz = pytz.timezone(rec.env.user.tz)
  log(rec.check_in.astimezone(context_tz).strftime('%A, %y-%m-%d %H-%M'), level='info')
log(rec.env.user.tz, level='info')

I get:

ValueError: <class 'NameError'>: "name 'pytz' is not defined" while evaluating


And if I try to "import pytz", I get:

Any idea on how to approach this?


Thanks!

Аватар
Відмінити
Найкраща відповідь

Hi Emilio:

You cannot import python modules directly in an automated action. The only way to do it, is to write a custom module and call the custom function from the automated action.

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
Take Users Timezone Вирішено
3
лип. 25
3734
0
лип. 21
4338
Time & Date Issue Вирішено
6
вер. 19
11015
2
бер. 16
7663
0
бер. 15
7995