Jump to content

Setting Office TIming??


tuxbuddy

Recommended Posts

This is a code written for Timing and Escalation Stuffs.I need to modify it to office timing from 10:00 to 5:30 rather than 24/7.Anyone who can hep me with this?

 

<?php

* Purpose:
* --------
* Date and Time related functions
* 

// Defines for easy handling of time
define( 'TIME_YEAR', 2 );
define( 'TIME_MONTH', 1 );
define( 'TIME_DAY', 0 );
define( 'TIME_HOUR', 3 );
define( 'TIME_MINUTE', 4 );
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 ) ); 
}

?>

Link to comment
https://forums.phpfreaks.com/topic/101034-setting-office-timing/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.