summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_test/cases/inc/IXR_Library_date.test.php34
-rw-r--r--inc/IXR_Library.php14
2 files changed, 42 insertions, 6 deletions
diff --git a/_test/cases/inc/IXR_Library_date.test.php b/_test/cases/inc/IXR_Library_date.test.php
new file mode 100644
index 000000000..a2b6154d8
--- /dev/null
+++ b/_test/cases/inc/IXR_Library_date.test.php
@@ -0,0 +1,34 @@
+<?php
+require_once DOKU_INC.'inc/IXR_Library.php';
+
+class ixr_library_date_test extends UnitTestCase {
+
+
+ function test_parseIso(){
+ // multiple tests
+ $tests = array(
+ // full datetime, different formats
+ array('2010-08-17T09:23:14', 1282036994),
+ array('20100817T09:23:14', 1282036994),
+ array('2010-08-17 09:23:14', 1282036994),
+ array('20100817 09:23:14', 1282036994),
+ array('2010-08-17T09:23:14Z', 1282036994),
+ array('20100817T09:23:14Z', 1282036994),
+
+ // no seconds
+ array('2010-08-17T09:23', 1282036980),
+ array('20100817T09:23', 1282036980),
+
+ // no time
+ array('2010-08-17', 1282003200),
+ //array('20100817', 1282003200), #this will NOT be parsed, but is assumed to be timestamp
+ );
+
+ foreach($tests as $test){
+ $dt = new IXR_Date($test[0]);
+ $this->assertEqual($dt->getTimeStamp(),$test[1]);
+ }
+ }
+
+}
+//Setup VIM: ex: et ts=4 enc=utf-8 :
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;