date field conversion
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3345 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									da19359626
								
							
						
					
					
						commit
						fb8d5af50a
					
				
					 1 changed files with 15 additions and 0 deletions
				
			
		
							
								
								
									
										15
									
								
								external/dsv.py
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								external/dsv.py
									
										
									
									
										vendored
									
									
								
							|  | @ -22,6 +22,8 @@ $Id$ | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| import csv | import csv | ||||||
|  | from datetime import date, timedelta | ||||||
|  | from time import strptime | ||||||
| 
 | 
 | ||||||
| from zope import component | from zope import component | ||||||
| from zope.interface import implements | from zope.interface import implements | ||||||
|  | @ -64,3 +66,16 @@ class CsvReader(BaseReader): | ||||||
|                     result.append(element) |                     result.append(element) | ||||||
|                     lastIdentifiers[element.type] = id |                     lastIdentifiers[element.type] = id | ||||||
|         return result |         return result | ||||||
|  | 
 | ||||||
|  |     def getDate(self, value, correctBug=False): | ||||||
|  |         if not value: | ||||||
|  |             return value | ||||||
|  |         try: | ||||||
|  |             v = strptime(value, '%Y-%m-%d') | ||||||
|  |         except ValueError: | ||||||
|  |             return value | ||||||
|  |         else: | ||||||
|  |             d = date(*v[:3]) | ||||||
|  |             if correctBug: | ||||||
|  |                 d -= timedelta(4 * 365 + 2) | ||||||
|  |             return d | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm