diff --git a/providers/Bugs/mod.ts b/providers/Bugs/mod.ts index 012e21ee..81093ed2 100644 --- a/providers/Bugs/mod.ts +++ b/providers/Bugs/mod.ts @@ -8,7 +8,7 @@ import { import type { ProviderCategory } from '@/providers/categories.ts'; import { DurationPrecision, FeatureQuality, type FeatureQualityMap } from '@/providers/features.ts'; import { getFromEnv } from '@/utils/config.ts'; -import type { PartialDate } from '@/utils/date.ts'; +import { parseCompactDate, type PartialDate } from '@/utils/date.ts'; import { parseDuration } from '@/utils/time.ts'; import { ProviderError } from '@/utils/errors.ts'; import type { @@ -149,7 +149,7 @@ export class BugsReleaseLookup extends ReleaseApiLookup this.convertRawArtist(a)), - releaseDate: this.convertReleaseDate(parseYYYYMMDD(raw.album.release_ymd)), + releaseDate: this.convertReleaseDate(parseCompactDate(raw.album.release_ymd)), labels: this.extractLabels(raw.album), images: [this.coverArtwork(raw.album.image.path)], types: mapReleaseType(raw.album.album_tp_nm), @@ -220,16 +220,6 @@ interface BugsRawRelease { tracks: BugsTrack[]; } -function parseYYYYMMDD(date: string): PartialDate { - const match = date.match(/^(\d{4})(\d{2})(\d{2})$/); - if (!match) return {}; - return { - year: parseInt(match[1]), - month: parseInt(match[2]), - day: parseInt(match[3]), - }; -} - function mapReleaseType(albumType?: string): ReleaseGroupType[] | undefined { if (!albumType) return undefined; if (albumType === '싱글') return ['Single']; diff --git a/utils/date.ts b/utils/date.ts index da443f11..7ccc2a27 100644 --- a/utils/date.ts +++ b/utils/date.ts @@ -28,7 +28,7 @@ export function formatPartialDate(date: PartialDate) { return dateComponents.join('-'); } -/** Parses `YYYY-MM-DD` date strings */ +/** Parses `YYYY-MM-DD`, `YYYY-MM`, and `YYYY` date strings */ export function parseHyphenatedDate(date: string): PartialDate { if (date.match(/^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?$/)) { return zipObject(['year', 'month', 'day'], date.split('-').map((component) => Number.parseInt(component))); @@ -36,6 +36,19 @@ export function parseHyphenatedDate(date: string): PartialDate { return {}; } +/** Parses `YYYYMMDD` date strings */ +export function parseCompactDate(date: string): PartialDate { + const match = date.match(/^(\d{4})(\d{2})(\d{2})$/); + if (match) { + return { + year: Number.parseInt(match[1]), + month: Number.parseInt(match[2]), + day: Number.parseInt(match[3]), + }; + } + return {}; +} + /** Parses a simple ISO 8601 date time string (`YYYY-MM-DDTHH:mm:ss.sssZ`) */ export function parseISODateTime(dateTime: string): PartialDate { const date = new Date(dateTime);