diff --git a/paramecio/citoplasma/datetime.py b/paramecio/citoplasma/datetime.py index 5d36a02..322976f 100644 --- a/paramecio/citoplasma/datetime.py +++ b/paramecio/citoplasma/datetime.py @@ -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() - \ No newline at end of file +def obtain_timezone(timezone): + + return get_timezone(timezone) + \ No newline at end of file diff --git a/paramecio/cromosoma/coreforms.py b/paramecio/cromosoma/coreforms.py index 285b51b..407a12c 100644 --- a/paramecio/cromosoma/coreforms.py +++ b/paramecio/cromosoma/coreforms.py @@ -31,7 +31,7 @@ class BaseForm: value=str(value) - return value.replace('"', '"') + return value.replace('"', '"').replace("'", ''') class TextForm(BaseForm): diff --git a/tests/datetimetest.py b/tests/datetimetest.py index 6384a03..911fb21 100644 --- a/tests/datetimetest.py +++ b/tests/datetimetest.py @@ -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') + \ No newline at end of file