@@ -738,25 +738,36 @@ protected function resize_app_window(int $width = 500, int $height = 720) {
738
738
* This function is similar to the arg_time_to_string transformation, but it allows the time to be a sub-text of the string.
739
739
*
740
740
* @param string $text
741
- * @return string Transformed text.
741
+ * @return string|string[] Transformed text.
742
742
*/
743
- protected function transform_time_to_string (string $ text ): string {
743
+ protected function transform_time_to_string (string $ text ): string | array {
744
744
if (!preg_match ('/##(.*)##/ ' , $ text , $ matches )) {
745
745
// No time found, return the original text.
746
746
return $ text ;
747
747
}
748
748
749
749
$ timepassed = explode ('## ' , $ matches [1 ]);
750
+ $ basetime = time ();
750
751
751
752
// 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 )) {
753
754
return $ text ;
754
755
}
755
756
756
757
$ count = count ($ timepassed );
757
758
if ($ count === 2 ) {
758
759
// 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 ;
760
771
} else if ($ count === 1 ) {
761
772
return str_replace ($ matches [0 ], $ timestamp , $ text );
762
773
} else {
0 commit comments