Skip to content
Snippets Groups Projects
dates.js 905 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");
}

Alexander Schoch's avatar
Alexander Schoch committed
export function getTimeString(time) {
  const t = dayjs(time).tz("Europe/Zurich");
  return t.format("HH:mm");
}

Alexander Schoch's avatar
Alexander Schoch committed
export function formatTimeFromDB(startTime, endTime) {
Alexander Schoch's avatar
Alexander Schoch committed
  return getTimeString(startTime) + "" + getTimeString(endTime);
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
}