Moved processDate function to utils

This commit is contained in:
Alexander Cerutti
2021-10-10 02:49:17 +02:00
parent 57c3876f96
commit a052858950
3 changed files with 17 additions and 20 deletions

View File

@@ -3,10 +3,9 @@ import { default as Bundle, filesSymbol } from "./Bundle";
import { getModelFolderContents } from "./parser";
import * as Schemas from "./schemas";
import { Stream } from "stream";
import { processDate } from "./processDate";
import * as Signature from "./Signature";
import * as Strings from "./StringsUtils";
import { isValidRGB } from "./utils";
import { isValidRGB, processDate } from "./utils";
/** Exporting for tests specs */
export const propsSymbol = Symbol("props");

View File

@@ -1,17 +0,0 @@
import { dateToW3CString } from "./utils";
import formatMessage, { ERROR, DEBUG } from "./messages";
export function processDate(key: string, date: Date): string | null {
if (!(date instanceof Date)) {
return null;
}
const dateParse = dateToW3CString(date);
if (!dateParse) {
console.warn(formatMessage(DEBUG.DATE_FORMAT_UNMATCH, key));
return null;
}
return dateParse;
}

View File

@@ -26,6 +26,21 @@ export function isValidRGB(value?: string): boolean {
return rgb.slice(1, 4).every((v) => Math.abs(Number(v)) <= 255);
}
export function processDate(key: string, date: Date): string | null {
if (!(date instanceof Date)) {
return null;
}
const dateParse = dateToW3CString(date);
if (!dateParse) {
console.warn(formatMessage(DEBUG.DATE_FORMAT_UNMATCH, key));
return null;
}
return dateParse;
}
/**
* Converts a date to W3C Standard format
*
@@ -35,7 +50,7 @@ export function isValidRGB(value?: string): boolean {
* undefined otherwise
*/
export function dateToW3CString(date: Date) {
function dateToW3CString(date: Date) {
if (!(date instanceof Date)) {
return "";
}