From 848b6dcef317055d9d2b49c2793547639b9ee2ac Mon Sep 17 00:00:00 2001 From: vcoppe Date: Fri, 7 Feb 2025 18:13:46 +0100 Subject: [PATCH] catch invalid dates on export, closes #180 --- gpx/src/io.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gpx/src/io.ts b/gpx/src/io.ts index 9f4a264c..f20a7046 100644 --- a/gpx/src/io.ts +++ b/gpx/src/io.ts @@ -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();