Skip to content
Snippets Groups Projects
dates.js 877 B
Newer Older
Alexander Schoch's avatar
Alexander Schoch committed
import dayjs from "dayjs";

const utc = require("dayjs/plugin/utc");
Alexander Schoch's avatar
Alexander Schoch committed
const customParseFormat = require("dayjs/plugin/customParseFormat");
const timezone = require("dayjs/plugin/timezone");
dayjs.extend(utc);
Alexander Schoch's avatar
Alexander Schoch committed
dayjs.extend(customParseFormat);
dayjs.extend(timezone);
Alexander Schoch's avatar
Alexander Schoch committed

require("dayjs/locale/en");
require("dayjs/locale/de");

export function formatDateFromDB(date, locale) {
  dayjs.locale(locale);
  const d = dayjs(date).tz("Europe/Zurich");
Alexander Schoch's avatar
Alexander Schoch committed
  return locale == "de" ? d.format("dd, DD.MM.YY") : d.format("ddd, DD.MM.YY");
}

export function formatTimeFromDB(startTime, endTime) {
  const s = dayjs(startTime).tz("Europe/Zurich");
  const e = dayjs(endTime).tz("Europe/Zurich");
  return s.format("HH:mm") + "" + e.format("HH:mm");
Alexander Schoch's avatar
Alexander Schoch committed
}

export function isInFuture(event) {
  const now = new Date();
  now.setDate(now.getDate() - 1);
  return event.date > now.toISOString();
Alexander Schoch's avatar
Alexander Schoch committed
}