Fix time formatting

This commit is contained in:
Elio Struyf
2021-10-25 10:11:31 +02:00
parent f500749644
commit a7aab96f0e
5 changed files with 10 additions and 6 deletions
+2 -2
View File
@@ -172,7 +172,7 @@ export class Article {
let newFileName = `${slugName}${ext}`;
if (filePrefix && typeof filePrefix === "string") {
newFileName = `${format(new Date(), DateHelper.formatUpdate(filePrefix))}-${newFileName}`;
newFileName = `${format(new Date(), DateHelper.formatUpdate(filePrefix) as string)}-${newFileName}`;
}
const newPath = editor.document.uri.fsPath.replace(fileName, newFileName);
@@ -244,7 +244,7 @@ export class Article {
const dateFormat = Settings.get(SETTING_DATE_FORMAT) as string;
if (dateFormat && typeof dateFormat === "string") {
return format(dateValue, DateHelper.formatUpdate(dateFormat));
return format(dateValue, DateHelper.formatUpdate(dateFormat) as string);
} else {
return typeof dateValue.toISOString === 'function' ? dateValue.toISOString() : dateValue?.toString();
}
+1 -1
View File
@@ -35,7 +35,7 @@ export class Preview {
if (settings.pathname) {
const articleDate = ArticleHelper.getDate(article);
try {
slug = join(format(articleDate || new Date(), DateHelper.formatUpdate(settings.pathname)), slug);
slug = join(format(articleDate || new Date(), DateHelper.formatUpdate(settings.pathname) as string), slug);
} catch (error) {
slug = join(settings.pathname, slug);
}
+1 -1
View File
@@ -204,7 +204,7 @@ export class ArticleHelper {
let newFileName = `${sanitizedName}.md`;
if (prefix && typeof prefix === "string") {
newFileName = `${format(new Date(), DateHelper.formatUpdate(prefix))}-${newFileName}`;
newFileName = `${format(new Date(), DateHelper.formatUpdate(prefix) as string)}-${newFileName}`;
}
newFilePath = join(folderPath, newFileName);
+5 -1
View File
@@ -3,7 +3,11 @@ import { parse, parseISO, parseJSON } from "date-fns";
export class DateHelper {
public static formatUpdate(value: string) {
public static formatUpdate(value: string | null | undefined): string | null {
if (!value) {
return null;
}
value = value.replace(/YYYY/g, 'yyyy');
value = value.replace(/DD/g, 'dd');
return value;
@@ -52,7 +52,7 @@ export const DateTimeField: React.FunctionComponent<IDateTimeFieldProps> = ({lab
selected={dateValue as Date || new Date()}
onChange={onDateChange}
timeInputLabel="Time:"
dateFormat={format || "MM/dd/yyyy HH:mm"}
dateFormat={DateHelper.formatUpdate(format) || "MM/dd/yyyy HH:mm"}
customInput={(<CustomInput />)}
showTimeInput
/>