From 5ab78106b0f9170d5e4930d0901862e4373a686f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 9 Jun 2010 21:43:10 +0200 Subject: Make XMLRPC date parsing more flexible FS#1966 Since the specs aren't 100% clear, dates might be passed in different formats by various XMLRPC clients. This patch makes date parsing a bit more flexible. Unit tests included. --- inc/IXR_Library.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'inc/IXR_Library.php') diff --git a/inc/IXR_Library.php b/inc/IXR_Library.php index b82952d74..2fb7dfe68 100644 --- a/inc/IXR_Library.php +++ b/inc/IXR_Library.php @@ -615,12 +615,14 @@ class IXR_Date { $this->second = gmdate('s', $timestamp); } function parseIso($iso) { - $this->year = substr($iso, 0, 4); - $this->month = substr($iso, 5, 2); - $this->day = substr($iso, 8, 2); - $this->hour = substr($iso, 11, 2); - $this->minute = substr($iso, 14, 2); - $this->second = substr($iso, 17, 2); + if(preg_match('/^(\d\d\d\d)-?(\d\d)-?(\d\d)([T ](\d\d):(\d\d)(:(\d\d))?)?/',$iso,$match)){ + $this->year = (int) $match[1]; + $this->month = (int) $match[2]; + $this->day = (int) $match[3]; + $this->hour = (int) $match[5]; + $this->minute = (int) $match[6]; + $this->second = (int) $match[8]; + } } function getIso() { return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second; -- cgit v1.2.3