@@ -68,32 +68,44 @@ public function getMenuByCampus(string $link)
6868 ) {
6969 $ items = $ row ->getElementsByTagName ('td ' );
7070 foreach ($ items as $ j => $ item ) {
71- $ menus [$ week_string_dates [$ j ]][] = trim (preg_replace ('/[\pZ\pC]/u ' , ' ' , $ item ->textContent ));
71+ $ treated_item = trim (preg_replace ('/[\pZ\pC]/u ' , ' ' , $ item ->textContent ));
72+ if ($ treated_item != "" ) {
73+ $ menus [$ week_string_dates [$ j ]][] = $ treated_item ;
74+ }
7275 }
7376 }
7477 }
7578 }
7679 }
7780
81+ uksort ($ menus , function ($ a , $ b ) {
82+ if (date_create_from_format ("d/m/Y " , $ a ) == date_create_from_format ("d/m/Y " , $ b )) return 0 ;
83+ return ((date_create_from_format ("d/m/Y " , $ a ) < date_create_from_format ("d/m/Y " , $ b )) ? -1 : 1 );
84+ });
7885 return $ menus ;
7986 }
8087
8188 public function handleWeekDate (string $ week )
8289 {
8390 preg_match_all ("/(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/([0-9]{4}|[0-9]{2})/ " , $ week , $ matches );
84- preg_match_all ("/\s(0[1-9]|[1-2][0-9]|3[0-1])\s|\s([1-9])\s/ " , $ week , $ matches_prime );
85- if ($ matches_prime [0 ]) {
86- $ date2 = date_create_from_format ("d/m/Y " , $ matches [0 ][0 ])->modify ('+1 day ' );
87- $ date1 = clone $ date2 ;
88- $ date1 ->modify ("-5 days " );
89- } else {
90- $ date2 = date_create_from_format ("d/m/Y " , $ matches [0 ][1 ])->modify ('+1 day ' );
91- $ date1 = date_create_from_format ("d/m/Y " , $ matches [0 ][0 ]);
92-
93- if ($ date2 ->diff ($ date1 )->m > 0 ) {
91+
92+ if ($ matches [0 ]) {
93+ $ date2 = date_create_from_format ("d/m/Y " , end ($ matches [0 ]))->modify ('+1 day ' );
94+ if (count ($ matches [0 ]) > 1 ){
95+ $ date1 = date_create_from_format ("d/m/Y " , $ matches [0 ][0 ]);
96+ } else {
9497 $ date1 = clone $ date2 ;
9598 $ date1 ->modify ("-5 days " );
9699 }
100+
101+ }
102+
103+ if ($ date1 ->format ("Y " ) < 100 ) {
104+ $ date1 = date_create_from_format ("d/m/y " , $ date1 ->format ("d/m/y " ));
105+ }
106+
107+ if ($ date2 ->format ("Y " ) < 100 ) {
108+ $ date2 = date_create_from_format ("d/m/y " , $ date2 ->format ("d/m/y " ));
97109 }
98110
99111 $ week_dates = new DatePeriod (
0 commit comments