[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [10069] phpgwapi_datetime::date_to_timestamp() handle
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [10069] phpgwapi_datetime::date_to_timestamp() handles hours, minutes an seconds as well |
Date: |
Mon, 01 Oct 2012 11:05:58 +0000 |
Revision: 10069
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10069
Author: sigurdne
Date: 2012-10-01 11:05:57 +0000 (Mon, 01 Oct 2012)
Log Message:
-----------
phpgwapi_datetime::date_to_timestamp() handles hours, minutes an seconds as well
Modified Paths:
--------------
trunk/phpgwapi/inc/class.datetime.inc.php
Modified: trunk/phpgwapi/inc/class.datetime.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.datetime.inc.php 2012-10-01 10:13:20 UTC (rev
10068)
+++ trunk/phpgwapi/inc/class.datetime.inc.php 2012-10-01 11:05:57 UTC (rev
10069)
@@ -839,9 +839,9 @@
}
/**
- * Convert a date araray to a unix timestamp
+ * Convert a date array to a unix timestamp
*
- * @param array $date the date array to convert, must contain
keys day, month & year
+ * @param string $date the date to convert, must contain keys
day, month & year
* @return int unix timestamp
*/
public static function date_to_timestamp($datestr = '')
@@ -851,11 +851,51 @@
return 0;
}
+ if( strpos($datestr, ':') )
+ {
+ return self::datetime_to_timestamp($datestr);
+ }
+
$date_array = self::date_array($datestr);
return mktime (13, 0, 0, $date_array['month'],
$date_array['day'], $date_array['year']);
}
+
/**
+ * Convert a datetime to a unix timestamp
+ *
+ * @param string $date the date convert
+ * @return int unix timestamp
+ */
+ public static function datetime_to_timestamp($datestr = '')
+ {
+ if ( !$datestr )
+ {
+ return 0;
+ }
+
+ $format =
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+ if(substr_count($datestr, ':') == 1 )
+ {
+ $format .= ' H:i';
+ }
+ else if(substr_count($datestr, ':') == 2 )
+ {
+ $format .= ' H:i:s';
+ }
+
+ $date = DateTime::createFromFormat("{$format}",
$datestr);
+ if($date)
+ {
+ return $date->getTimestamp();
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ /**
* Convert a M month string to an int
*
* @param string $str abbreviated month name string
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [10069] phpgwapi_datetime::date_to_timestamp() handles hours, minutes an seconds as well,
Sigurd Nes <=