[Contesting] Add support for user defined date format

This commit is contained in:
Andreas Kristiansen
2025-08-28 08:02:23 +02:00
parent 5a8e3dafff
commit bf49a0250e
2 changed files with 55 additions and 3 deletions

View File

@@ -1,6 +1,17 @@
<script>
var lang_contestname_warning = "<?= __("You need to start a new session before you can change the contest name!"); ?>";
var lang_contest_reset_session = "<?= __("Are you really sure you want to start a new contest session?"); ?>";
// Get Date format
var user_date_format = "<?php
if($this->session->userdata('user_date_format')) {
// If Logged in and session exists
echo $this->session->userdata('user_date_format');
} else {
// Get Default date format from /config/wavelog.php
echo $this->config->item('qso_date_format');
}
?>";
</script>
<div class="container qso_panel contesting">

View File

@@ -895,7 +895,48 @@ function getUTCTimeStamp(el) {
function getUTCDateStamp(el) {
var now = new Date();
var localTime = now.getTime();
var utc = localTime + (now.getTimezoneOffset() * 60000);
$(el).attr('value', ("0" + now.getUTCDate()).slice(-2)+'-'+("0" + (now.getUTCMonth()+1)).slice(-2)+'-'+now.getUTCFullYear());
var day = ("0" + now.getUTCDate()).slice(-2);
var month = ("0" + (now.getUTCMonth() + 1)).slice(-2);
var year = now.getUTCFullYear();
var short_year = year.toString().slice(-2);
// Format the date based on user_date_format passed from PHP
var formatted_date;
switch (user_date_format) {
case "d/m/y":
formatted_date = day + "/" + month + "/" + short_year;
break;
case "d/m/Y":
formatted_date = day + "/" + month + "/" + year;
break;
case "m/d/y":
formatted_date = month + "/" + day + "/" + short_year;
break;
case "m/d/Y":
formatted_date = month + "/" + day + "/" + year;
break;
case "d.m.Y":
formatted_date = day + "." + month + "." + year;
break;
case "y/m/d":
formatted_date = short_year + "/" + month + "/" + day;
break;
case "Y-m-d":
formatted_date = year + "-" + month + "-" + day;
break;
case "M d, Y":
// Need to get the month name abbreviation
var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
formatted_date = monthNames[now.getUTCMonth()] + " " + parseInt(day) + ", " + year;
break;
case "M d, y":
var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
formatted_date = monthNames[now.getUTCMonth()] + " " + parseInt(day) + ", " + short_year;
break;
default:
// Default to d-m-Y format as shown in the PHP code
formatted_date = day + "-" + month + "-" + year;
}
$(el).attr('value', formatted_date);
}