mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Teach the date parser to also parse the international standard date format
The standard way to write a date is yyyy-mm-dd, which is unambiguous and sorts correctly. We parsed that right in the 'datetime' case, but not in the normal date case. And we do want to use that in our output format, exactly because it's standard. And also parse 'duration' for the dive duration. It's what we use when saving, it just so happened that we ended up not parsing it right, but then picking it up from the samples instead. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									1376712f0b
								
							
						
					
					
						commit
						5001ab66cb
					
				
					 1 changed files with 15 additions and 2 deletions
				
			
		
							
								
								
									
										17
									
								
								parse-xml.c
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								parse-xml.c
									
										
									
									
									
								
							|  | @ -106,14 +106,25 @@ static void divedate(char *buffer, void *_when) | ||||||
| { | { | ||||||
| 	int d,m,y; | 	int d,m,y; | ||||||
| 	time_t *when = _when; | 	time_t *when = _when; | ||||||
|  | 	int success = 0; | ||||||
| 
 | 
 | ||||||
|  | 	success = tm.tm_sec | tm.tm_min | tm.tm_hour; | ||||||
| 	if (sscanf(buffer, "%d.%d.%d", &d, &m, &y) == 3) { | 	if (sscanf(buffer, "%d.%d.%d", &d, &m, &y) == 3) { | ||||||
| 		tm.tm_year = y; | 		tm.tm_year = y; | ||||||
| 		tm.tm_mon = m-1; | 		tm.tm_mon = m-1; | ||||||
| 		tm.tm_mday = d; | 		tm.tm_mday = d; | ||||||
| 		if (tm.tm_sec | tm.tm_min | tm.tm_hour) | 	} else if (sscanf(buffer, "%d-%d-%d", &y, &m, &d) == 3) { | ||||||
| 			*when = utc_mktime(&tm); | 		tm.tm_year = y; | ||||||
|  | 		tm.tm_mon = m-1; | ||||||
|  | 		tm.tm_mday = d; | ||||||
|  | 	} else { | ||||||
|  | 		fprintf(stderr, "Unable to parse date '%s'\n", buffer); | ||||||
|  | 		success = 0; | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	if (success) | ||||||
|  | 		*when = utc_mktime(&tm); | ||||||
|  | 
 | ||||||
| 	free(buffer); | 	free(buffer); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -396,6 +407,8 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf) | ||||||
| 		return; | 		return; | ||||||
| 	if (MATCH(".meandepth", depth, &dive->meandepth)) | 	if (MATCH(".meandepth", depth, &dive->meandepth)) | ||||||
| 		return; | 		return; | ||||||
|  | 	if (MATCH(".duration", duration, &dive->duration)) | ||||||
|  | 		return; | ||||||
| 	if (MATCH(".divetime", duration, &dive->duration)) | 	if (MATCH(".divetime", duration, &dive->duration)) | ||||||
| 		return; | 		return; | ||||||
| 	if (MATCH(".divetimesec", duration, &dive->duration)) | 	if (MATCH(".divetimesec", duration, &dive->duration)) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue