Instead of using this method i decided to just add the time difference to
the UTC time to get my local time.
import datetime
db.define_table('my_token',
Field('purchased_on', 'datetime', default=(request.now+datetime.
timedelta(hours=2)), readable=False, writable=False),
.............
.............
.............
Regards;
Mostwanted
On Wednesday, June 3, 2020 at 8:22:00 PM UTC+2, mostwanted wrote:
>
>
> Hi guys has anyone ever tried this solution by Massimo & Nyphold (
> http://luca.dealfaro.org/code/web2py-recipes/utc-to-localtime-and-back-in-web2py
> )?
> I tried it in my application but I must be missing a step or something
> because my time is NOT changing or maybe i'm just using it wrong!
> Because of different time zones I wanna convert my users time stamps from
> the app hosters (pythonanywhere.com) time (UTC) to my time (local time):
>
> *CODE:*
>
> *Model (db.py):*
> # --------------------------------------------------------------------
> #Detecting the usertime zone
> #---------------------------------------------------------------------
> is_timezone_unknown = (session.user_timezone is None)
> user_timezone = session.user_timezone or 'UTC'
>
> *Model (Application DB)*
> datetime_validator = IS_DATETIME(timezone=pytz.timezone(user_timezone),
> format=DATE_FORMAT)
>
>
> *Controller:*
> def set_timezone():
> """Ajax call to set the timezone information for the session."""
> tz_name = request.vars.name
> from pytz import all_timezones_set
> if tz_name in all_timezones_set:
> session.user_timezone = tz_name
>
> *View (Somewhere in the Layout): *
> {{if is_timezone_unknown:}}
> <script src="{{=URL('static', 'js/jstz.min.js')}}"></script>
> <script>
> $(function() {
> var tz_name = jstz.determine();
> $.get("{{=URL('default', 'set_timezone')}}", tz_name);
> });
> </script>
> {{pass}}
>
> I wanna believe this is how this solution is used but I am not getting
> results!
>
> Please assist;
>
> Regards;
>
> Mostwanted
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/7ca49988-1f6a-4498-91c3-4ff1ce28b899%40googlegroups.com.