The problem is not that seconds might end up being index 7, the problem is in the regex in the preg_match. The colon (:) between minutes and seconds is being included with the seconds value, this is also why PHP 5 throws a strict warning about expecting a long and getting a string, because it is receiving :28 instead of just 28.
Patch for rss_utils.inc
Logged In: YES
user_id=1239697
What happens if there is no second in the timestamp. Is
position 6 and 7 empty or will the array be only from 0 to 8?
I think the 2nd case is the right one and so the patch
should be changed a bit.
Logged In: NO
What? Theres not enough info to declaire a bug in this post. Please post more info.
Logged In: YES
user_id=1386245
Originator: NO
The problem is not that seconds might end up being index 7, the problem is in the regex in the preg_match. The colon (:) between minutes and seconds is being included with the seconds value, this is also why PHP 5 throws a strict warning about expecting a long and getting a string, because it is receiving :28 instead of just 28.
$pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/";
should be:
$pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):((\d{2}))?(:?([-+])(\d{2}):?(\d{2})|(Z))?/";
Logged In: NO
Para arreglar el problema hay que recoger el elemento 7 del array $match en vez del elemento 6.
Con esto solucionamos el bug, y funciona perfectamente para fechas con y sin segundos, ya que devuelve cadena vacía cuando no hay segundos.
Vamos a flipar para convertir aplicaciones de PHP4 a PHP5 con problemas de este tipo que no sabes de donde te vienen :P
Logged In: NO
You just need a ?: before the seconds bit of the regexp.
the function validates the format and then determines the epoch. Why not simplify the regexp to validate, then simply use strtotime to find the epoch?
function parse_w3cdtf ( $date_str ) {
# regex to match wc3dtf
$pat = "/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?([-+]\d{2}:?\d{2}|Z)?/";
if ( preg_match( $pat, $date_str ) ) {
return strtotime( $date_str );
}
else {
return -1;
}
}