[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [10754] Changed to locallly added data converter
From: |
Torstein |
Subject: |
[Fmsystem-commits] [10754] Changed to locallly added data converter |
Date: |
Wed, 06 Feb 2013 06:53:31 +0000 |
Revision: 10754
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10754
Author: vator
Date: 2013-02-06 06:53:30 +0000 (Wed, 06 Feb 2013)
Log Message:
-----------
Changed to locallly added data converter
Modified Paths:
--------------
trunk/controller/inc/class.uicheck_list.inc.php
Added Paths:
-----------
trunk/controller/inc/helper/class.date_converter.inc.php
Modified: trunk/controller/inc/class.uicheck_list.inc.php
===================================================================
--- trunk/controller/inc/class.uicheck_list.inc.php 2013-02-06 06:52:12 UTC
(rev 10753)
+++ trunk/controller/inc/class.uicheck_list.inc.php 2013-02-06 06:53:30 UTC
(rev 10754)
@@ -45,6 +45,7 @@
include_class('controller', 'check_item', 'inc/model/');
include_class('controller', 'date_generator', 'inc/component/');
include_class('controller', 'check_list_status_updater', 'inc/helper/');
+ include_class('controller', 'date_converter', 'inc/helper/');
class controller_uicheck_list extends phpgwapi_uicommon
{
@@ -232,7 +233,7 @@
$location_id =
phpgw::get_var('location_id');
$check_list->set_location_id($location_id);
$component_id =
phpgw::get_var('component_id');
-
$check_list->set_component_id($component_id);
+
$check_list->set_component_id($component_id);
}
$component_arr =
execMethod('property.soentity.read_single_eav', array('location_id' =>
$location_id, 'id' => $component_id));
@@ -240,7 +241,7 @@
$component = new controller_component();
$component->set_location_code(
$component_arr['location_code'] );
- $component->set_xml_short_desc( $short_desc );
+ $component->set_xml_short_desc( $short_desc );
$component_array = $component->toArray();
$building_location_code =
$this->get_building_location_code($component_arr['location_code']);
@@ -363,9 +364,9 @@
$planned_date = phpgw::get_var('planned_date',
'string');
$completed_date = phpgw::get_var('completed_date',
'string');
$comment = phpgw::get_var('comment', 'string');
-
- $deadline_date_ts =
phpgwapi_datetime::date_to_timestamp( $deadline_date );
+ $deadline_date_ts = date_converter::date_to_timestamp(
$deadline_date );
+
if($planned_date != '')
{
$planned_date_ts =
phpgwapi_datetime::date_to_timestamp( $planned_date );
Added: trunk/controller/inc/helper/class.date_converter.inc.php
===================================================================
--- trunk/controller/inc/helper/class.date_converter.inc.php
(rev 0)
+++ trunk/controller/inc/helper/class.date_converter.inc.php 2013-02-06
06:53:30 UTC (rev 10754)
@@ -0,0 +1,187 @@
+<?php
+
+ class date_converter
+ {
+
+ /**
+ * Convert a date array to a unix timestamp
+ *
+ * @param string $date the date to convert, must contain keys
day, month & year
+ * @return int unix timestamp
+ */
+ public static function date_to_timestamp($datestr = '')
+ {
+ if ( !$datestr )
+ {
+ return 0;
+ }
+
+ $hour = 0;
+ $minute = 0;
+ $second = 0;
+
+ if( strpos($datestr, ':') )
+ {
+ $date_part = explode(' ', $datestr);
+ $time_part = explode(':', $date_part[1]);
+
+ $hour = (int) $time_part[0];
+ $minute = (int) $time_part[1];
+ $second = isset($time_part[2]) && $time_part[2]
? (int)$time_part[2] : 0;
+ }
+
+
+ if( version_compare(PHP_VERSION, '5.3.0') >= 0 &&
strpos($datestr, ':'))
+ {
+ return self::datetime_to_timestamp($datestr);
+ }
+
+ $date_array = self::date_array($datestr);
+ return mktime ($hour, $minute, $second,
$date_array['month'], $date_array['day'], $date_array['year']);
+ }
+
+ /**
+ * Convert a date string to an array containing date parts
+ *
+ * @param string $datestr the date string to convert - must
match user's preferred date format
+ * @return array date parts: year,month and day
+ */
+ public static function date_array($datestr)
+ {
+ $dateformat =&
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+
+ $pattern = '/[\.\/\-]/';
+ $fields = preg_split($pattern, $datestr);
+ foreach(preg_split($pattern, $dateformat) as $n =>
$field)
+ {
+ $date[$field] = (int) $fields[$n];
+
+ if ( $field == 'M' )
+ {
+ $date['m'] =
self::convert_M_to_int($fields[$n]);
+ }
+ }
+
+ return array
+ (
+ 'year' => $date['Y'],
+ 'month' => $date['m'],
+ 'day' => $date['d']
+ );
+ }
+
+ /**
+ * 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
+ * @return int the month number - 0 is returned for invalid input
+ */
+ private static function convert_M_to_int($str)
+ {
+ for($i=1; $i <=12; ++$i)
+ {
+ if ( date('M', mktime(0, 0, 0, $i, 1, 2000)) ==
$str )
+ {
+ return $i;
+ }
+ }
+ return 0;
+ }
+
+ /**
+ * Get a list of translated day names
+ *
+ * @return array list of day names
+ */
+ public static function get_dow_fullnames()
+ {
+ static $dow_list = null;
+ if ( is_null($dow_list) )
+ {
+ $dow_list = array();
+ foreach ( self::$dow_fullnames as $id =>
$dow_name )
+ {
+ $dow_list[$id] = lang($dow_name);
+ }
+ }
+ return $dow_list;
+ }
+
+ /**
+ * Get a list of translated month names
+ *
+ * @return array list of month names
+ */
+ public static function get_month_fullnames()
+ {
+ static $month_list = null;
+ if ( is_null($month_list) )
+ {
+ $raw_list = self::$month_fullnames;
+ unset($raw_list[0]); // WAR month index hack
+
+ $month_list = array();
+ foreach ( $raw_list as $id => $month )
+ {
+ if ( $id == 0 )
+ {
+ continue;
+ }
+ $month_list[$id] = lang($month);
+ }
+ }
+ return $month_list;
+ }
+
+ /**
+ * Convert an ISO 8601 day of week number to a local name
+ *
+ * @param int $dow ISO 8601 day of week number
+ * @return string local say of week name
+ */
+ public static function nr2weekday($dow = 0)
+ {
+ $dow_list = self::get_dow_fullnames();
+ if ( isset($dow_list[$dow]) )
+ {
+ return $dow_list[$dow];
+ }
+ return lang('Unknown');
+ }
+ }
+
+?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [10754] Changed to locallly added data converter,
Torstein <=