LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-08-2008, 04:25 AM   #1
ajeetraina
Member
 
Registered: Jun 2007
Location: India
Distribution: Ubuntu,Red Hat, Fedora
Posts: 292

Rep: Reputation: 30
Timing Issue??


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
Code:
<?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 "&nbsp;&nbsp;&nbsp;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 "&nbsp;&nbsp;&nbsp;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 "&nbsp;&nbsp;&nbsp;weeknr_to_date($weeknr, $year): while( $weeknr_days >= ".$month_days[$month]." )<br />";

                $weeknr_days -= $month_days[$month];
                $month++;
        }



        //echo "&nbsp;&nbsp;&nbsp;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.
 
Old 05-08-2008, 06:17 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I'm not sure I see your problem.
The tool can HANDLE 24/7 support, but if you only USE it Mon-Fri, 8 hrs a day. I doubt that's going to break anything....
ie I sincerely doubt there's a check in the code to see its being used or not....
 
Old 05-08-2008, 11:40 PM   #3
ajeetraina
Member
 
Registered: Jun 2007
Location: India
Distribution: Ubuntu,Red Hat, Fedora
Posts: 292

Original Poster
Rep: Reputation: 30
I can provide you with tool if you are ready to help me out.It wont be difficult for expert like you but is difficult for newbie like me.

Pls Help.

Waiting for your Reply
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Monior out of timing danandbecky Linux - Newbie 1 11-30-2006 08:30 PM
how to start timing and print the timing result on portions of java codes ?? alred Programming 2 05-15-2006 10:00 AM
timing a function saajii Programming 1 10-25-2004 02:37 AM
mencoder timing delos Linux - Software 1 09-27-2004 02:24 PM
timing in c++ deveraux83 Programming 2 04-20-2004 05:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration