LEPTON CMS 7.3.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
24 public const SYSTEM_DEFAULT_STR = 'System Default';
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 ];
120
128 public array $CORE_time_formats_PHP = [
129 'g:i A' => '%I:%M %p',
130 'g:i a' => '%I:%M %P',
131 'H:i:s' => '%H:%M:%S',
132 'H:i' => '%H:%M'
133 ];
134
142 public array $CORE_time_formats_MYSQL = [
143 'g:i A' => '%l:%i %p', // Uppercase Ante meridiem and Post meridiem
144 'g:i a' => '%r %p',
145 'H:i:s' => '%H:%i:%s', // 3
146 'H:i' => '%H:%i' // 4
147 ];
148
156 public array $CORE_date_formats_DatePicker = [
157 'l, jS F, Y'=> 'DD, d. MM yy', //'A, e B, yy',
158 'jS F, Y' => 'e B, yy', // 1
159 'd M Y' => 'd M yy',
160 'M d Y' => 'M d yy',
161 'D M d, Y' => 'DD d MM, yy', // 'a m d, yy', // 2 [Aldus: 21.01.2020 - Buggy in LepSem!]
162 'd-m-Y' => 'd-m-yy', // 3
163 'm-d-Y' => 'm-d-yy',
164 'd.m.Y' => 'd.m.yy', // 4
165 'm.d.Y' => 'm.d.yy',
166 'd/m/Y' => 'd/m/yy', // 5
167 'm/d/Y' => 'm/d/yy',
168 'j.n.Y' => 'd.m.yy' // 6! Day in month without leading zero
169 ];
170
181 public bool $useINTL = false;
182 public bool $intl_installed = false;
183
191 public array $CORE_date_formats_INTL = [
192 'l, jS F, Y'=> 'A, e B, yyyy',
193 'jS F, Y' => 'e B, yyyy', // 1
194 'd M Y' => 'd M yyyy',
195 'M d Y' => 'M d yyyy',
196 'D M d, Y' => 'EE d MM, yyyy', // 'a m d, yy',
197 'd-m-Y' => 'd-M-yy', // 3
198 'm-d-Y' => 'M-d-yy',
199 'd.m.Y' => 'd.M.yy', // 4
200 'm.d.Y' => 'M.d.yy',
201 'd/m/Y' => 'd/M/yy', // 5
202 'm/d/Y' => 'M/d/yy',
203 'j.n.Y' => 'd.M.yyyy' // 6! Day in month without leading zero
204 ];
205
210 public const MYSQL_LOCALES = [
211 "ar_AE" => "Arabic - United Arab Emirates",
212 "ar_BH" => "Arabic - Bahrain",
213 "ar_DZ" => "Arabic - Algeria",
214 "ar_EG" => "Arabic - Egypt",
215 "ar_IN" => "Arabic - India",
216 "ar_IQ" => "Arabic - Iraq",
217 "ar_JO" => "Arabic - Jordan",
218 "ar_KW" => "Arabic - Kuwait",
219 "ar_LB" => "Arabic - Lebanon",
220 "ar_LY" => "Arabic - Libya",
221 "ar_MA" => "Arabic - Morocco",
222 "ar_OM" => "Arabic - Oman",
223 "ar_QA" => "Arabic - Qatar",
224 "ar_SA" => "Arabic - Saudi Arabia",
225 "ar_SD" => "Arabic - Sudan",
226 "ar_SY" => "Arabic - Syria",
227 "ar_TN" => "Arabic - Tunisia",
228 "ar_YE" => "Arabic - Yemen",
229 "be_BY" => "Belarusian - Belarus",
230 "bg_BG" => "Bulgarian - Bulgaria",
231 "ca_ES" => "Catalan - Spain",
232 "cs_CZ" => "Czech - Czech Republic",
233 "da_DK" => "Danish - Denmark",
234 "de_AT" => "German - Austria",
235 "de_BE" => "German - Belgium",
236 "de_CH" => "German - Switzerland",
237 "de_DE" => "German - Germany",
238 "de_LU" => "German - Luxembourg",
239 "el_GR" => "Greek - Greece",
240 "en_AU" => "English - Australia",
241 "en_CA" => "English - Canada",
242 "en_GB" => "English - United Kingdom",
243 "en_IN" => "English - India",
244 "en_NZ" => "English - New Zealand",
245 "en_PH" => "English - Philippines",
246 "en_US" => "English - United States",
247 "en_ZA" => "English - South Africa",
248 "en_ZW" => "English - Zimbabwe",
249 "es_AR" => "Spanish - Argentina",
250 "es_BO" => "Spanish - Bolivia",
251 "es_CL" => "Spanish - Chile",
252 "es_CO" => "Spanish - Colombia",
253 "es_CR" => "Spanish - Costa Rica",
254 "es_DO" => "Spanish - Dominican Republic",
255 "es_EC" => "Spanish - Ecuador",
256 "es_ES" => "Spanish - Spain",
257 "es_GT" => "Spanish - Guatemala",
258 "es_HN" => "Spanish - Honduras",
259 "es_MX" => "Spanish - Mexico",
260 "es_NI" => "Spanish - Nicaragua",
261 "es_PA" => "Spanish - Panama",
262 "es_PE" => "Spanish - Peru",
263 "es_PR" => "Spanish - Puerto Rico",
264 "es_PY" => "Spanish - Paraguay",
265 "es_SV" => "Spanish - El Salvador",
266 "es_US" => "Spanish - United States",
267 "es_UY" => "Spanish - Uruguay",
268 "es_VE" => "Spanish - Venezuela",
269 "et_EE" => "Estonian - Estonia",
270 "eu_ES" => "Basque - Spain",
271 "fi_FI" => "Finnish - Finland",
272 "fo_FO" => "Faroese - Faroe Islands",
273 "fr_BE" => "French - Belgium",
274 "fr_CA" => "French - Canada",
275 "fr_CH" => "French - Switzerland",
276 "fr_FR" => "French - France",
277 "fr_LU" => "French - Luxembourg",
278 "gl_ES" => "Galician - Spain",
279 "gu_IN" => "Gujarati - India",
280 "he_IL" => "Hebrew - Israel",
281 "hi_IN" => "Hindi - India",
282 "hr_HR" => "Croatian - Croatia",
283 "hu_HU" => "Hungarian - Hungary",
284 "id_ID" => "Indonesian - Indonesia",
285 "is_IS" => "Icelandic - Iceland",
286 "it_CH" => "Italian - Switzerland",
287 "it_IT" => "Italian - Italy",
288 "ja_JP" => "Japanese - Japan",
289 "ko_KR" => "Korean - Republic of Korea",
290 "lt_LT" => "Lithuanian - Lithuania",
291 "lv_LV" => "Latvian - Latvia",
292 "mk_MK" => "Macedonian - North Macedonia",
293 "mn_MN" => "Mongolia - Mongolian",
294 "ms_MY" => "Malay - Malaysia",
295 "nb_NO" => "Norwegian(Bokmål) - Norway",
296 "nl_BE" => "Dutch - Belgium",
297 "nl_NL" => "Dutch - The Netherlands",
298 "no_NO" => "Norwegian - Norway",
299 "pl_PL" => "Polish - Poland",
300 "pt_BR" => "Portugese - Brazil",
301 "pt_PT" => "Portugese - Portugal",
302 "rm_CH" => "Romansh - Switzerland",
303 "ro_RO" => "Romanian - Romania",
304 "ru_RU" => "Russian - Russia",
305 "ru_UA" => "Russian - Ukraine",
306 "sk_SK" => "Slovak - Slovakia",
307 "sl_SI" => "Slovenian - Slovenia",
308 "sq_AL" => "Albanian - Albania",
309 "sr_RS" => "Serbian - Serbia",
310 "sv_FI" => "Swedish - Finland",
311 "sv_SE" => "Swedish - Sweden",
312 "ta_IN" => "Tamil - India",
313 "te_IN" => "Telugu - India",
314 "th_TH" => "Thai - Thailand",
315 "tr_TR" => "Turkish - Turkey",
316 "uk_UA" => "Ukrainian - Ukraine",
317 "ur_PK" => "Urdu - Pakistan",
318 "vi_VN" => "Vietnamese - Vietnam",
319 "zh_CN" => "Chinese - China",
320 "zh_HK" => "Chinese - Hong Kong",
321 "zh_TW" => "Chinese - Taiwan"
322 ];
323
331 public static function getInstance(bool $bUseINTL = false): object
332 {
333 if (null === static::$instance) {
334 static::$instance = new static();
335 }
336 static::$instance->useINTL = $bUseINTL;
337
338 if (true === $bUseINTL)
339 {
340 static::$instance->intl_installed = static::$instance->checkINTLExtensionExists();
341 }
342
343 return static::$instance;
344 }
345
349 protected function __construct ()
350 {
351 // nothing
352 }
353
360 public function addLanguage ($aString=""): bool
361 {
362 if ($aString == "") {
363 return false;
364 }
365 if (false === in_array($aString, $this->lang)) {
366 $this->lang[] = $aString;
367 }
368 return true;
369 }
370
377 public function setFormat( string $aString="" ): bool
378 {
379 if($this->useINTL)
380 {
381 $this->sINTLFormat = $aString;
382 } else {
383 $this->format=$aString;
384 }
385 return true;
386 }
387
399 public function toHTML(int $aTimestamp = 0 ): string
400 {
401 if (NULL == $aTimestamp)
402 {
403 $aTimestamp = TIME();
404 }
405
406 $aTempLocale = setlocale(LC_ALL, $this->lang);
407 if (false === $aTempLocale)
408 {
409 $aTempLocale = setlocale(LC_ALL, 0);
410 }
411
412 if ((true === $this->useINTL) && (true === $this->intl_installed))
413 {
414 $fmt = datefmt_create(
415 $aTempLocale, // 'de-DE',
416 IntlDateFormatter::FULL,
417 IntlDateFormatter::FULL,
418 DEFAULT_TIMEZONE_STRING, // 'Europe/Berlin',
419 IntlDateFormatter::GREGORIAN,
420 $this->sINTLFormat
421 //$this->format // "yyyy.MM.dd G 'um' HH:mm:ss zzz" // "MMMM | d | y | H"
422 );
423 if (is_null($fmt))
424 {
425 // Huston: we've got a problem!
426 $this->useINTL = false;
427 return date($this->format, $aTimestamp);
428 } else
429 {
430 return datefmt_format($fmt, $aTimestamp );
431 }
432 } else {
438 if (class_exists("IntlDateFormatter"))
439 {
440 $oTempFormatter = new IntlDateFormatter(
441 $aTempLocale, // 'en_US',
442 IntlDateFormatter::LONG,
443 IntlDateFormatter::NONE,
444 DEFAULT_TIMEZONE_STRING, // 1 timezone
445 IntlDateFormatter::GREGORIAN, // 2 calendar
446 $this->sINTLFormat // 3 format
447 );
448 return $oTempFormatter->format($aTimestamp);
449 } else
450 {
451 // Aldus 2025-01-19: Problem! Just an Aldus fix for "%" in format!
452 return date(str_replace("%", "",$this->format), $aTimestamp);
453 }
454 }
455 }
456
467 public function setLanguage(array $aArray = []): bool
468 {
469 $this->lang = [];
470 foreach ($aArray as $a)
471 {
472 $this->lang[] = $a;
473 }
474 return true;
475 }
476
494 public function transform (string $aDateString = "01.01.1971", string $aFormat="dmy"): string
495 {
496 $this->_force_date ($aDateString);
497 $this->_force_format ($aFormat);
498
499 $temp = explode(".", $aDateString);
500 $temp = array_map(
501 function ($a) {
502 return intval($a);
503 },
504 $temp
505 );
506 switch ($aFormat)
507 {
508 case 'dmy':
509 $this->_force_year($temp[2]);
510 $temp_time = mktime( 1, 0, 0, $temp[1], $temp[0], $temp[2]);
511 break;
512
513 case 'mdy':
514 $this->_force_year($temp[2]);
515 $temp_time = mktime( 1, 0, 0, $temp[0], $temp[1], $temp[2]);
516 break;
517
518 case 'ymd':
519 $this->_force_year($temp[0]);
520 $temp_time = mktime( 1, 0, 0, $temp[1], $temp[2], $temp[0]);
521 break;
522
530 default:
531 $temp_time = time();
532 break;
533 }
534 return $this->toHTML($temp_time);
535 }
536
552 private function _force_date(string &$aDateString ): void
553 {
554 $pattern = ["*[\\/|.|-]+*"];
555 $replace = ["."];
556
557 $aDateString = preg_replace($pattern, $replace, $aDateString);
558 }
559
571 private function _force_format(string &$aFormat): void
572 {
573
574 $aFormat = strtolower ($aFormat);
575
576 $pattern = ["*[\\/|.|-]+*", "*[ |%]+*"];
577 $replace = ["", ""];
578
579 $aFormat = preg_replace($pattern, $replace, $aFormat);
580 }
581
591 private function _force_year(string &$aYearStr = "1971"): void
592 {
593 if (strlen($aYearStr) == 2)
594 {
595 $aYearStr = (((int) $aYearStr > $this->force_year + (int) DATE("y", TIME())) ? "19" : "20").$aYearStr;
596 }
597 if (strlen($aYearStr) > 4)
598 {
599 $aYearStr = substr($aYearStr, 0, 4);
600 }
601 }
602
610 public function parse_string (string &$aStr = "", string $aPattern = "/([0-3][0-9].[01]{0,1}[0-9].[0-9]{2,4})/s"): void
611 {
612 $found=[];
613 preg_match_all($aPattern, $aStr, $found );
614 foreach ($found[1] as $a)
615 {
616 $aStr = str_replace($a, $this->transform($a), $aStr);
617 }
618 }
619
628 public function set_core_language(string $aKeyStr = ""): bool
629 {
630
631 $return_value = true;
632
633 switch ($aKeyStr)
634 {
635
636 case "DE":
637 $this->lang = ['de_DE.UTF-8', 'de_DE@euro', 'de_DE', 'de', 'ge'];
638 break;
639
640 case "EN":
641 $this->lang = ['en_EN@euro', 'en_EN', 'en', 'EN', 'en_UK', 'UK', 'en_US', 'en_GB', 'en_CA'];
642 break;
643
644 case "FR":
645 $this->lang = ['FR', 'fr_FR.UTF-8', 'fr_FR', 'fr_FR@euro', 'fr'];
646 break;
647
648 case "IT":
649 $this->lang = ['it_IT@euro', 'it_IT', 'it'];
650 break;
651
652 case "NL":
653 $this->lang = ['nl_NL@euro', 'nl_NL', 'nl', 'Dutch', 'nld_nld'];
654 break;
655
656 case "RU":
657 $this->lang = ['RU', 'ru_RU.UTF-8', 'ru_RU', 'ru_RU@euro', 'ru'];
658 break;
659
660 case "ZH":
661 $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'];
662 break;
663
664 default:
665 $this->test_locale($aKeyStr);
666 break;
667 }
668 return $return_value;
669 }
670
685 public function test_locale (string $aKey = "de_DE", bool $use_it = true): array
686 {
687 if (strlen($aKey) == 2)
688 {
689 $aKey = strtolower($aKey)."_".strtoupper($aKey);
690 }
691
692 $temp_array = [];
693 ob_start();
694 exec('locale -a', $temp_array);
695 ob_end_flush();
696 $all = [];
697
698 foreach($temp_array as $lang_key)
699 {
700 if (substr($lang_key, 0,5) == $aKey)
701 {
702 $all[]=$lang_key;
703 }
704 }
705
706 if (!empty($all) && (true === $use_it))
707 {
708 $this->lang = $all;
709 }
710 return $all;
711 }
712
720 public function formatToDatepicker(string $sFormatString = ""): string
721 {
722 if (isset($this->CORE_date_formats_DatePicker[$sFormatString])) {
723 return $this->CORE_date_formats_DatePicker[$sFormatString];
724 } elseif (isset($this->CORE_date_formats_DatePicker[DATE_FORMAT])) {
725 return $this->CORE_date_formats_DatePicker[DATE_FORMAT];
726 } else {
727 return "";
728 }
729 }
730
739 public function calendarToTimestamp(string $str = "", int $offset = 0): int
740 {
741 $str = trim($str);
742 if ($str == '0' || $str == '')
743 {
744 return 0;
745 }
746
747 // convert to yyyy-mm-dd
748 // "dd.mm.yyyy"?
749 if(preg_match('/^\d{1,2}\.\d{1,2}\.\d{2}(\d{2})?/', $str)) {
750 $str = preg_replace('/^(\d{1,2})\.(\d{1,2})\.(\d{2}(\d{2})?)/', '$3-$2-$1', $str);
751 }
752
753 // "mm/dd/yyyy"?
754 if(preg_match('#^\d{1,2}/\d{1,2}/(\d{2}(\d{2})?)#', $str)) {
755 $str = preg_replace('#^(\d{1,2})/(\d{1,2})/(\d{2}(\d{2})?)#', '$3-$1-$2', $str);
756 }
757
758 // use strtotime()
759 if ($offset != 0)
760 {
761 return (strtotime($str, $offset));
762 }
763 else
764 {
765 return (strtotime($str));
766 }
767 }
768
774 public function detectPageLanguage() : array
775 {
776 // [1] $_GET
777 $sTempCurrentPageLanguage = ($_GET["lang"] ?? NULL);
778
779 // [1.1] none found - page-language?
780 if (is_null($sTempCurrentPageLanguage))
781 {
782 $sTempCurrentPageLanguage = LEPTON_frontend::getInstance()->page['language'];
783 }
784
785 // [2]
786 $sBasic = strtolower($sTempCurrentPageLanguage)."_".strtoupper($sTempCurrentPageLanguage);
787
788 // [3]
789 return [
790 $sBasic,
791 $sBasic.".UTF-8",
792 $sBasic."@euro"
793 ];
794 }
795
801 public function checkINTLExtensionExists() : bool
802 {
803 $aAllExtensions = get_loaded_extensions();
804 if (!in_array("intl", $aAllExtensions))
805 {
806 return false;
807 }
808 return true;
809 }
810
823 public function formatWithMySQL(string $format = DEFAULT_DATE_FORMAT, int|null $timestamp = null, string $optionalLang = "" ): string|null
824 {
825 if ($timestamp === null)
826 {
827 $timestamp = time();
828 }
829
830 $sRealFormat = $this->CORE_date_formats_MYSQL[$format] ?? $format;
831
832 $tempLang = self::buildLanguageKey(
833 (empty($optionalLang)
834 ? LANGUAGE
835 : $optionalLang
836 )
837 );
838
840
841 if ($tempLang !== "en_EN")
842 {
843 $database->simple_query("SET lc_time_names = '".$tempLang."';");
844 }
845 else
846 {
847 $database->simple_query("SET lc_time_names = 'en_gb';");
848 }
849
850 // see: https://www.epochconverter.com/programming/mysql
851 $sQuery = ($timestamp < 0)
852 ? "SELECT DATE_FORMAT( DATE_ADD(FROM_UNIXTIME(0), interval " . $timestamp . " second),'" . $sRealFormat . "');"
853 : "SELECT DATE_FORMAT( FROM_UNIXTIME(" . $timestamp . "),'" . $sRealFormat . "');"
854 ;
855
856 return $database->get_one($sQuery);
857 }
858
868 static function buildLanguageKey(string $key = LANGUAGE): string
869 {
870 if (preg_match("~^[a-z]{2}_[A-Z]{2}$~", $key)) {
871 // given string is "in correct form"
872 return $key;
873 } elseif (strlen($key) >= 2) {
874 // more than two chars - use the first two ones
875 $key = substr(trim($key), 0, 2);
876 return strtolower($key) . "_" . strtoupper($key);
877 } else {
878 return "Error: need at least two chars for key! One given!";
879 }
880 }
881
926 public function getWeekdayNames(string $sLanguage, bool $bAbbreviated = false): array
927 {
928 $returnValue = [];
929
930 // Der 5. Januar 1970 war ein Montag.
931 $tag = 5;
932 $monat = 1;
933 $jahr = 1970;
934
935 $stunde = 1;
936 $minute = 0;
937 $sekunde = 0;
938
939 for ($i = 0; $i < 7; $i++)
940 {
941 $iTimestamp = mktime($stunde, $minute, $sekunde, $monat, $tag+$i, $jahr);
942 $returnValue[$i+1] = $this->formatWithMySQL(($bAbbreviated ? "%a" : "%W"), $iTimestamp, $sLanguage);
943 }
944
945 return $returnValue;
946 }
947
958 public function getMonthNames(string $sLanguage, bool $bAbbreviated = false): array
959 {
960 $returnValue = [];
961
962 // Der 5. Januar 1970 war ein Montag.
963 $tag = 5;
964 // $monat = 1;
965 $jahr = 1970;
966
967 $stunde = 1;
968 $minute = 0;
969 $sekunde = 0;
970
971 for ($monat = 1; $monat <= 12; $monat++)
972 {
973 $iTimestamp = mktime($stunde, $minute, $sekunde, $monat, $tag, $jahr);
974 $returnValue[$monat] = $this->formatWithMySQL(($bAbbreviated ? "%b" : "%M"), $iTimestamp, $sLanguage);
975 }
976
977 return $returnValue;
978 }
979
980 public function getLocaleList(): array
981 {
982 return self::MYSQL_LOCALES;
983 }
984
985########################################### will replace code from LEPTON_basics ###########################################
986// @ADD_date 20250117, replaces lepton_basics
987
995 static function get_dateformats(): array
996 {
997 global $user_time;
998 global $TEXT;
999
1000 // Get the current time (in the users timezone if required)
1001 $actual_time = time();
1002
1003 // Get "System Default"
1004 $sSystemDefault = "";
1005 if (isset($user_time) && $user_time === true)
1006 {
1007 $sSystemDefault = date(DEFAULT_DATE_FORMAT, $actual_time).' (';
1008 $sSystemDefault .= ($TEXT['SYSTEM_DEFAULT'] ?? self::SYSTEM_DEFAULT_STR).')';
1009 }
1010
1011 // Add values to list
1012 $DATE_FORMATS = [
1013 'system_default' => $sSystemDefault,
1014 'j.n.Y' => date('j.n.Y', $actual_time).' (j.n.Y)',
1015 'm/d/Y' => date('m/d/Y', $actual_time).' (M/D/Y)',
1016 'd/m/Y' => date('d/m/Y', $actual_time).' (D/M/Y)',
1017 'm.d.Y' => date('m.d.Y', $actual_time).' (M.D.Y)',
1018 'd.m.Y' => date('d.m.Y', $actual_time).' (D.M.Y)',
1019 'm-d-Y' => date('m-d-Y', $actual_time).' (M-D-Y)',
1020 'd-m-Y' => date('d-m-Y', $actual_time).' (D-M-Y)' /*,
1021 'D M d, Y' => date( 'D M d, Y', $actual_time ), // Aldus 2025-01-17: by [1] overwritten!
1022 'M d Y' => date( 'M d Y', $actual_time ), // Aldus 2025-01-17: by [2] overwritten!
1023 'd M Y' => date( 'd M Y', $actual_time ), // Aldus 2025-01-17: by [3] overwritten!
1024 'jS F, Y' => date( 'jS F, Y', $actual_time ), // Aldus 2025-01-17: by [4] overwritten!
1025 'l, jS F, Y' => date( 'l, jS F, Y', $actual_time ) // Aldus 2025-01-17: by [5] overwritten!
1026 */
1027 ];
1028
1034 $oThis = self::getInstance();
1035 $oThis->set_core_language(DEFAULT_LANGUAGE);
1036
1040 $aFormatList = [
1041 'D M d, Y', // [1] Fri Jan 17, 2025
1042 'M d Y', // [2] Jan 17 2025
1043 'd M Y', // [3] 17. January 2025
1044 'jS F, Y', // [4] 17th January, 2025
1045 'l, jS F, Y' // [5] Friday, 17th January, 2025
1046 ];
1047
1051 foreach ($aFormatList as &$format)
1052 {
1053 $DATE_FORMATS[$format] = $oThis->formatWithMySQL($format, $actual_time);
1054 }
1055
1056 return $DATE_FORMATS;
1057 }
1058
1065 static function get_timeformats(): array
1066 {
1067 global $user_time;
1068 global $TEXT;
1069
1070 // Get the current time (in the users timezone if required)
1071 $actual_time = time();
1072
1073 // Get "System Default"
1074 $sSystemDefault = "";
1075
1076 if ((isset($user_time)) && ($user_time === true))
1077 {
1078 $sSystemDefault = date(DEFAULT_TIME_FORMAT, $actual_time).' (';
1079 $sSystemDefault .= ($TEXT['SYSTEM_DEFAULT'] ?? self::SYSTEM_DEFAULT_STR).')';
1080 }
1081
1082 return [
1083 'system_default' => $sSystemDefault,
1084 'H:i' => date('H:i', $actual_time),
1085 'H:i:s' => date('H:i:s', $actual_time),
1086 'g:i a' => date('g:i a', $actual_time), // Lowercase Ante meridiem and Post meridiem
1087 'g:i A' => date('g:i A', $actual_time) // Uppercase Ante meridiem and Post meridiem
1088 ];
1089 }
1090
1102 static function get_days(string $lang= "en_EN", bool $abbr= false): array
1103 {
1104 return self::getInstance()->getWeekdayNames($lang, $abbr); // Wochentagsnamen ausgeschrieben
1116 }
1117
1129 static function get_months(string $lang= "en_EN", bool $abbr= false): array
1130 {
1131 return self::getInstance()->getMonthNames($lang, $abbr); // Monatsnamen ausgeschrieben
1148 }
1149
1156 static function get_timezones(): array
1157 {
1158 return [
1159 "Pacific/Kwajalein",
1160 "Pacific/Samoa",
1161 "Pacific/Honolulu",
1162 "America/Anchorage",
1163 "America/Los_Angeles",
1164 "America/Phoenix",
1165 "America/Mexico_City",
1166 "America/Lima",
1167 "America/Caracas",
1168 "America/Halifax",
1169 "America/Buenos_Aires",
1170 "Atlantic/Reykjavik",
1171 "Atlantic/Azores",
1172 "Europe/London",
1173 "Europe/Berlin",
1174 "Europe/Kaliningrad",
1175 "Europe/Moscow",
1176 "Asia/Tehran",
1177 "Asia/Baku",
1178 "Asia/Kabul",
1179 "Asia/Tashkent",
1180 "Asia/Calcutta",
1181 "Asia/Colombo",
1182 "Asia/Bangkok",
1183 "Asia/Hong_Kong",
1184 "Asia/Tokyo",
1185 "Australia/Adelaide",
1186 "Pacific/Guam",
1187 "Etc/GMT+10",
1188 "Pacific/Fiji"
1189 ];
1190 }
1191}
static getInstance(array &$settings=[])
$database
Definition constants.php:52