import { format } from 'date-fns'
import { fi, enUS } from 'date-fns/locale'

type Props = {
  date?: Date
  dateFormat?: string
  language?: string
}
export const parseDate = ({
  date,
  dateFormat = 'dd.MM.yyyy',
  language,
}: Props) => {
  return date
    ? format(date, dateFormat, { locale: language === 'en' ? enUS : fi })
    : null
}
