From 05c7b6c3a336732262886fdd09b1929135173174 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Tue, 26 Sep 2023 15:22:57 +0300 Subject: [PATCH 1/4] Fix locale as `sv` isn't `se` https://github.com/webmin/authentic-theme/issues/1676 --- web-lib-funcs.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 164406d76..7280bdb4e 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -6272,7 +6272,8 @@ return { 'af' => 'Afrikaans', 'en-SB' => 'English (Solomon Islands)', 'en-SC' => 'English (Seychelles)', 'en-SD' => 'English (Sudan)', - 'en-SE' => 'English (Sweden)', + 'en-SV' => 'English (Sweden)', + 'en-SE' => 'English (Northern Sami)', 'en-SG' => 'English (Singapore)', 'en-SH' => 'English (St Helena)', 'en-SI' => 'English (Slovenia)', From 73b2322597c8f87f83ed7e63f5cfa8023ecd0e72 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Tue, 26 Sep 2023 19:19:21 +0300 Subject: [PATCH 2/4] Add English (United States) (military time) locale https://github.com/webmin/authentic-theme/issues/1676#issuecomment-1735466651 --- web-lib-funcs.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 7280bdb4e..fe6ecc9a2 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -2115,7 +2115,28 @@ if (!$@ && $] > 5.011) { } } } + + # Allow forcing military time + my $force_military_time; + my $locale_name_initial = $locale_name; + if ($locale_name =~ /[a-z]{2}24$/i) { + $locale_name =~ s/^(.*?)24$/$1/; + $force_military_time++; + } + # Load standard locale my $locale = DateTime::Locale->load($locale_name); + # Create a new locale out of base locale + if ($force_military_time) { + my %locale_data = $locale->locale_data; + $locale_data{'code'} = $locale_name_initial; + # Force 24h time + $locale_data{'glibc_date_1_format'} = '%a %b %e %H:%M:%S %Z %Y'; + $locale_data{'glibc_datetime_format'} = '%a %d %b %Y %T %Z'; + $locale_data{'glibc_time_format'} = '%T'; + DateTime::Locale->register_from_data(%locale_data); + # Load new locale + $locale = DateTime::Locale->load($locale_name_initial); + } my $locale_format_full_tz = $locale->glibc_date_1_format; # Sat 20 Nov 2286 17:46:39 UTC my $locale_format_full = $locale->glibc_datetime_format; # Sat 20 Nov 2286 17:46:39 my $locale_format_short = $locale->glibc_date_format; # 20/11/86 @@ -6290,6 +6311,7 @@ return { 'af' => 'Afrikaans', 'en-UG' => 'English (Uganda)', 'en-UM' => 'English (U.S. Outlying Islands)', 'en-US' => 'English (United States)', + 'en-US24' => 'English (United States) (military time)', 'en-VC' => 'English (St Vincent & the Grenadines)', 'en-VG' => 'English (British Virgin Islands)', 'en-VI' => 'English (U.S. Virgin Islands)', From 4e54ce3f85c69d76ad41dbe6798ae0c479d81f63 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Tue, 26 Sep 2023 21:22:44 +0300 Subject: [PATCH 3/4] Fix to correctly cache cloned locale with military time --- web-lib-funcs.pl | 51 ++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index fe6ecc9a2..c33ba14cf 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -2091,6 +2091,7 @@ code or preserve the original, old logic sub make_date { my ($secs, $only, $fmt) = @_; +state $locale_military_name; $secs ||= 0; eval "use DateTime; use DateTime::Locale; use DateTime::TimeZone;"; if (!$@ && $] > 5.011) { @@ -2115,18 +2116,24 @@ if (!$@ && $] > 5.011) { } } } - - # Allow forcing military time - my $force_military_time; + # Pre-process time locale + my $locale_military_status = sub { + return ($locale_military_name && $locale_military_name =~ /[a-z]/i) ? 2 : + ($locale_military_name == 1) ? 1 : 0; + }; + # Allow locales with military time (in 24h format) + my $locale_name_loaded = &$locale_military_status() == 2 ? + $locale_military_name : $locale_name; my $locale_name_initial = $locale_name; - if ($locale_name =~ /[a-z]{2}24$/i) { + if ($locale_name =~ /[a-z]{2}24$/i && &$locale_military_status() == 0) { $locale_name =~ s/^(.*?)24$/$1/; - $force_military_time++; - } - # Load standard locale - my $locale = DateTime::Locale->load($locale_name); + $locale_name_loaded = $locale_name; + $locale_military_name = 1; + } + # Load given locale + my $locale = DateTime::Locale->load($locale_name_loaded); # Create a new locale out of base locale - if ($force_military_time) { + if (&$locale_military_status() == 1) { my %locale_data = $locale->locale_data; $locale_data{'code'} = $locale_name_initial; # Force 24h time @@ -2134,9 +2141,11 @@ if (!$@ && $] > 5.011) { $locale_data{'glibc_datetime_format'} = '%a %d %b %Y %T %Z'; $locale_data{'glibc_time_format'} = '%T'; DateTime::Locale->register_from_data(%locale_data); - # Load new locale - $locale = DateTime::Locale->load($locale_name_initial); - } + # Load newly cloned locale in 24h time format + $locale_military_name = $locale_name_loaded = $locale_name_initial; + $locale = DateTime::Locale->load($locale_name_loaded); + } + my $locale_format_full_tz = $locale->glibc_date_1_format; # Sat 20 Nov 2286 17:46:39 UTC my $locale_format_full = $locale->glibc_datetime_format; # Sat 20 Nov 2286 17:46:39 my $locale_format_short = $locale->glibc_date_format; # 20/11/86 @@ -2171,15 +2180,15 @@ if (!$@ && $] > 5.011) { # my $xxxx = $locale->full_date_format; my $data = { # Wed Feb 8 05:09:39 PM UTC 2023 - 'full-tz-utc' => DateTime->from_epoch(locale => $locale_name, epoch => $secs)->strftime($locale_format_full_tz), + 'full-tz-utc' => DateTime->from_epoch(locale => $locale_name_loaded, epoch => $secs)->strftime($locale_format_full_tz), # Wed Feb 8 07:10:01 PM EET 2023 - 'full-tz' => DateTime->from_epoch(locale => $locale_name, epoch => $secs, time_zone => $tz)->strftime($locale_format_full_tz), + 'full-tz' => DateTime->from_epoch(locale => $locale_name_loaded, epoch => $secs, time_zone => $tz)->strftime($locale_format_full_tz), # Wed 08 Feb 2023 07:11:26 PM EET - 'full' => DateTime->from_epoch(locale => $locale_name, epoch => $secs, time_zone => $tz)->strftime($locale_format_full), + 'full' => DateTime->from_epoch(locale => $locale_name_loaded, epoch => $secs, time_zone => $tz)->strftime($locale_format_full), # 02/08/2023 - 'short' => DateTime->from_epoch(locale => $locale_name, epoch => $secs, time_zone => $tz)->strftime($locale_format_short), + 'short' => DateTime->from_epoch(locale => $locale_name_loaded, epoch => $secs, time_zone => $tz)->strftime($locale_format_short), # 07:12:07 PM - 'time' => DateTime->from_epoch(locale => $locale_name, epoch => $secs, time_zone => $tz)->strftime($locale_format_time), + 'time' => DateTime->from_epoch(locale => $locale_name_loaded, epoch => $secs, time_zone => $tz)->strftime($locale_format_time), 'ago' => $ago, 'tz' => $tz, 'delimiter' => $locale_format_delimiter, @@ -2192,8 +2201,8 @@ if (!$@ && $] > 5.011) { # %c alternative with full week and month and no seconds in time (complete) # Wednesday, February 8, 2023, 8:18 PM or 星期三, 2023年2月8日 20:18 or miércoles, 8 febrero 2023, 20:28 - $data->{'monthfull'} = DateTime->from_epoch(locale => $locale_name, epoch => $secs, time_zone => $tz)->strftime("%B"); - foreach (split(/\s+/, DateTime->from_epoch(locale => $locale_name, epoch => $secs, time_zone => $tz)->strftime("%A, %c"))) { + $data->{'monthfull'} = DateTime->from_epoch(locale => $locale_name_loaded, epoch => $secs, time_zone => $tz)->strftime("%B"); + foreach (split(/\s+/, DateTime->from_epoch(locale => $locale_name_loaded, epoch => $secs, time_zone => $tz)->strftime("%A, %c"))) { if ($data->{'monthfull'} =~ /^$_/) { $data->{'complete'} .= "$data->{'monthfull'} " } @@ -2228,12 +2237,12 @@ if (!$@ && $] > 5.011) { @date = grep { /\%/ } @date; $locale_format_short = join($locale_format_delimiter, @date); } - my $date_format_short = DateTime->from_epoch(locale => $locale_name, epoch => $secs, time_zone => $tz)->strftime($locale_format_short); + my $date_format_short = DateTime->from_epoch(locale => $locale_name_loaded, epoch => $secs, time_zone => $tz)->strftime($locale_format_short); if (!ref($only) && $only) { return $date_format_short; } else { - my $date_format_time = DateTime->from_epoch(locale => $locale_name, epoch => $secs, time_zone => $tz)->strftime($locale_format_time); + my $date_format_time = DateTime->from_epoch(locale => $locale_name_loaded, epoch => $secs, time_zone => $tz)->strftime($locale_format_time); $date_format_time = $date_format_time; $date_format_time =~ s/(\d+):(\d+):(\d+)(.*?)/$1:$2$4/; if ($main::webmin_script_type eq 'web') { From 0289ceed5bb95da2e1b044960c3301eb4e63c8d5 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Tue, 26 Sep 2023 21:24:12 +0300 Subject: [PATCH 4/4] Fix indent [build] --- web-lib-funcs.pl | 1 - 1 file changed, 1 deletion(-) diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index c33ba14cf..3b43f9004 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -2145,7 +2145,6 @@ if (!$@ && $] > 5.011) { $locale_military_name = $locale_name_loaded = $locale_name_initial; $locale = DateTime::Locale->load($locale_name_loaded); } - my $locale_format_full_tz = $locale->glibc_date_1_format; # Sat 20 Nov 2286 17:46:39 UTC my $locale_format_full = $locale->glibc_datetime_format; # Sat 20 Nov 2286 17:46:39 my $locale_format_short = $locale->glibc_date_format; # 20/11/86