LunchDevCommunity / community-calendar

📅 Community calendar for our Discord server, built with love and Eleventy.
https://events.lunch.dev
15 stars 12 forks source link

Event date validation #85

Open chantastic opened 3 years ago

chantastic commented 3 years ago

Until #79, we were validating the event date before building them.

I'm opening this issue to hold the implementation for future discussion of a similar implementation:

// Some helpers to make sure our event frontmatter is :100:
// Make events have an eleventy and js-yaml-friendly standardized date format of:
// date: 2021-01-11T21:00:00-08:00
// See: https://www.11ty.dev/docs/dates/#setting-a-content-date-in-front-matter
// Note: we make sure the parsed date is valid, then check the actual raw input format to make sure we have consistency

// const dateFormatRegex = /(date:)\s[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}Z/gm;
const isValidDate = (date, rawInputContent) => {
  !Number.isNaN(Date.parse(date)) && rawInputContent.match(dateFormatRegex);
};