Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions providers/Bugs/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -149,7 +149,7 @@ export class BugsReleaseLookup extends ReleaseApiLookup<BugsProvider, BugsRawRel
return {
title: raw.album.title,
artists: raw.album.artists.map((a) => 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),
Expand Down Expand Up @@ -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'];
Expand Down
15 changes: 14 additions & 1 deletion utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,27 @@ 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)));
}
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);
Expand Down
Loading