Author: mcantelon
Date: Fri Jan 20 11:28:35 2012
New Revision: 10730
Log:
Added date parsing helper to QubitFlatileImport class.
Modified:
trunk/lib/QubitFlatfileImport.class.php
Modified: trunk/lib/QubitFlatfileImport.class.php
==============================================================================
--- trunk/lib/QubitFlatfileImport.class.php Fri Jan 20 10:29:19 2012
(r10729)
+++ trunk/lib/QubitFlatfileImport.class.php Fri Jan 20 11:28:35 2012
(r10730)
@@ -61,8 +61,8 @@
/*
*
- * Helper methods
- * --------------
+ * General helper methods
+ * ----------------------
*/
/**
@@ -102,6 +102,44 @@
}
/**
+ * Attempt to parse date from non-machine-readable text
+ *
+ * @param string $dateText description of date
+ *
+ * @return string date in YYYY-MM-DD format
+ */
+ public function parseDate($dateText)
+ {
+ $dateText = trim($dateText);
+ if (is_numeric($dateText))
+ {
+ // return year as beginning date of year
+ $dateData = array(
+ 'year' => $dateText,
+ 'month' => '01',
+ 'day' => '01'
+ );
+ } else {
+ $dateData = date_parse($dateText);
+ }
+
+ if (!$dateData['year'] || !$dateData['month'] || !$dateData['day'])
+ {
+ return FALSE;
+ } else {
+ // turn back to string
+ $dateString = $dateData['year'] .'-'
+ . $dateData['month'] .'-'
+ . $dateData['day'];
+
+ $date = new DateTime($dateString);
+
+ // format to pad with leading 0s
+ return $date->format('Y-m-d');
+ }
+ }
+
+ /**
* Set status variable value
*
* @param string $var name of variable
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.