tuxbuddy Posted May 8, 2008 Share Posted May 8, 2008 I have a tool called HelpCORE which is a ticket Tracking and Call Handling.The tool is 24*7 based support.In Our firm we have normal Office timing and so do we have 8 hours working support.Now How can I modify the tool so as to work a/c to my requirements. Here's the snippet which I think shall help us with fixing: File : time.php <?php /* * HelpCORE source file * ==================== * * CVS: * ---- * $header$ * * Purpose: * -------- * Date and Time related functions * * Copyright: * ---------- * Copyright (C) 2002-2003 Dennis Fleurbaaij <dennis@io-software.nl> * Copyright (C) 2002-2005 IO Software <info@io-software.nl> * * This program 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. * * This program 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 this * program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, * Cambridge, MA 02139, USA. * * Please note that this software is dual licensed. For the commercial use of this * software you will need a Commercial License. Please see http://www.io-software.nl * for the terms and conditions. * * For more information you can contact IO Software at http://www.io-software.nl */ // Defines for easy handling of time define( 'TIME_YEAR', 2 ); define( 'TIME_MONTH', 1 ); define( 'TIME_DAY', 0 ); define( 'TIME_HOUR', 3 ); define( 'TIME_SECOND', 5 ); /** * Return the current microtime */ function stopwatch_start() { list( $usec, $sec ) = explode( " ", microtime() ); return ( ( float )$usec + ( float )$sec ); } /** * Return the time spent since the input time */ function stopwatch_stop( $starttime ) { list( $usec, $sec ) = explode( " ", microtime() ); return ( ( ( float )$usec + ( float )$sec ) - $starttime ); } /* * Db time to dfe */ function db_time_to_dfe( $db_time ) { return dmy_array_to_days_from_epoch( db_time_to_array( $db_time ) ); } /** * Calculates d m y to days from epoch */ function dmy_array_to_days_from_epoch( $array ) { return dmy_to_days_from_epoch( $array[0], $array[1], $array[2] ); } /** * calculates how long since the computer epoch we are */ function dmy_to_days_from_epoch( $day, $month, $year ) { if( ($timestamp=@gmmktime (1, 0, 0, $month, $day, $year)) === -1 ) { __FATAL__( __FILE__, __LINE__, __CLASS__, __FUNCTION__, 'Invalid timestamp( " D:'.$day.', M:'.$month.', Y:'.$year.' ) -> '.$timestamp.'" )' ); return 0; } return ($timestamp / 86400); } /** * Epoch to array */ function epoch_to_dmy( $epoch ) { // We use day-epcohs $epoch = $epoch * 86400; return( array( gmdate('d', $epoch), gmdate('m', $epoch), gmdate('Y', $epoch), gmdate('H', $epoch), gmdate('i', $epoch), gmdate('s', $epoch) ) ); } /** * Calculates EXACT dmy */ function exact_epoch_to_dmy( $epoch ) { return( array( gmdate('d', $epoch), gmdate('m', $epoch), gmdate('Y', $epoch), gmdate('H', $epoch), gmdate('i', $epoch), gmdate('s', $epoch) ) ); } /** * Calculates days to months and years */ function day_to_dmy_array( $days ) { global $month_days; $months = $month_days; $year = 1970; $month = 1; // Calc howmany years we have while ( true ) { // Count jaar (leapyear is counted later) $days -= 365; $year++; // Shrikkel if ( ( $year % 4 == 0 ) && ( $year % 100 != 0 ) ) { if ( $days < 366 ) { // echo "+ Break on leap ($year)<br />"; break; } $days--; // Normal } else { if ( $days < 365 ) { // echo "+ Normal break<br />"; break; } } } // echo "v- After yearcount we have $days days left.<br />"; // Calc months while( $days > $months[$month] ) { $days -= $months[$month]; $month++; } if( $days == 0 ) $days = 1; // echo "v- After monthcount we have $days days left.<br />"; if( $days < 10 ) $days = '0' . $days; if( $month < 10 ) $month = '0' . $month; // echo "Days: $days Month: $month Year: $year<br />"; return array( $days, $month, $year, '00', '00', '00' ); } /* * Integer to time function int_to_time( $time ) { $days = ''; $mins = $time % 60; $hours = ( int )( $time / 60 ); if( $mins < 10 ) { $mins = '0' . $mins; } $timestring = $hours . ':' . $mins; return $timestring; } /** * Seconds to time string */ function seconds_to_time( $time ) { $days = ''; $timestring = ''; $seconds = $time % 60; $mins = ( ( int )($time/60) ) % 60; $hours = ( int )( ($time/60) / 60 ); if( $mins < 10 ) { $mins = '0' . $mins; } if( $hours > 24 ) { $timestring .= ((int) ($hours/24) ) .' '.text('days').' '; $hours = $hours % 24; } $timestring .= $hours . ':' . $mins .':'.$seconds; return $timestring; } /** * returns now */ function now() { return array_to_db_time( array( date( 'd' ), date( 'm' ), date( 'Y' ), date( 'H' ), date( 'i' ), date( 's' ) ) ); } /** * Find out in what week this date is */ function date_to_weeknr( $date ) { if( ($timestamp=strtotime( $date ) ) === -1 ) { __ERROR__( __FILE__, __LINE__, __CLASS__, __FUNCTION__, 'Invalid timestamp: strtotime("'.$date.'") => "'.$timestamp.'"' ); } return date( 'W', $timestamp ); } /** * Find out on what day a week begins * Note: we can't do leap years so we just guess if the user does not know if it's a leap year */ function weeknr_to_date( $weeknr, $year) { global $month_days; $months = $month_days; if( $weeknr > 53 ) __FATAL__( __FILE__, __LINE__, __CLASS__, __FUNCTION__, 'weeknr_to_date(): week cannot be larger then 53.' ); // There is no week 53, it's week one of the next year if( $weeknr == 53 ) { return array_to_db_date( array( '01', '01', ($year+1) ) ); } // No week zero and start counting at one $weeknr_days = (($weeknr-1) * 7)+1; // The second problem is finding out what day this year started. As not all years start at monday but all weeks DO ! $offset_day = date( 'w', mktime (0,0,0,1,1,$year) ) - 1; // Minus one because php starts at sunday and the world(c) at monday //echo $offset_day.'<br />'; // Now fix the weernr days to start not at monday but at the actual day, this is probmeatic as we can go back in time if( $offset_day >= $weeknr_days ) { // Goes back a year //echo " weeknr_to_date($weeknr, $year): PREV YEAR EXECPT array_to_db_date( array( ( 31 - $offset_day ), '12', ($year-1) ) ): ".array_to_db_date( array( ( 31 - $offset_day ), '12', ($year-1) ) )."<br /><br />"; return array_to_db_date( array( ( 32 - $offset_day ), '12', ($year-1) ) ); // Dec has 32 days to compensate for 0-1 } // Remains in this year else { $weeknr_days -= $offset_day; } //echo " weeknr_to_date($weeknr, $year): weeknr_days: $weeknr_days<br />"; // Schrikkeljaar if ( $year % 4 == 0 ) { $months[02] = 29; } $month = 1; while( $weeknr_days >= $month_days[$month] ) { //echo " weeknr_to_date($weeknr, $year): while( $weeknr_days >= ".$month_days[$month]." )<br />"; $weeknr_days -= $month_days[$month]; $month++; } //echo " weeknr_to_date($weeknr, $year): return array_to_db_date( array( $weeknr_days, $month, $year ) ): ".array_to_db_date( array( $weeknr_days, $month, $year ) )."<br /><br />"; if( $weeknr_days < 10 ) $weeknr_days = '0' . (int)$weeknr_days; if( $month < 10 ) $month = '0' . (int)$month; return array_to_db_date( array( $weeknr_days, $month, $year ) ); } ?> Pls help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.