11 lines
341 B
TypeScript
11 lines
341 B
TypeScript
/**
|
|
* Парсит дату из ID статьи (формат: "2019-05-01-slug").
|
|
*/
|
|
export function parseDateFromId(id: string): Date {
|
|
const match = id.match(/^(\d{4})-(\d{2})-(\d{2})-/);
|
|
if (!match) {
|
|
throw new Error(`Cannot parse date from article id: ${id}`);
|
|
}
|
|
return new Date(`${match[1]}-${match[2]}-${match[3]}`);
|
|
}
|