X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiResult.php;h=e27cf7dd64fcf3400c4c05be5a4581f727e3e4ad;hb=2a3f330a289c7391f62a15d209c91d2f38deaa58;hp=61a4394e74d338e7c4b369e9917976facde6edd0;hpb=9aba586d3b758719d9aa08b236a9de93956b6a96;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index 61a4394e74..e27cf7dd64 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -1196,6 +1196,29 @@ class ApiResult implements ApiSerializable { } } + /** + * Format an expiry timestamp for API output + * @since 1.29 + * @param string $expiry Expiry timestamp, likely from the database + * @param string $infinity Use this string for infinite expiry + * (only use this to maintain backward compatibility with existing output) + * @return string Formatted expiry + */ + public static function formatExpiry( $expiry, $infinity = 'infinity' ) { + static $dbInfinity; + if ( $dbInfinity === null ) { + $dbInfinity = wfGetDB( DB_REPLICA )->getInfinity(); + } + + if ( $expiry === '' || $expiry === null || $expiry === false || + wfIsInfinity( $expiry ) || $expiry === $dbInfinity + ) { + return $infinity; + } else { + return wfTimestamp( TS_ISO_8601, $expiry ); + } + } + /**@}*/ }