[evolvis-commits] r7090: date routines (not used yet), part 1: parse a date string↵ y-m-d (ISO), d.m.y (German), y/m/d (Ami) ↵

mirabilos at evolvis.org mirabilos at evolvis.org
Wed Nov 17 17:27:39 CET 2010


Author: mirabilos
Date: 2010-11-17 17:27:38 +0100 (Wed, 17 Nov 2010)
New Revision: 7090

Added:
   trunk/gforge_base/evolvisforge/gforge/common/include/datepick.php
Log:
date routines (not used yet), part 1: parse a date string
y-m-d (ISO), d.m.y (German), y/m/d (Ami)


Added: trunk/gforge_base/evolvisforge/gforge/common/include/datepick.php
===================================================================
--- trunk/gforge_base/evolvisforge/gforge/common/include/datepick.php	                        (rev 0)
+++ trunk/gforge_base/evolvisforge/gforge/common/include/datepick.php	2010-11-17 16:27:38 UTC (rev 7090)
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Date operations for FusionForge
+ *
+ * Copyright © 2010
+ *	Thorsten “mirabilos” Glaser <t.glaser at tarent.de>
+ * All rights reserved.
+ *
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/* parse y-m-d or d.m.y or m/d/y format into time_t (int) */
+function datepick_parse($text) {
+	$text = trim($text);
+	if (preg_match('#^[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2}$#', $text)) {
+		/* ISO 8601 */
+		$a = explode('-', $text);
+		$y = $a[0];
+		$m = $a[1];
+		$d = $a[2];
+	} else if (preg_match('#^[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,4}$#', $text)) {
+		/* German */
+		$a = explode('.', $text);
+		$y = $a[2];
+		$m = $a[1];
+		$d = $a[0];
+	} else if (preg_match('#^[0-9]{1,2}/[0-9]{1,2}/[0-9]{1,4}$#', $text)) {
+		/* American */
+		$a = explode('/', $text);
+		$y = $a[2];
+		$m = $a[0];
+		$d = $a[1];
+	} else
+		return false;
+	return strtotime($y."-".$m."-".$d);
+}
+
+?>
\ No newline at end of file



More information about the evolvis-commits mailing list