diff --git a/libs/api/metadata-converter/src/lib/iso19139/read-parts.spec.ts b/libs/api/metadata-converter/src/lib/iso19139/read-parts.spec.ts index 9e30c111e0..3a64318005 100644 --- a/libs/api/metadata-converter/src/lib/iso19139/read-parts.spec.ts +++ b/libs/api/metadata-converter/src/lib/iso19139/read-parts.spec.ts @@ -6,6 +6,7 @@ import GEOCAT_CH_DATASET from '../fixtures/geocat-ch.iso19139.dataset.xml' // @ts-ignore import GEOCAT_CH_SERVICE from '../fixtures/geocat-ch.iso19139.service.xml' import { + getUpdateFrequencyFromCustomPeriod, readContacts, readDistributions, readOnlineResources, @@ -91,6 +92,18 @@ describe('read parts', () => { }) }) }) + describe('getUpdateFrequencyFromCustomPeriod', () => { + it('keeps a partial weekly period', () => { + expect(getUpdateFrequencyFromCustomPeriod('P0Y0M2D')).toEqual({ + updatedTimes: 3, + per: 'week', + }) + expect(getUpdateFrequencyFromCustomPeriod('P0Y0M3D')).toEqual({ + updatedTimes: 2, + per: 'week', + }) + }) + }) }) describe('dataset record', () => { diff --git a/libs/api/metadata-converter/src/lib/iso19139/read-parts.ts b/libs/api/metadata-converter/src/lib/iso19139/read-parts.ts index 674feff624..dfb1cc3590 100644 --- a/libs/api/metadata-converter/src/lib/iso19139/read-parts.ts +++ b/libs/api/metadata-converter/src/lib/iso19139/read-parts.ts @@ -434,7 +434,7 @@ export function getUpdateFrequencyFromCustomPeriod( } else if (days <= 7) { return { per: 'week', - updatedTimes: Math.round(7 / days), + updatedTimes: Math.round(7 / days - 0.0001), // this is to make sure that 'every 2 days' = '3 times per week' } } else if (days) { return { diff --git a/libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts b/libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts index 12b4cd1009..1169c595b6 100644 --- a/libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts +++ b/libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts @@ -5,7 +5,11 @@ import { parseXmlString, xmlToString, } from '../xml-utils' -import { writeDistributions, writeKeywords } from './write-parts' +import { + getISODuration, + writeDistributions, + writeKeywords, +} from './write-parts' import { GENERIC_DATASET_RECORD } from '../fixtures/generic.records' import { DatasetRecord } from '@geonetwork-ui/common/domain/model/record' @@ -512,4 +516,21 @@ describe('write parts', () => { `) }) }) + + describe('getISODuration', () => { + it('keeps a partial weekly period', () => { + expect( + getISODuration({ + updatedTimes: 3, + per: 'week', + }) + ).toEqual('P0Y0M2D') + expect( + getISODuration({ + updatedTimes: 2, + per: 'week', + }) + ).toEqual('P0Y0M3D') + }) + }) }) diff --git a/libs/api/metadata-converter/src/lib/iso19139/write-parts.ts b/libs/api/metadata-converter/src/lib/iso19139/write-parts.ts index 21b54ca1c0..b29dc6b599 100644 --- a/libs/api/metadata-converter/src/lib/iso19139/write-parts.ts +++ b/libs/api/metadata-converter/src/lib/iso19139/write-parts.ts @@ -24,10 +24,8 @@ import { findChildOrCreate, findChildrenElement, findNestedChildOrCreate, - findNestedElement, findNestedElements, readAttribute, - readText, removeAllChildren, removeChildren, removeChildrenByName, @@ -36,7 +34,6 @@ import { } from '../xml-utils' import { ChainableFunction, - combine, fallback, filterArray, getAtIndex, @@ -220,7 +217,7 @@ export function getISODuration(updateFrequency: UpdateFrequencyCustom): string { else duration.hours = Math.round(24 / updateFrequency.updatedTimes) break case 'week': - duration.days = Math.round(7 / updateFrequency.updatedTimes) + duration.days = Math.round(7 / updateFrequency.updatedTimes - 0.0001) // this is to make sure that '2 times per week' = 'every 3 days' break case 'month': if (updateFrequency.updatedTimes <= 1) duration.months = 1