Jump to content
MakeWebGames

Jail time in minutes not days?


marvin

Recommended Posts

Why would you want it in minutes , you want people to know how long they are banned from your game from , you dont want them to be confused when they go on your game and it says " you are banned for something like 999674 minutes

999674 is equal to 694 days. Im customizing the game to how my members want it played. Minutes works better in my situation.

Link to comment
Share on other sites

/**
* A function for making time periods readable
*
* @author      Aidan Lister <[email protected]>
* @version     2.0.1
* @link        http://aidanlister.com/2004/04/making-time-periods-readable/
* @param       int     number of seconds elapsed
* @param       string  which time periods to display
* @param       bool    whether to show zero time periods
*/
function time_duration($seconds, $use = null, $zeros = false)
{
   // Define time periods
   $periods = array (
       'years'     => 31556926,
       'Months'    => 2629743,
       'weeks'     => 604800,
       'days'      => 86400,
       'hours'     => 3600,
       'minutes'   => 60,
       'seconds'   => 1
       );

   // Break into periods
   $seconds = (float) $seconds;
   $segments = array();
   foreach ($periods as $period => $value) {
       if ($use && strpos($use, $period[0]) === false) {
           continue;
       }
       $count = floor($seconds / $value);
       if ($count == 0 && !$zeros) {
           continue;
       }
       $segments[strtolower($period)] = $count;
       $seconds = $seconds % $value;
   }

   // Build the string
   $string = array();
   foreach ($segments as $key => $value) {
       $segment_name = substr($key, 0, -1);
       $segment = $value . ' ' . $segment_name;
       if ($value != 1) {
           $segment .= 's';
       }
       $string[] = $segment;
   }

   return implode(', ', $string);
}

 

So if its currently stored as a timestamp in the future then do. time() - $storedTimeStamp. If its stored as seconds, then just use that.

Send that to this like time_duration(time,'m');

M means minutes only.

Link to comment
Share on other sites

/**
* A function for making time periods readable
*
* @author      Aidan Lister <[email protected]>
* @version     2.0.1
* @link        http://aidanlister.com/2004/04/making-time-periods-readable/
* @param       int     number of seconds elapsed
* @param       string  which time periods to display
* @param       bool    whether to show zero time periods
*/
function time_duration($seconds, $use = null, $zeros = false)
{
   // Define time periods
   $periods = array (
       'years'     => 31556926,
       'Months'    => 2629743,
       'weeks'     => 604800,
       'days'      => 86400,
       'hours'     => 3600,
       'minutes'   => 60,
       'seconds'   => 1
       );

   // Break into periods
   $seconds = (float) $seconds;
   $segments = array();
   foreach ($periods as $period => $value) {
       if ($use && strpos($use, $period[0]) === false) {
           continue;
       }
       $count = floor($seconds / $value);
       if ($count == 0 && !$zeros) {
           continue;
       }
       $segments[strtolower($period)] = $count;
       $seconds = $seconds % $value;
   }

   // Build the string
   $string = array();
   foreach ($segments as $key => $value) {
       $segment_name = substr($key, 0, -1);
       $segment = $value . ' ' . $segment_name;
       if ($value != 1) {
           $segment .= 's';
       }
       $string[] = $segment;
   }

   return implode(', ', $string);
}

 

So if its currently stored as a timestamp in the future then do. time() - $storedTimeStamp. If its stored as seconds, then just use that.

Send that to this like time_duration(time,'m');

M means minutes only.

do I have to make a new php file for that or where do I put all that?

Link to comment
Share on other sites

Thats just a function. Post it outside of your current function or class or method, or whatever.

Then just reference it. Depending if your in a class file or not simply time_duration() or self::time_duration() or $this->time_duration().

I shouldn't of posted, since I code in a custom framework & I don't know one bit of how the structure of MCCodes is.

Link to comment
Share on other sites

Thats just a function. Post it outside of your current function or class or method, or whatever.

Then just reference it. Depending if your in a class file or not simply time_duration() or self::time_duration() or $this->time_duration().

I shouldn't of posted, since I code in a custom framework & I don't know one bit of how the structure of MCCodes is.

Im not smart enough to understand what your saying.

Link to comment
Share on other sites

Neon is telling you how to call the function. If that's too complicated, try using this one:

 

function time_format($secs) {
  $times = array(3600, 60, 1);
  $time = '';
  $tmp = '';
  for($i = 0; $i < 3; $i++) {
     $tmp = floor($secs / $times[$i]);
     if($tmp < 1) {
        $tmp = '00';
     }
     elseif($tmp < 10) {
        $tmp = '0' . $tmp;
     }
     $time .= $tmp;
     if($i < 2) {
        $time .= ':';
     }
     $secs = $secs % $times[$i];
  }
  return $time;
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...