@@ -738,25 +738,36 @@ protected function resize_app_window(int $width = 500, int $height = 720) {
738738 * This function is similar to the arg_time_to_string transformation, but it allows the time to be a sub-text of the string.
739739 *
740740 * @param string $text
741- * @return string Transformed text.
741+ * @return string|string[] Transformed text.
742742 */
743- protected function transform_time_to_string (string $ text ): string {
743+ protected function transform_time_to_string (string $ text ): string | array {
744744 if (!preg_match ('/##(.*)##/ ' , $ text , $ matches )) {
745745 // No time found, return the original text.
746746 return $ text ;
747747 }
748748
749749 $ timepassed = explode ('## ' , $ matches [1 ]);
750+ $ basetime = time ();
750751
751752 // If not a valid time string, then just return what was passed.
752- if ((($ timestamp = strtotime ($ timepassed [0 ])) === false )) {
753+ if ((($ timestamp = strtotime ($ timepassed [0 ], $ basetime )) === false )) {
753754 return $ text ;
754755 }
755756
756757 $ count = count ($ timepassed );
757758 if ($ count === 2 ) {
758759 // If timestamp with specified strftime format, then return formatted date string.
759- return str_replace ($ matches [0 ], userdate ($ timestamp , $ timepassed [1 ]), $ text );
760+ $ result = [str_replace ($ matches [0 ], userdate ($ timestamp , $ timepassed [1 ]), $ text )];
761+
762+ // If it's a relative date, allow a difference of 1 minute for the base time used to calculate the timestampt.
763+ if ($ timestamp !== strtotime ($ timepassed [0 ], 0 )) {
764+ $ timestamp = strtotime ($ timepassed [0 ], $ basetime - 60 );
765+ $ result [] = str_replace ($ matches [0 ], userdate ($ timestamp , $ timepassed [1 ]), $ text );
766+ }
767+
768+ $ result = array_unique ($ result );
769+
770+ return count ($ result ) == 1 ? $ result [0 ] : $ result ;
760771 } else if ($ count === 1 ) {
761772 return str_replace ($ matches [0 ], $ timestamp , $ text );
762773 } else {
0 commit comments