sot / kadi

Chandra commands and events
https://sot.github.io/kadi
BSD 3-Clause "New" or "Revised" License
5 stars 3 forks source link

Ensure that timezone TZ env var is unmodified by `django.setup()` #284

Closed taldcroft closed 1 year ago

taldcroft commented 1 year ago

Description

This fixes the issue described in #283, but instead by ensuring that the TZ environment variable is not modified by the call to django.setup(). For most unix machines this means that TZ will be undefined, but on GRETA it will remain as GMT.

Interface impacts

None

Testing

Unit tests

Independent check of unit tests by [REVIEWER NAME]

Functional tests

These tests use https://github.com/sot/cxotime/pull/36.

Test 1 (no TZ defined)

(ska3) ➜  kadi git:(master) ✗ env PYTHONPATH=/Users/aldcroft/git/cxotime ipython

Python 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:27:35) [Clang 14.0.6 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import kadi.events
   ...: 
   ...: kadi.events.eclipses
Out[1]: <EventQuery: Eclipse>

In [3]: from cxotime import CxoTime

In [4]: t = CxoTime.now()

In [5]: t.print_conversions()
local       2023 Thu Mar 30 12:00:07 PM EDT 
iso_local   2023-03-30T12:00:07.241000-04:00
date        2023:089:16:00:07.241           
cxcsec      796579276.425                   
decimalyear 2023.24292                      
iso         2023-03-30 16:00:07.241         
unix        1680192007.241            

In [7]: import os
In [8]: os.environ.get("TZ")
In [9]:       

Test 2 (TZ=GMT)

(ska3) ➜  kadi git:(leave-timezone-unmodified) env TZ=GMT PYTHONPATH=/Users/aldcroft/git/cxotime ipython 
Python 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:27:35) [Clang 14.0.6 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import kadi.events

In [2]: kadi.events.eclipses
Out[2]: <EventQuery: Eclipse>

In [3]: import os

In [4]: os.environ.get("TZ")
Out[4]: 'GMT'

In [5]: from cxotime import CxoTime

In [6]: t = CxoTime("2022:300:01:00:00.000")

In [7]: t.print_conversions()
local       2022 Thu Oct 27 01:00:00 AM GMT
iso_local   2022-10-27T01:00:00+00:00      
date        2022:300:01:00:00.000          
cxcsec      783219669.184                  
decimalyear 2022.81929                     
iso         2022-10-27 01:00:00.000        
unix        1666832400.000