Skip to content

Commit

Permalink
Get default date/time format from default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonVanAssche committed Jul 19, 2024
1 parent 33ed978 commit a7021fc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lua/date-time-inserter/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local function validate_date_format(date_format)
-- Check if the date format has the correct length.
if string.len(date_format) ~= 8 then
print("INVALID_DATE_FORMAT: Date format must be 8 characters long (e.g. MMDDYYYY).")
return "MMDDYYYY"
return settings.date_format
end

-- Check wheter the date format contains all the required characters.
Expand All @@ -32,31 +32,31 @@ local function validate_date_format(date_format)
print(
"INVALID_DATE_FORMAT: Date format must contain the characters M, D and Y (e.g. MMDDYYYY)."
)
return "MMDDYYYY"
return settings.date_format
end

-- Check if the date format contains the string 'DD' once.
if string.find(date_format, "DD") == nil then
print(
'INVALID_DATE_FORMAT: Date format must contain exactly one occurrence of the "DD" string (e.g. MMDDYYYY).'
)
return "MMDDYYYY"
return settings.date_format
end

-- Check if the date format contains the string 'MM' once.
if string.find(date_format, "MM") == nil then
print(
'INVALID_DATE_FORMAT: Date format must contain exactly one occurrence of the "MM" string (e.g. MMDDYYYY).'
)
return "MMDDYYYY"
return settings.date_format
end

-- Check if the date format contains the string 'YYYY' once.
if string.find(date_format, "YYYY") == nil then
print(
'INVALID_DATE_FORMAT: Date format must contain exactly one occurrence of the "YYYY" string (e.g. MMDDYYYY).'
)
return "MMDDYYYY"
return settings.date_format
end

return date_format
Expand All @@ -68,7 +68,7 @@ end
local function validate_time_format(time_format)
if time_format ~= 12 and time_format ~= 24 then
print("INVALID_TIME_FORMAT: Time format must be either 12 or 24.")
return 12
return settings.time_format
end

return time_format
Expand Down

0 comments on commit a7021fc

Please sign in to comment.