Fix in datetime
This commit is contained in:
parent
ded04f96b0
commit
3aaba5e7a1
3 changed files with 51 additions and 15 deletions
|
|
@ -25,10 +25,18 @@ from settings import config
|
|||
|
||||
# Next convert to
|
||||
|
||||
locale='es_ES'
|
||||
|
||||
format_date="yyyy/LL/dd"
|
||||
|
||||
format_time="HH:mm:ss"
|
||||
|
||||
timezone='UTC'
|
||||
|
||||
if hasattr(config, 'timezone'):
|
||||
timezone=config.timezone
|
||||
else:
|
||||
timezone='UTC'
|
||||
|
||||
#if hasattr
|
||||
|
||||
tzutc=get_timezone('UTC')
|
||||
|
||||
|
|
@ -74,20 +82,33 @@ def obtain_fields_time(time):
|
|||
|
||||
return year, month, day, hour, minute, second
|
||||
|
||||
|
||||
# In the format of tzinfo
|
||||
|
||||
def format_tztime(time):
|
||||
def format_tztime(time, tzc=None):
|
||||
|
||||
if tzc==None:
|
||||
tzc=tz
|
||||
|
||||
#try:
|
||||
|
||||
year, month, day, hour, minute, second=obtain_fields_time(time)
|
||||
|
||||
t=datetime(year, month, day, hour, minute, second)
|
||||
|
||||
return format_datetime(t, locale="es_ES", tzinfo=tz)
|
||||
|
||||
#except:
|
||||
|
||||
return format_datetime(t, format_time, tzinfo=tzc)
|
||||
|
||||
def format_tzdate(time, tzc=None):
|
||||
|
||||
if tzc==None:
|
||||
tzc=tz
|
||||
|
||||
year, month, day, hour, minute, second=obtain_fields_time(time)
|
||||
|
||||
t=datetime(year, month, day, hour, minute, second)
|
||||
|
||||
return format_datetime(t, format_date, tzinfo=tzc)
|
||||
|
||||
|
||||
# return timenow()
|
||||
|
||||
def obtain_timezone(timezone):
|
||||
|
||||
return get_timezone(timezone)
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ class BaseForm:
|
|||
|
||||
value=str(value)
|
||||
|
||||
return value.replace('"', '"')
|
||||
return value.replace('"', '"').replace("'", ''')
|
||||
|
||||
class TextForm(BaseForm):
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,26 @@ class TestFieldMethods(unittest.TestCase):
|
|||
|
||||
def test_timenow(self):
|
||||
|
||||
time=datetime.normalize_time(2012, 12, 21, 00, 24, 21)
|
||||
time=datetime.normalize_time(2012, 12, 21, 23, 24, 21)
|
||||
|
||||
self.assertEqual(time, '20121221002421')
|
||||
self.assertEqual(time, '20121221232421')
|
||||
|
||||
value=datetime.format_tztime(time)
|
||||
|
||||
self.assertEqual(value, '21/12/2012 00:24:21')
|
||||
self.assertEqual(value, '23:24:21')
|
||||
|
||||
value=datetime.format_tzdate(time)
|
||||
|
||||
self.assertEqual(value, '2012/12/21')
|
||||
|
||||
tz=datetime.obtain_timezone('Europe/Madrid')
|
||||
|
||||
value=datetime.format_tzdate(time, tz)
|
||||
|
||||
self.assertEqual(value, '2012/12/22')
|
||||
|
||||
value=datetime.format_tztime(time, tz)
|
||||
|
||||
self.assertEqual(value, '00:24:21')
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue