From 6ee29e294cbf9bbfbb4f64f42005e2c8e9a5a35d Mon Sep 17 00:00:00 2001 From: "Daniel D. Beck" Date: Wed, 24 Jul 2024 12:13:56 +0200 Subject: [PATCH] Handle version ranges in `index.ts` Baseline high calculations Prompted by the error in https://github.com/web-platform-dx/web-features/pull/1442 --- index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index 86c6212ed90..afc734c5107 100644 --- a/index.ts +++ b/index.ts @@ -1,10 +1,10 @@ import fs from 'fs'; import path from 'path'; +import { Temporal } from '@js-temporal/polyfill'; import { fdir } from 'fdir'; import YAML from 'yaml'; import { FeatureData, GroupData, SnapshotData } from './types'; -import { Temporal } from '@js-temporal/polyfill'; import { toString as hastTreeToString } from 'hast-util-to-string'; import rehypeStringify from 'rehype-stringify'; @@ -12,7 +12,7 @@ import remarkParse from 'remark-parse'; import remarkRehype from 'remark-rehype'; import { unified } from 'unified'; -import { BASELINE_LOW_TO_HIGH_DURATION } from 'compute-baseline'; +import { BASELINE_LOW_TO_HIGH_DURATION, parseRangedDateString } from 'compute-baseline'; // The longest name allowed, to allow for compact display. const nameMaxLength = 80; @@ -135,9 +135,10 @@ for (const [key, data] of yamlEntries('features')) { // Compute Baseline high date from low date. if (data.status?.baseline === 'high') { - const lowDate = Temporal.PlainDate.from(data.status.baseline_low_date); + const [date, ranged] = parseRangedDateString(data.status.baseline_low_date); + const lowDate = Temporal.PlainDate.from(date); const highDate = lowDate.add(BASELINE_LOW_TO_HIGH_DURATION); - data.status.baseline_high_date = String(highDate); + data.status.baseline_high_date = ranged ? `≤${highDate}` : String(highDate); } // Ensure name and description are not too long.