LEPTON CMS 7.4.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
lepton_date.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
20// @ADD_date 20250117, replaces lib_lepton_datetools
21class LEPTON_date
22{
23 public const SYSTEM_DEFAULT_STR = 'System Default';
24
32 public static $instance;
33
42 public string $format = "%d.%m.%Y";
43
44 public string $sINTLFormat = "d.M.yyyy";
45
54 public array $lang = ['de_DE@euro', 'de_DE.UTF-8', 'de_DE', 'de', 'ge'];
55
63 public string $mode = "LC_ALL";
64
75 public int $force_year = 2;
76
84 public array $CORE_date_formats_PHP = [
85 'l, jS F, Y'=> '%A, %e %B, %Y',
86 'jS F, Y' => '%e %B, %Y',
87 'd M Y' => '%d %a %Y',
88 'M d Y' => '%a %d %Y',
89 'D M d, Y' => '%a %b %d, %Y', ##
90 'd-m-Y' => '%d-%m-%Y', #1
91 'm-d-Y' => '%m-%d-%Y',
92 'd.m.Y' => '%d.%m.%Y', #2
93 'm.d.Y' => '%m.%d.%Y',
94 'd/m/Y' => '%d/%m/%Y', #3
95 'm/d/Y' => '%m/%d/%Y',
96 'j.n.Y' => '%e.%n.%Y' #4! Day in month without leading zero
97 ];
98
106 public array $CORE_date_formats_MYSQL = [
107 'l, jS F, Y'=> '%W, %D %M, %Y', // 1
108 'jS F, Y' => '%D %M, %Y', // 2
109 'd M Y' => '%e. %M %Y', // 3 e.g. 24. Juli 2022
110 'M d Y' => '%b %e %Y', // 4
111 'D M d, Y' => '%a %b %e, %Y', // 5 *
112 'd-m-Y' => '%d-%m-%Y', // 6
113 'm-d-Y' => '%m-%d-%Y', // 7
114 'd.m.Y' => '%d.%m.%Y', // 8
115 'm.d.Y' => '%m.%d.%Y', // 9
116 'd/m/Y' => '%d/%m/%Y', // 10
117 'm/d/Y' => '%m/%d/%Y', // 11
118 'j.n.Y' => '%e.%c.%Y', // 12 Day in month without leading zero
119 'Y-m-d' => '%Y-%m-%d', // L* 7.4
120 'Y.m.d' => '%Y.%m.%d' // L* 7.4
121 ];
122
130 public array $CORE_time_formats_PHP = [
131 'g:i A' => '%I:%M %p',
132 'g:i a' => '%I:%M %P',
133 'H:i:s' => '%H:%M:%S',
134 'H:i' => '%H:%M'
135 ];
136
144 public array $CORE_time_formats_MYSQL = [
145 'g:i A' => '%l:%i %p', // Uppercase Ante meridiem and Post meridiem
146 'g:i a' => '%r %p',
147 'H:i:s' => '%H:%i:%s', // 3
148 'H:i' => '%H:%i' // 4
149 ];
150
158 public array $CORE_date_formats_DatePicker = [
159 'l, jS F, Y'=> 'DD, d. MM yy', //'A, e B, yy',
160 'jS F, Y' => 'd. MM, yy', // 1
161 'd M Y' => 'd. MM yy', // 2
162 'M d Y' => 'M d yy',
163 'D M d, Y' => 'D M d, yy', // *!
164 'd-m-Y' => 'd-m-yy', // 3
165 'm-d-Y' => 'm-d-yy',
166 'd.m.Y' => 'd.m.yy', // 4
167 'm.d.Y' => 'm.d.yy',
168 'Y-m-d' => 'yy-mm-dd', // lepton 7.4
169 'Y.m.d' => 'yy.mm.dd', // lepton 7.4
170 'd/m/Y' => 'd/m/yy', // 5
171 'm/d/Y' => 'm/d/yy',
172 'j.n.Y' => 'd.m.yy' // 6! Day in month without leading zero
173 ];
174
185 public bool $useINTL = false;
186 public bool $intl_installed = false;
187
195 public array $CORE_date_formats_INTL = [
196 'l, jS F, Y'=> 'A, e B, yyyy',
197 'jS F, Y' => 'e B, yyyy', // 1
198 'd M Y' => 'd M yyyy',
199 'M d Y' => 'M d yyyy',
200 'D M d, Y' => 'EE d MM, yyyy', // 'a m d, yy',
201 'd-m-Y' => 'd-M-yy', // 3
202 'm-d-Y' => 'M-d-yy',
203 'd.m.Y' => 'd.M.yy', // 4
204 'm.d.Y' => 'M.d.yy',
205 'd/m/Y' => 'd/M/yy', // 5
206 'm/d/Y' => 'M/d/yy',
207 'j.n.Y' => 'd.M.yyyy' // 6! Day in month without leading zero
208 ];
209
214 public const MYSQL_LOCALES = [
215 "ar_AE" => "Arabic - United Arab Emirates",
216 "ar_BH" => "Arabic - Bahrain",
217 "ar_DZ" => "Arabic - Algeria",
218 "ar_EG" => "Arabic - Egypt",
219 "ar_IN" => "Arabic - India",
220 "ar_IQ" => "Arabic - Iraq",
221 "ar_JO" => "Arabic - Jordan",
222 "ar_KW" => "Arabic - Kuwait",
223 "ar_LB" => "Arabic - Lebanon",
224 "ar_LY" => "Arabic - Libya",
225 "ar_MA" => "Arabic - Morocco",
226 "ar_OM" => "Arabic - Oman",
227 "ar_QA" => "Arabic - Qatar",
228 "ar_SA" => "Arabic - Saudi Arabia",
229 "ar_SD" => "Arabic - Sudan",
230 "ar_SY" => "Arabic - Syria",
231 "ar_TN" => "Arabic - Tunisia",
232 "ar_YE" => "Arabic - Yemen",
233 "be_BY" => "Belarusian - Belarus",
234 "bg_BG" => "Bulgarian - Bulgaria",
235 "ca_ES" => "Catalan - Spain",
236 "cs_CZ" => "Czech - Czech Republic",
237 "da_DK" => "Danish - Denmark",
238 "de_AT" => "German - Austria",
239 "de_BE" => "German - Belgium",
240 "de_CH" => "German - Switzerland",
241 "de_DE" => "German - Germany",
242 "de_LU" => "German - Luxembourg",
243 "el_GR" => "Greek - Greece",
244 "en_AU" => "English - Australia",
245 "en_CA" => "English - Canada",
246 "en_GB" => "English - United Kingdom",
247 "en_IN" => "English - India",
248 "en_NZ" => "English - New Zealand",
249 "en_PH" => "English - Philippines",
250 "en_US" => "English - United States",
251 "en_ZA" => "English - South Africa",
252 "en_ZW" => "English - Zimbabwe",
253 "es_AR" => "Spanish - Argentina",
254 "es_BO" => "Spanish - Bolivia",
255 "es_CL" => "Spanish - Chile",
256 "es_CO" => "Spanish - Colombia",
257 "es_CR" => "Spanish - Costa Rica",
258 "es_DO" => "Spanish - Dominican Republic",
259 "es_EC" => "Spanish - Ecuador",
260 "es_ES" => "Spanish - Spain",
261 "es_GT" => "Spanish - Guatemala",
262 "es_HN" => "Spanish - Honduras",
263 "es_MX" => "Spanish - Mexico",
264 "es_NI" => "Spanish - Nicaragua",
265 "es_PA" => "Spanish - Panama",
266 "es_PE" => "Spanish - Peru",
267 "es_PR" => "Spanish - Puerto Rico",
268 "es_PY" => "Spanish - Paraguay",
269 "es_SV" => "Spanish - El Salvador",
270 "es_US" => "Spanish - United States",
271 "es_UY" => "Spanish - Uruguay",
272 "es_VE" => "Spanish - Venezuela",
273 "et_EE" => "Estonian - Estonia",
274 "eu_ES" => "Basque - Spain",
275 "fi_FI" => "Finnish - Finland",
276 "fo_FO" => "Faroese - Faroe Islands",
277 "fr_BE" => "French - Belgium",
278 "fr_CA" => "French - Canada",
279 "fr_CH" => "French - Switzerland",
280 "fr_FR" => "French - France",
281 "fr_LU" => "French - Luxembourg",
282 "gl_ES" => "Galician - Spain",
283 "gu_IN" => "Gujarati - India",
284 "he_IL" => "Hebrew - Israel",
285 "hi_IN" => "Hindi - India",
286 "hr_HR" => "Croatian - Croatia",
287 "hu_HU" => "Hungarian - Hungary",
288 "id_ID" => "Indonesian - Indonesia",
289 "is_IS" => "Icelandic - Iceland",
290 "it_CH" => "Italian - Switzerland",
291 "it_IT" => "Italian - Italy",
292 "ja_JP" => "Japanese - Japan",
293 "ko_KR" => "Korean - Republic of Korea",
294 "lt_LT" => "Lithuanian - Lithuania",
295 "lv_LV" => "Latvian - Latvia",
296 "mk_MK" => "Macedonian - North Macedonia",
297 "mn_MN" => "Mongolia - Mongolian",
298 "ms_MY" => "Malay - Malaysia",
299 "nb_NO" => "Norwegian(Bokmål) - Norway",
300 "nl_BE" => "Dutch - Belgium",
301 "nl_NL" => "Dutch - The Netherlands",
302 "no_NO" => "Norwegian - Norway",
303 "pl_PL" => "Polish - Poland",
304 "pt_BR" => "Portugese - Brazil",
305 "pt_PT" => "Portugese - Portugal",
306 "rm_CH" => "Romansh - Switzerland",
307 "ro_RO" => "Romanian - Romania",
308 "ru_RU" => "Russian - Russia",
309 "ru_UA" => "Russian - Ukraine",
310 "sk_SK" => "Slovak - Slovakia",
311 "sl_SI" => "Slovenian - Slovenia",
312 "sq_AL" => "Albanian - Albania",
313 "sr_RS" => "Serbian - Serbia",
314 "sv_FI" => "Swedish - Finland",
315 "sv_SE" => "Swedish - Sweden",
316 "ta_IN" => "Tamil - India",
317 "te_IN" => "Telugu - India",
318 "th_TH" => "Thai - Thailand",
319 "tr_TR" => "Turkish - Turkey",
320 "uk_UA" => "Ukrainian - Ukraine",
321 "ur_PK" => "Urdu - Pakistan",
322 "vi_VN" => "Vietnamese - Vietnam",
323 "zh_CN" => "Chinese - China",
324 "zh_HK" => "Chinese - Hong Kong",
325 "zh_TW" => "Chinese - Taiwan"
326 ];
327
335 public static function getInstance(bool $bUseINTL = false): object
336 {
337 if (null === static::$instance) {
338 static::$instance = new static();
339 }
340 static::$instance->useINTL = $bUseINTL;
341
342 if (true === $bUseINTL)
343 {
344 static::$instance->intl_installed = static::$instance->checkINTLExtensionExists();
345 }
346
347 return static::$instance;
348 }
349
353 protected function __construct ()
354 {
355 // nothing
356 }
357
364 public function addLanguage ($aString=""): bool
365 {
366 if ($aString == "") {
367 return false;
368 }
369 if (false === in_array($aString, $this->lang)) {
370 $this->lang[] = $aString;
371 }
372 return true;
373 }
374
381 public function setFormat( string $aString="" ): bool
382 {
383 if($this->useINTL)
384 {
385 $this->sINTLFormat = $aString;
386 } else {
387 $this->format=$aString;
388 }
389 return true;
390 }
391
403 public function toHTML(int $iTimestamp = 0 ): string
404 {
405 if (NULL == $iTimestamp)
406 {
407 $iTimestamp = TIME();
408 }
409
410 $aTempLocale = setlocale(LC_ALL, $this->lang);
411 if (false === $aTempLocale)
412 {
413 $aTempLocale = setlocale(LC_ALL, 0);
414 }
415
416 if ((true === $this->useINTL) && (true === $this->intl_installed))
417 {
418 $fmt = datefmt_create(
419 $aTempLocale, // 'de-DE',
420 IntlDateFormatter::FULL,
421 IntlDateFormatter::FULL,
422 DEFAULT_TIMEZONE_STRING, // 'Europe/Berlin',
423 IntlDateFormatter::GREGORIAN,
424 $this->sINTLFormat
425 //$this->format // "yyyy.MM.dd G 'um' HH:mm:ss zzz" // "MMMM | d | y | H"
426 );
427 if (is_null($fmt))
428 {
429 // Huston: we've got a problem!
430 $this->useINTL = false;
431 return date($this->format, $iTimestamp);
432 }
433 else
434 {
435 $sFormatedDate = datefmt_format($fmt, $iTimestamp );
436 // echo LEPTON_tools::display_dev($this->sINTLFormat, "pre", "ui message", true);
437 return $sFormatedDate;
438 }
439 } else {
445 if (class_exists("IntlDateFormatter"))
446 {
447 $oTempFormatter = new IntlDateFormatter(
448 $aTempLocale, // 'en_US',
449 IntlDateFormatter::LONG,
450 IntlDateFormatter::NONE,
451 DEFAULT_TIMEZONE_STRING, // 1 timezone
452 IntlDateFormatter::GREGORIAN, // 2 calendar
453 $this->sINTLFormat // 3 format
454 );
455
456 return $oTempFormatter->format($iTimestamp);
457 }
458 else
459 {
460 // Aldus 2025-01-19: Aldus fix for the "%"-char in format!
461 // This is a more thoretical problem at all.
462 echo "HOUSTON";
463 return date(str_replace("%", "",$this->format), $iTimestamp);
464 }
465 }
466 }
467
478 public function setLanguage(array $aArray = []): bool
479 {
480 $this->lang = [];
481 foreach ($aArray as $a)
482 {
483 $this->lang[] = $a;
484 }
485 return true;
486 }
487
505 public function transform (string $aDateString = "01.01.1971", string $aFormat="dmy"): string
506 {
507 $this->_force_date ($aDateString);
508 $this->_force_format ($aFormat);
509
510 $temp = explode(".", $aDateString);
511 $temp = array_map(
512 function ($a) {
513 return intval($a);
514 },
515 $temp
516 );
517 switch ($aFormat)
518 {
519 case 'dmy':
520 $this->_force_year($temp[2]);
521 $temp_time = mktime( 1, 0, 0, $temp[1], $temp[0], $temp[2]);
522 break;
523
524 case 'mdy':
525 $this->_force_year($temp[2]);
526 $temp_time = mktime( 1, 0, 0, $temp[0], $temp[1], $temp[2]);
527 break;
528
529 case 'ymd':
530 $this->_force_year($temp[0]);
531 $temp_time = mktime( 1, 0, 0, $temp[1], $temp[2], $temp[0]);
532 break;
533
541 default:
542 $temp_time = time();
543 break;
544 }
545 return $this->toHTML($temp_time);
546 }
547
563 private function _force_date(string &$aDateString ): void
564 {
565 $pattern = ["*[\\/|.|-]+*"];
566 $replace = ["."];
567
568 $aDateString = preg_replace($pattern, $replace, $aDateString);
569 }
570
582 private function _force_format(string &$aFormat): void
583 {
584
585 $aFormat = strtolower ($aFormat);
586
587 $pattern = ["*[\\/|.|-]+*", "*[ |%]+*"];
588 $replace = ["", ""];
589
590 $aFormat = preg_replace($pattern, $replace, $aFormat);
591 }
592
602 private function _force_year(string|int &$aYearStr = "1971"): void
603 {
604 $aYearStr = (string) $aYearStr;
605
606 if (strlen($aYearStr) == 2)
607 {
608 $aYearStr = (((int) $aYearStr > $this->force_year + (int) DATE("y", TIME())) ? "19" : "20").$aYearStr;
609 }
610 if (strlen($aYearStr) > 4)
611 {
612 $aYearStr = substr($aYearStr, 0, 4);
613 }
614
615 $aYearStr = intval($aYearStr);
616 }
617
625 public function parse_string (string &$aStr = "", string $aPattern = "/([0-3][0-9].[01]{0,1}[0-9].[0-9]{2,4})/s"): void
626 {
627 $found=[];
628 preg_match_all($aPattern, $aStr, $found );
629 foreach ($found[1] as $a)
630 {
631 $aStr = str_replace($a, $this->transform($a), $aStr);
632 }
633 }
634
643 public function set_core_language(string $aKeyStr = ""): bool
644 {
645
646 $return_value = true;
647
648 switch ($aKeyStr)
649 {
650
651 case "DE":
652 $this->lang = ['de_DE.UTF-8', 'de_DE@euro', 'de_DE', 'de', 'ge'];
653 break;
654
655 case "EN":
656 $this->lang = ['en_EN@euro', 'en_EN', 'en', 'EN', 'en_UK', 'UK', 'en_US', 'en_GB', 'en_CA'];
657 break;
658
659 case "FR":
660 $this->lang = ['FR', 'fr_FR.UTF-8', 'fr_FR', 'fr_FR@euro', 'fr'];
661 break;
662
663 case "IT":
664 $this->lang = ['it_IT@euro', 'it_IT', 'it'];
665 break;
666
667 case "NL":
668 $this->lang = ['nl_NL@euro', 'nl_NL', 'nl', 'Dutch', 'nld_nld'];
669 break;
670
671 case "RU":
672 $this->lang = ['RU', 'ru_RU.UTF-8', 'ru_RU', 'ru_RU@euro', 'ru'];
673 break;
674
675 case "ZH":
676 $this->lang = ['zh_CN','zh_CN.eucCN','zh_CN.GB18030','zh_CN.GB2312','zh_CN.GBK','zh_CN.UTF-8','zh_HK','zh_HK.Big5HKSCS','zh_HK.UTF-8','zh_TW','zh_TW.Big5','zh_TW.UTF-8'];
677 break;
678
679 default:
680 $this->test_locale($aKeyStr);
681 break;
682 }
683 return $return_value;
684 }
685
700 public function test_locale (string $aKey = "de_DE", bool $use_it = true): array
701 {
702 if (strlen($aKey) == 2)
703 {
704 $aKey = strtolower($aKey)."_".strtoupper($aKey);
705 }
706
707 $temp_array = [];
708 ob_start();
709 exec('locale -a', $temp_array);
710 ob_end_flush();
711 $all = [];
712
713 foreach($temp_array as $lang_key)
714 {
715 if (substr($lang_key, 0,5) == $aKey)
716 {
717 $all[]=$lang_key;
718 }
719 }
720
721 if (!empty($all) && (true === $use_it))
722 {
723 $this->lang = $all;
724 }
725 return $all;
726 }
727
735 public function formatToDatepicker(string $sFormatString = ""): string
736 {
737 if (isset($this->CORE_date_formats_DatePicker[$sFormatString])) {
738 return $this->CORE_date_formats_DatePicker[$sFormatString];
739 } elseif (isset($this->CORE_date_formats_DatePicker[DATE_FORMAT])) {
740 return $this->CORE_date_formats_DatePicker[DATE_FORMAT];
741 } else {
742 return "";
743 }
744 }
745
754 public function calendarToTimestamp(string $str = "", int $offset = 0): int
755 {
756 $str = trim($str);
757 if ($str == '0' || $str == '')
758 {
759 return 0;
760 }
761
762 // convert to yyyy-mm-dd
763 // "dd.mm.yyyy"?
764 if(preg_match('/^\d{1,2}\.\d{1,2}\.\d{2}(\d{2})?/', $str)) {
765 $str = preg_replace('/^(\d{1,2})\.(\d{1,2})\.(\d{2}(\d{2})?)/', '$3-$2-$1', $str);
766 }
767
768 // "mm/dd/yyyy"?
769 if(preg_match('#^\d{1,2}/\d{1,2}/(\d{2}(\d{2})?)#', $str)) {
770 $str = preg_replace('#^(\d{1,2})/(\d{1,2})/(\d{2}(\d{2})?)#', '$3-$1-$2', $str);
771 }
772
773 // use strtotime()
774 if ($offset != 0)
775 {
776 return (strtotime($str, $offset));
777 }
778 else
779 {
780 return strtotime($str);
781 }
782 }
783
789 public function detectPageLanguage() : array
790 {
791 // [1] $_GET
792 $sTempCurrentPageLanguage = ($_GET["lang"] ?? NULL);
793
794 // [1.1] none found - page-language?
795 if (is_null($sTempCurrentPageLanguage))
796 {
797 $sTempCurrentPageLanguage = LEPTON_frontend::getInstance()->page['language'];
798 }
799
800 // [2]
801 $sBasic = strtolower($sTempCurrentPageLanguage)."_".strtoupper($sTempCurrentPageLanguage);
802
803 // [3]
804 return [
805 $sBasic,
806 $sBasic.".UTF-8",
807 $sBasic."@euro"
808 ];
809 }
810
816 public function checkINTLExtensionExists() : bool
817 {
818 $aAllExtensions = get_loaded_extensions();
819 if (!in_array("intl", $aAllExtensions))
820 {
821 return false;
822 }
823 return true;
824 }
825
838 public function formatWithMySQL(string $format = DEFAULT_DATE_FORMAT, int|null $timestamp = null, string $optionalLang = "" ): string|null
839 {
840 if ($timestamp === null)
841 {
842 $timestamp = time();
843 }
844
845 $sRealFormat = $this->CORE_date_formats_MYSQL[$format] ?? $format;
846
847 $tempLang = self::buildLanguageKey(
848 (empty($optionalLang)
849 ? LANGUAGE
850 : $optionalLang
851 )
852 );
853
855
856 if ($tempLang !== "en_EN")
857 {
858 $database->simple_query("SET lc_time_names = '".$tempLang."';");
859 }
860 else
861 {
862 $database->simple_query("SET lc_time_names = 'en_gb';");
863 }
864
865 // see: https://www.epochconverter.com/programming/mysql
866 $sQuery = ($timestamp < 0)
867 ? "SELECT DATE_FORMAT( DATE_ADD(FROM_UNIXTIME(0), interval " . $timestamp . " second),'" . $sRealFormat . "');"
868 : "SELECT DATE_FORMAT( FROM_UNIXTIME(" . $timestamp . "),'" . $sRealFormat . "');"
869 ;
870
871 return $database->get_one($sQuery);
872 }
873
883 static function buildLanguageKey(string $key = LANGUAGE): string
884 {
885 if (preg_match("~^[a-z]{2}_[A-Z]{2}$~", $key)) {
886 // given string is "in correct form"
887 return $key;
888 } elseif (strlen($key) >= 2) {
889 // more than two chars - use the first two ones
890 $key = substr(trim($key), 0, 2);
891 return strtolower($key) . "_" . strtoupper($key);
892 } else {
893 return "Error: need at least two chars for key! One given!";
894 }
895 }
896
941 public function getWeekdayNames(string $sLanguage, bool $bAbbreviated = false): array
942 {
943 $returnValue = [];
944
945 // Der 5. Januar 1970 war ein Montag.
946 $tag = 5;
947 $monat = 1;
948 $jahr = 1970;
949
950 $stunde = 1;
951 $minute = 0;
952 $sekunde = 0;
953
954 for ($i = 0; $i < 7; $i++)
955 {
956 $iTimestamp = mktime($stunde, $minute, $sekunde, $monat, $tag+$i, $jahr);
957 $returnValue[$i+1] = $this->formatWithMySQL(($bAbbreviated ? "%a" : "%W"), $iTimestamp, $sLanguage);
958 }
959
960 return $returnValue;
961 }
962
973 public function getMonthNames(string $sLanguage, bool $bAbbreviated = false): array
974 {
975 $returnValue = [];
976
977 // Der 5. Januar 1970 war ein Montag.
978 $tag = 5;
979 // $monat = 1;
980 $jahr = 1970;
981
982 $stunde = 1;
983 $minute = 0;
984 $sekunde = 0;
985
986 for ($monat = 1; $monat <= 12; $monat++)
987 {
988 $iTimestamp = mktime($stunde, $minute, $sekunde, $monat, $tag, $jahr);
989 $returnValue[$monat] = $this->formatWithMySQL(($bAbbreviated ? "%b" : "%M"), $iTimestamp, $sLanguage);
990 }
991
992 return $returnValue;
993 }
994
995 public function getLocaleList(): array
996 {
997 return self::MYSQL_LOCALES;
998 }
999
1000########################################### will replace code from LEPTON_basics ###########################################
1001// @ADD_date 20250117, replaces lepton_basics
1002
1010 static function get_dateformats(): array
1011 {
1012 global $user_time;
1013 global $TEXT;
1014
1015 // Get the current time (in the users timezone if required)
1016 $actual_time = time();
1017
1018 // Get "System Default"
1019 $sSystemDefault = "";
1020 if (isset($user_time) && $user_time === true)
1021 {
1022 $sSystemDefault = date(DEFAULT_DATE_FORMAT, $actual_time).' (';
1023 $sSystemDefault .= ($TEXT['SYSTEM_DEFAULT'] ?? self::SYSTEM_DEFAULT_STR).')';
1024 }
1025
1026 // Add values to list
1027 $DATE_FORMATS = [
1028 'system_default' => $sSystemDefault,
1029 'j.n.Y' => date('j.n.Y', $actual_time).' (j.n.Y)',
1030 'm/d/Y' => date('m/d/Y', $actual_time).' (M/D/Y)',
1031 'd/m/Y' => date('d/m/Y', $actual_time).' (D/M/Y)',
1032 'm.d.Y' => date('m.d.Y', $actual_time).' (M.D.Y)',
1033 'd.m.Y' => date('d.m.Y', $actual_time).' (D.M.Y)',
1034 'm-d-Y' => date('m-d-Y', $actual_time).' (M-D-Y)',
1035 'd-m-Y' => date('d-m-Y', $actual_time).' (D-M-Y)',
1036 'Y-m-d' => date('Y-m-d', $actual_time).' (Y-M-D)', // new in L* 7.4
1037 'Y.m.d' => date('Y.m.d', $actual_time).' (Y.M.D)', // new in L* 7.4
1038 /*
1039 'D M d, Y' => date( 'D M d, Y', $actual_time ), // Aldus 2025-01-17: by [1] overwritten!
1040 'M d Y' => date( 'M d Y', $actual_time ), // Aldus 2025-01-17: by [2] overwritten!
1041 'd M Y' => date( 'd M Y', $actual_time ), // Aldus 2025-01-17: by [3] overwritten!
1042 'jS F, Y' => date( 'jS F, Y', $actual_time ), // Aldus 2025-01-17: by [4] overwritten!
1043 'l, jS F, Y' => date( 'l, jS F, Y', $actual_time ) // Aldus 2025-01-17: by [5] overwritten!
1044 */
1045 ];
1046
1052 $oThis = self::getInstance();
1053 $oThis->set_core_language(DEFAULT_LANGUAGE);
1054
1058 $aFormatList = [
1059 'D M d, Y', // [1] Fri Jan 17, 2025
1060 'M d Y', // [2] Jan 17 2025
1061 'd M Y', // [3] 17. January 2025
1062 'jS F, Y', // [4] 17th January, 2025
1063 'l, jS F, Y' // [5] Friday, 17th January, 2025
1064 ];
1065
1069 if (LANGUAGE == 'EN')
1070 {
1071 foreach ($aFormatList as &$format)
1072 {
1073 $DATE_FORMATS[$format] = $oThis->formatWithMySQL($format, $actual_time);
1074 }
1075 } else
1076 {
1077 // 1
1078 $patterns = [
1079 "/([0-9]{1,2})th/i",
1080 "/([0-9]{1,2})rd/i",
1081 "/([0-9]{1,2})st/i",
1082 ];
1083
1084 foreach ($aFormatList as &$format)
1085 {
1086 $sFormatedTime = $oThis->formatWithMySQL($format, $actual_time);
1087 if (str_contains($format, "S"))
1088 {
1089 $sFormatedTime = preg_replace(
1090 $patterns,
1091 "$1".(LANGUAGE == "NL" ? "" : "."),
1092 $sFormatedTime
1093 );
1094 }
1095 $DATE_FORMATS[$format] = $sFormatedTime;
1096 }
1097
1098 }
1099 return $DATE_FORMATS;
1100 }
1101
1108 static function get_timeformats(): array
1109 {
1110 global $user_time;
1111 global $TEXT;
1112
1113 // Get the current time (in the users timezone if required)
1114 $actual_time = time();
1115
1116 // Get "System Default"
1117 $sSystemDefault = "";
1118
1119 if ((isset($user_time)) && ($user_time === true))
1120 {
1121 $sSystemDefault = date(DEFAULT_TIME_FORMAT, $actual_time).' (';
1122 $sSystemDefault .= ($TEXT['SYSTEM_DEFAULT'] ?? self::SYSTEM_DEFAULT_STR).')';
1123 }
1124
1125 return [
1126 'system_default' => $sSystemDefault,
1127 'H:i' => date('H:i', $actual_time),
1128 'H:i:s' => date('H:i:s', $actual_time),
1129 'g:i a' => date('g:i a', $actual_time), // Lowercase Ante meridiem and Post meridiem
1130 'g:i A' => date('g:i A', $actual_time) // Uppercase Ante meridiem and Post meridiem
1131 ];
1132 }
1133
1145 static function get_days(string $lang= "en_EN", bool $abbr= false): array
1146 {
1147 return self::getInstance()->getWeekdayNames($lang, $abbr); // Wochentagsnamen ausgeschrieben
1159 }
1160
1172 static function get_months(string $lang= "en_EN", bool $abbr= false): array
1173 {
1174 return self::getInstance()->getMonthNames($lang, $abbr); // Monatsnamen ausgeschrieben
1191 }
1192
1199 static function get_timezones(): array
1200 {
1201 return [
1202 "Pacific/Kwajalein",
1203 "Pacific/Samoa",
1204 "Pacific/Honolulu",
1205 "America/Anchorage",
1206 "America/Los_Angeles",
1207 "America/Phoenix",
1208 "America/Mexico_City",
1209 "America/Lima",
1210 "America/Caracas",
1211 "America/Halifax",
1212 "America/Buenos_Aires",
1213 "Atlantic/Reykjavik",
1214 "Atlantic/Azores",
1215 "Europe/London",
1216 "Europe/Berlin",
1217 "Europe/Kaliningrad",
1218 "Europe/Moscow",
1219 "Asia/Tehran",
1220 "Asia/Baku",
1221 "Asia/Kabul",
1222 "Asia/Tashkent",
1223 "Asia/Calcutta",
1224 "Asia/Colombo",
1225 "Asia/Bangkok",
1226 "Asia/Hong_Kong",
1227 "Asia/Tokyo",
1228 "Australia/Adelaide",
1229 "Pacific/Guam",
1230 "Etc/GMT+10",
1231 "Pacific/Fiji"
1232 ];
1233 }
1234}
static getInstance(array &$settings=[])
$database
Definition constants.php:52