Skip to content

Commit

Permalink
feat(converter): improve the converter on the weekly update frequencies
Browse files Browse the repository at this point in the history
  • Loading branch information
LHBruneton-C2C authored and jahow committed May 21, 2024
1 parent f93c34b commit 15b62fc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
13 changes: 13 additions & 0 deletions libs/api/metadata-converter/src/lib/iso19139/read-parts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion libs/api/metadata-converter/src/lib/iso19139/read-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 22 additions & 1 deletion libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -512,4 +516,21 @@ describe('write parts', () => {
</root>`)
})
})

describe('getISODuration', () => {
it('keeps a partial weekly period', () => {
expect(
getISODuration({
updatedTimes: 3,
per: 'week',
})
).toEqual('P0Y0M2D')
expect(
getISODuration({
updatedTimes: 2,
per: 'week',
})
).toEqual('P0Y0M3D')
})
})
})
5 changes: 1 addition & 4 deletions libs/api/metadata-converter/src/lib/iso19139/write-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ import {
findChildOrCreate,
findChildrenElement,
findNestedChildOrCreate,
findNestedElement,
findNestedElements,
readAttribute,
readText,
removeAllChildren,
removeChildren,
removeChildrenByName,
Expand All @@ -36,7 +34,6 @@ import {
} from '../xml-utils'
import {
ChainableFunction,
combine,
fallback,
filterArray,
getAtIndex,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 15b62fc

Please sign in to comment.