Changeset 8380 for main/waeup.kofa/trunk
- Timestamp:
- 7 May 2012, 10:15:21 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/utils
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py
r8333 r8380 23 23 import grok 24 24 import csv 25 import datetime 25 26 import os 26 27 import tempfile … … 405 406 # CSV writers like byte streams better than unicode 406 407 value = value.encode('utf-8') 408 elif isinstance(value, datetime.datetime): 409 value = str(value) 410 elif isinstance(value, datetime.date): 411 # Order is important here: check for date after datetime as 412 # datetimes are also dates. 413 # 414 # Append hash '#' to dates to circumvent unwanted excel automatic 415 value = str('%s#' % value) 407 416 elif value is None: 408 417 # None is not really representable in CSV files -
main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_batching.py
r8228 r8380 16 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 ## 18 import datetime 18 19 import doctest 19 20 import logging … … 268 269 result4 = exporter.mangle_value(u'string', 'foo') 269 270 result5 = exporter.mangle_value(None, 'foo') 271 result6 = exporter.mangle_value(datetime.date(2012, 4, 1), 'foo') 272 result7 = exporter.mangle_value( 273 datetime.datetime(2012, 4, 1, 12, 1, 1), 'foo') 270 274 self.assertEqual( 271 275 (result1, result2, result3, result4, result5), … … 273 277 self.assertEqual(type(result3), type('string')) 274 278 self.assertEqual(type(result4), type('string')) 279 # dates are formatted with trailing hash 280 self.assertEqual(result6, '2012-04-01#') 281 # datetimes are formatted as yyyy-mm-dd hh:mm:ss 282 self.assertEqual(result7, '2012-04-01 12:01:01') 275 283 return 276 284
Note: See TracChangeset for help on using the changeset viewer.