frontend update
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import {format, parse} from "date-fns";
|
||||
import {API_DATE_FORMAT, API_DATETIME_FORMAT} from "./constants";
|
||||
|
||||
function humanReadableSize(bytes, dp = 1) {
|
||||
const thresh = 1024;
|
||||
|
||||
@@ -44,4 +47,35 @@ const getBaseUrl = () => {
|
||||
return window.location.protocol + "//" + window.location.host;
|
||||
}
|
||||
|
||||
export { humanReadableSize, removeParameter, getParameter, encodeText, decodeText, getBaseUrl };
|
||||
const formatDate = (L, apiDate) => {
|
||||
if (!(apiDate instanceof Date)) {
|
||||
if (!isNaN(apiDate)) {
|
||||
apiDate = new Date(apiDate);
|
||||
} else {
|
||||
apiDate = parse(apiDate, API_DATE_FORMAT, new Date());
|
||||
}
|
||||
}
|
||||
|
||||
return format(apiDate, L("general.date_format", "YYY/MM/dd"));
|
||||
}
|
||||
|
||||
const formatDateTime = (L, apiDate) => {
|
||||
if (!(apiDate instanceof Date)) {
|
||||
if (!isNaN(apiDate)) {
|
||||
apiDate = new Date(apiDate);
|
||||
} else {
|
||||
apiDate = parse(apiDate, API_DATETIME_FORMAT, new Date());
|
||||
}
|
||||
}
|
||||
|
||||
return format(apiDate, L("general.date_time_format", "YYY/MM/dd HH:mm:ss"));
|
||||
}
|
||||
|
||||
const upperFirstChars = (str) => {
|
||||
return str.split(" ")
|
||||
.map(block => block.charAt(0).toUpperCase() + block.substring(1))
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
export { humanReadableSize, removeParameter, getParameter, encodeText, decodeText, getBaseUrl,
|
||||
formatDate, formatDateTime, upperFirstChars };
|
||||
Reference in New Issue
Block a user