Commit 9d51c570 authored by Axel Bocciarelli's avatar Axel Bocciarelli
Browse files

Use moment's built-in formats

parent ecf2c496
Pipeline #31528 passed with stage
in 3 minutes and 11 seconds
......@@ -25,7 +25,7 @@ class DatasetTable extends React.Component {
return (
<>
<Glyphicon glyph="time" style={{ marginRight: 5, top: 2 }} />
{parsedDate.format("HH:mm")}
{parsedDate.format(moment.HTML5_FMT.TIME)}
<span style={{ marginLeft: 5, color: "#777", fontSize: 11 }}>{parsedDate.format("ll")}</span>
</>
);
......
......@@ -199,7 +199,7 @@ export class Event extends React.Component {
</Tooltip>
}
>
<span style={{ cursor: "pointer", color: "black", margin: "0px" }}>{moment(getOriginalEvent(event).creationDate).format("HH:mm:ss")} </span>
<span style={{ cursor: "pointer", color: "black", margin: "0px" }}>{moment(getOriginalEvent(event).creationDate).format(moment.HTML5_FMT.TIME_SECONDS)} </span>
</OverlayTrigger>
</td>
<td className="borderTopSeparatorBetweenEvents" style={{ width: "30px" }}>
......
......@@ -11,8 +11,6 @@ import DayPickerInput from "react-day-picker/DayPickerInput";
import { formatDate, parseDate } from "react-day-picker/moment";
import "react-day-picker/lib/style.css";
const DATE_QUERY_FORMAT = "YYYY-MM-DD";
function getActionColumn(handleView) {
return {
text: "",
......@@ -54,7 +52,7 @@ function ParcelTable(props) {
const latestQuery = useRef(); // work around stale query reference when changing search term
latestQuery.current = query;
const dateFilter = query.get("date") ? moment(query.get("date"), DATE_QUERY_FORMAT) : undefined;
const dateFilter = query.get("date") ? moment(query.get("date"), moment.HTML5_FMT.DATE) : undefined;
const statusFilter = query.get("status");
const searchFilter = query.get("q");
const [sortField, sortOrder] = (query.get("sort") || "_id-desc").split("-");
......@@ -63,7 +61,7 @@ function ParcelTable(props) {
const newQuery = new URLSearchParams(query);
if (date) {
newQuery.set("date", moment(date).format(DATE_QUERY_FORMAT));
newQuery.set("date", moment(date).format(moment.HTML5_FMT.DATE));
} else {
newQuery.delete("date");
}
......
......@@ -20,10 +20,10 @@ function DataStatisticsPage() {
<div className="app__inner">
<Tabs id="uncontrolled-tab-example" defaultActiveKey={1}>
<Tab eventKey={1} title="Today">
<GeneralStatsPanel user={user} start={moment().format("YYYY-MM-DD")} end={moment().add(1, "days").format("YYYY-MM-DD")} name="" />
<GeneralStatsPanel user={user} start={moment().format(moment.HTML5_FMT.DATE)} end={moment().add(1, "days").format(moment.HTML5_FMT.DATE)} name="" />
</Tab>
<Tab eventKey={2} title="Last week">
<GeneralStatsPanel user={user} start={moment().subtract(7, "days").format("YYYY-MM-DD")} end={moment().add(1, "days").format("YYYY-MM-DD")} name="" />
<GeneralStatsPanel user={user} start={moment().subtract(7, "days").format(moment.HTML5_FMT.DATE)} end={moment().add(1, "days").format(moment.HTML5_FMT.DATE)} name="" />
</Tab>
<Tab eventKey={3} title="All">
<GeneralStatsPanel user={user} start="2014-01-01" end="2024-01-01" name="From 2024-01-01" />
......
import escapeStringRegexp from "escape-string-regexp";
import UI from "../../config/ui/config";
import { DOC_VIEW } from "../../constants/eventTypes";
import moment from "moment";
const REGEXP_FILTER_TYPE = "regexpFilterType";
const EQUALITY_FILTER_TYPE = "equalityFilterType";
......@@ -162,10 +163,10 @@ function regexpFilterOnSingleCriterion(criterion) {
function getDateFilterOnSingleCriterion(criterion) {
if (criterion.momentDate) {
if (criterion.search === "before") {
return { $lt: `${criterion.momentDate.format("YYYY-MM-DDTHH:mm:ss.SSS")}Z` };
return { $lt: `${criterion.momentDate.format(moment.HTML5_FMT.DATETIME_LOCAL_MS)}Z` };
}
if (criterion.search === "after") {
return { $gte: `${criterion.momentDate.format("YYYY-MM-DDTHH:mm:ss.SSS")}Z` };
return { $gte: `${criterion.momentDate.format(moment.HTML5_FMT.DATETIME_LOCAL_MS)}Z` };
}
}
return null;
......
......@@ -5,7 +5,7 @@ import keycloak from "../config/sso/keycloak";
import ICAT from "../config/icat/icat";
export function getRemainingSessionTime(expirationTime) {
return moment(expirationTime, "MMMM Do YYYY, h:mm:ss a").diff(moment());
return moment(expirationTime).diff(moment());
}
export function checkExpirationTime() {
......
......@@ -52,7 +52,7 @@ export function getEventIcon(category, size) {
* @returns {string} the date in the format HH:mm
*/
export function getEventCreationDate(event) {
return moment(event.creationDate).format("HH:mm:ss");
return moment(event.creationDate).format(moment.HTML5_FMT.TIME_SECONDS);
}
/**
......
......@@ -31,7 +31,7 @@ const user = (state = initialState, action) => {
username: state.username,
isSSO: state.isSSO,
sessionId: action.sessionId,
expirationTime: moment().add(action.lifeTimeMinutes, "minutes").format("MMMM Do YYYY, h:mm:ss a"),
expirationTime: moment().add(action.lifeTimeMinutes, "minutes").format(),
fullName: action.fullName,
name: action.name,
isAdministrator: action.isAdministrator,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment