WebFaction
Community site: login faq

Hi

I have a Django app hosted with Webfaction. One form in the app pre-populates the date with today's date.. except it is not honouring Time Zones. In the morming, it is one day behind. I think it flip to the correct date after 11am

The form is defined as follows in my forms.py:

date_created = forms.DateField(widget=forms.DateInput(format='%d/%m/%Y', attrs=
    {'class':'datepicker'}),
    initial=datetime.utcnow(),
    error_messages={'invalid': 'Please enter a valid date in the format dd/mm/yyyy'},
    required=False)

The app. is hosted in the European data centre. In settings.py the TIME_ZONE is set to 'Europe/London'

If I run manage.py shell and print.oz.environ['TZ'] it shows 'Europe/London' Within the shell print datetime.datetime.now() shows the correct time. So does datetime.datetime.utcnow()

In my .bashrc file I also have export TZ="Europe/London", though I've not yet sourced it (read about this in another post). Is this step really necessary if the above is correct?

Any idea as to why my time zone is incorrect?

asked 02 Nov '11, 07:17

howieweiner
112
accept rate: 0%


Hi,

I cannot see anything wrong with your settings or code. Could you please open a support ticket so we can try troubleshooting this?

permanent link

answered 02 Nov '11, 08:16

todork
1.2k5
accept rate: 34%

Try setting the TZ environment variable in your ~/webapps/app_name/apache2/bin/start script, eg:

TZ="Europe/London" LD_LIBRARY_PATH=/home/username/webapps/app_name/apache2/lib /home/username/webapps/app_name/apache2/bin/httpd.worker -f /home/username/webapps/app_name/apache2/conf/httpd.conf -k start

Hope that helps!

permanent link

answered 02 Nov '11, 19:54

seanf
12.2k41836
accept rate: 37%

Seems to have sorted the issue

Thanks for your help!

permanent link

answered 03 Nov '11, 12:47

howieweiner
112
accept rate: 0%

OIK. This issue was not actually to do with server time zone settings. It was actually a coding error, though an obscure one at that. Changing the code as follows, fixed the problem:

initial=datetime.utcnow

The parenthesis have been removed. With parenthesis, the function is only evaluated once; without, it is evaluated on each call. The first time it is evaluated, it will take the current time and cache it, until the server is restarted. I happened to be restarting the server quite a bitas I roll out regular updates, so this was hard to spot - as well as the issue occurring when the clocks changed, to add confusion.

permanent link

answered 11 Nov '11, 04:05

howieweiner
112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×337
×5

question asked: 02 Nov '11, 07:17

question was seen: 6,034 times

last updated: 11 Nov '11, 04:05

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM