catch invalid dates on export, closes #180

This commit is contained in:
vcoppe
2025-02-07 18:13:46 +01:00
parent dfcdd71057
commit 848b6dcef3

View File

@@ -96,14 +96,19 @@ export function parseGPX(gpxData: string): GPXFile {
export function buildGPX(file: GPXFile, exclude: string[]): string {
const gpx = file.toGPXFileType(exclude);
let lastDate = undefined;
const builder = new XMLBuilder({
format: true,
ignoreAttributes: false,
attributeNamePrefix: '',
attributesGroupName: 'attributes',
suppressEmptyNode: true,
tagValueProcessor: (tagName: string, tagValue: unknown): string => {
tagValueProcessor: (tagName: string, tagValue: unknown): string | undefined => {
if (tagValue instanceof Date) {
if (isNaN(tagValue.getTime())) {
return lastDate?.toISOString();
}
lastDate = tagValue;
return tagValue.toISOString();
}
return tagValue.toString();