# -*- coding: utf-8 -*-
#    Asymmetric Base Framework - A collection of utilities for django frameworks
#    Copyright (C) 2013  Asymmetric Ventures Inc.
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; version 2 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

from __future__ import absolute_import, division, print_function, unicode_literals

from django import forms
from django.utils import dateparse
from django.utils.encoding import force_text

import six

class DateTimeTZField(forms.DateTimeField):
	
	def to_python(self, value):
		unicode_value = force_text(value, strings_only = True)
		if isinstance(unicode_value, six.text_type):
			value = unicode_value.strip()
		
		if isinstance(value, six.text_type):
			value = dateparse.parse_datetime(value)
		return super(DateTimeTZField, self).to_python(value)
