mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 15:43:25 +00:00
catch invalid dates on export, closes #180
This commit is contained in:
@@ -96,14 +96,19 @@ export function parseGPX(gpxData: string): GPXFile {
|
|||||||
export function buildGPX(file: GPXFile, exclude: string[]): string {
|
export function buildGPX(file: GPXFile, exclude: string[]): string {
|
||||||
const gpx = file.toGPXFileType(exclude);
|
const gpx = file.toGPXFileType(exclude);
|
||||||
|
|
||||||
|
let lastDate = undefined;
|
||||||
const builder = new XMLBuilder({
|
const builder = new XMLBuilder({
|
||||||
format: true,
|
format: true,
|
||||||
ignoreAttributes: false,
|
ignoreAttributes: false,
|
||||||
attributeNamePrefix: '',
|
attributeNamePrefix: '',
|
||||||
attributesGroupName: 'attributes',
|
attributesGroupName: 'attributes',
|
||||||
suppressEmptyNode: true,
|
suppressEmptyNode: true,
|
||||||
tagValueProcessor: (tagName: string, tagValue: unknown): string => {
|
tagValueProcessor: (tagName: string, tagValue: unknown): string | undefined => {
|
||||||
if (tagValue instanceof Date) {
|
if (tagValue instanceof Date) {
|
||||||
|
if (isNaN(tagValue.getTime())) {
|
||||||
|
return lastDate?.toISOString();
|
||||||
|
}
|
||||||
|
lastDate = tagValue;
|
||||||
return tagValue.toISOString();
|
return tagValue.toISOString();
|
||||||
}
|
}
|
||||||
return tagValue.toString();
|
return tagValue.toString();
|
||||||
|
Reference in New Issue
Block a user