diff -r df3106def670 -r 9ab9f762abed src/source/dev_guide/utilities.rst --- a/src/source/dev_guide/utilities.rst Fri Dec 21 15:48:43 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -.. _utilities: - -Custom PyAMS utilities -====================== - -PyAMS_utils provides a small set of utilities. You can create some of them as global utilities registered in -the global components registry; other ones can be created manually by a site administrator and -are then registered automatically. - - -Server timezone ---------------- - -To manage timezones correctly, and display datetimes based on current server timezone, all datetimes should -be defined and stored in UTC. - -PyAMS_utils provides a :py:class:`ServerTimezoneUtility ` which -allows you to assign a default timezone to your server. - -To display a datetime with correct timezone, you can use the :py:func:`tztime ` function, -which assign server timezone to the given parameter: - -.. code-block:: python - - from datetime import datetime - from pyams_utils.timezone import tztime - - now = datetime.utcnow() - my_date = tztime(now) # converts *now* to server timezone - -We could imagine that datetimes could be displayed with current user timezone. But it's quite impossible to know -the user timazone from a server request. The only options are: - -- you ask an authenticated user to update a timezone setting in his profile - -- you can include Javascript libraries which will try to detect browser timezone from their computer configuration, and - do an AJAX request to update data in their session. - -That should require an update of :py:func:`tzinfo` adapter to get timezone info from session, request or user profile. - -