Refactor/time formatting (#696)

* chore: upgrade related dependencies

* fix: skip sentry on dev

* refactor: unify time formatting

* refactor: display default format for page
This commit is contained in:
Carlos Valente
2024-01-09 15:30:11 +01:00
committed by GitHub
parent 9031051465
commit b4e73ff6b5
54 changed files with 1177 additions and 687 deletions
@@ -44,10 +44,10 @@ import { dbModel } from '../models/dataModel.js';
// Create controller for GET request to '/ontime/poll'
// Returns data for current state
export const poll = async (req, res) => {
export const poll = async (_req, res) => {
try {
const s = eventStore.poll();
res.status(200).send(s);
const state = eventStore.poll();
res.status(200).send(state);
} catch (error) {
res.status(500).send({
message: `Could not get sync data: ${error}`,
@@ -120,7 +120,7 @@ const getNetworkInterfaces = () => {
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
if (net.family === 'IPv4' && !net.internal) {
results.push({
name: name,
name,
address: net.address,
});
}
@@ -653,7 +653,7 @@ export const deleteProjectFile: RequestHandler = async (req, res) => {
const projectFilePath = join(uploadsFolderPath, filename);
const errors = validateProjectFiles({ filename: filename });
const errors = validateProjectFiles({ filename });
if (errors.length) {
return res.status(409).send({ message: errors.join(', ') });
@@ -1,6 +1,6 @@
// any value inside double curly braces {{val}}
import { formatDisplay } from 'ontime-utils';
import { millisToString, removeLeadingZero } from 'ontime-utils';
// any value inside double curly braces {{val}}
const placeholderRegex = /{{(.*?)}}/g;
function formatDisplayFromString(value: string, hideZero = false): string {
@@ -12,7 +12,11 @@ function formatDisplayFromString(value: string, hideZero = false): string {
valueInNumber = parsedValue;
}
}
return formatDisplay(valueInNumber, hideZero);
let formatted = millisToString(valueInNumber, { fallback: hideZero ? '00:00' : '00:00:00' });
if (hideZero) {
formatted = removeLeadingZero(formatted);
}
return formatted;
}
type AliasesDefinition = Record<string, { key: string; cb: (value: unknown) => string }>;
@@ -1,6 +1,6 @@
import { ensureJsonExtension } from '../utils/ensureJsonExtension.js';
import { ensureJsonExtension } from './ensureJsonExtension.js';
export const sanitizeProjectFilename = (req, res, next) => {
export const sanitizeProjectFilename = (req, _res, next) => {
const { filename, newFilename } = req.body;
const { filename: projectName } = req.params;
-13
View File
@@ -87,7 +87,6 @@ export const forgivingStringToMillis = (value: string, fillLeft = true): number
* @description Parses an excel date using the correct parser
* @param {string} excelDate
* @returns {number} - time in milliseconds
*/
export const parseExcelDate = (excelDate: unknown): number => {
if (excelDate instanceof Date) {
@@ -103,15 +102,3 @@ export const parseExcelDate = (excelDate: unknown): number => {
return 0;
};
/**
* @description Converts milliseconds to seconds -- Copied from client code
* @param {number | null} millis - time in seconds
* @returns {number} Amount in seconds
*/
export const millisToSeconds = (millis: number | null): number => {
if (millis === null) {
return 0;
}
return millis < 0 ? Math.ceil(millis / mts) : Math.floor(millis / mts);
};