From 7071879ae5384a62dac5d6cbb2fb5f72c114f41b Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Fri, 20 Dec 2019 11:58:31 +0530 Subject: [PATCH] fix: Better date format options with label --- .../doctype/SystemSettings/SystemSettings.js | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/models/doctype/SystemSettings/SystemSettings.js b/models/doctype/SystemSettings/SystemSettings.js index 5e352159..8b1af28f 100644 --- a/models/doctype/SystemSettings/SystemSettings.js +++ b/models/doctype/SystemSettings/SystemSettings.js @@ -1,3 +1,26 @@ +const { DateTime } = require('luxon'); + +let dateFormatOptions = (() => { + let formats = [ + 'dd/MM/yyyy', + 'MM/dd/yyyy', + 'dd-MM-yyyy', + 'MM-dd-yyyy', + 'yyyy-MM-dd', + 'd MMM, y', + 'MMM d, y' + ]; + + let today = DateTime.local(); + + return formats.map(format => { + return { + label: today.toFormat(format), + value: format + }; + }); +})(); + module.exports = { name: 'SystemSettings', label: 'System Settings', @@ -10,15 +33,7 @@ module.exports = { fieldname: 'dateFormat', label: 'Date Format', fieldtype: 'Select', - options: [ - 'dd/MM/yyyy', - 'MM/dd/yyyy', - 'dd-MM-yyyy', - 'MM-dd-yyyy', - 'yyyy-MM-dd', - 'd MMM, y', - 'MMM d, y' - ], + options: dateFormatOptions, default: 'MMM d, y', required: 1 }, @@ -29,6 +44,6 @@ module.exports = { options: ['2', '3', '4', '5'], default: '2', required: 1 - }, + } ] };