replaced dayjs with date-fns

This commit is contained in:
2024-03-27 11:37:57 +01:00
parent 5da644acce
commit ec7fb0ecc3
6 changed files with 36 additions and 30 deletions

View File

@@ -1,9 +1,6 @@
export const API_DATE_FORMAT = "yyyy-MM-dd";
export const API_TIME_FORMAT = "HH:mm:ss";
export const API_DATETIME_FORMAT = API_DATE_FORMAT + " " + API_TIME_FORMAT;
export const API_DATE_FORMAT_DAYJS = "YYYY-MM-DD";
export const API_TIME_FORMAT_DAYJS = "HH:mm:ss";
export const API_DATETIME_FORMAT_DAYJS = API_DATE_FORMAT_DAYJS + " " + API_TIME_FORMAT_DAYJS;
export const USER_GROUP_ADMIN = 1;

View File

@@ -1,6 +1,7 @@
import React, {useReducer} from 'react';
import {createContext, useCallback, useState} from "react";
import { enUS as dateFnsEN, de as dateFnsDE } from 'date-fns/locale';
import {getCookie, getParameter} from "./util";
const LocaleContext = createContext(null);
@@ -31,7 +32,7 @@ function reducer(entries, action) {
function LocaleProvider(props) {
const [entries, dispatch] = useReducer(reducer, window.languageEntries || {});
const [currentLocale, setCurrentLocale] = useState(window.languageCode || "en_US");
const [currentLocale, setCurrentLocale] = useState(window.languageCode || getParameter("lang") || getCookie("lang") || "en_US");
const translate = useCallback((key, defaultTranslation = null) => {

View File

@@ -46,6 +46,16 @@ const getParameter = (key) => {
}
}
const getCookie = (name) => {
let cookieString = decodeURIComponent(document.cookie);
let match = cookieString.match(new RegExp('(^| )' + name + '=([^;]+)'));
if (match) {
return match[2];
} else {
return null;
}
}
const encodeText = (str) => {
return Uint8Array.from(str, c => c.charCodeAt(0));
}
@@ -87,7 +97,6 @@ function formatDistance(dateFns, apiDate) {
return formatDistanceDateFns(toDate(apiDate), new Date(), { addSuffix: true, locale: dateFns });
}
const upperFirstChars = (str) => {
return str.split(" ")
.map(block => block.charAt(0).toUpperCase() + block.substring(1))
@@ -100,7 +109,7 @@ const isInt = (value) => {
!isNaN(parseInt(value, 10));
}
export { humanReadableSize, removeParameter, getParameter,
export { humanReadableSize, removeParameter, getParameter, getCookie,
encodeText, decodeText, getBaseUrl,
formatDate, formatDateTime, formatDistance,
upperFirstChars, isInt, createDownload };