Return to Snippet

Revision: 17282
at October 21, 2009 08:06 by stavelin


Updated Code
<?
  $day   = 21;     // Day of the countdown
  $month = 12;      // Month of the countdown
  $year  = 2009;   // Year of the countdown
  $hour  = 23;     // Hour of the day (east coast time)

  $sekunder = ((mktime ($hour,0,0,$month,$day,$year)-time(void))); // sekunder

// s���¥ Aidans kode:

/**
 * A function for making time periods readable
 *
 * @author      Aidan Lister <[email protected]>
 * @version     2.0.0
 * @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 (
        '&aring;r'      => 31556926,
        'm&aring;neder' => 2629743,
        'uker'          => 604800,
        'dager'         => 86400,
        'timer'         => 3600,
        'minutter'      => 60,
        'sekunder'      => 1
        );

    // Break into periods
    $seconds = (float) $seconds;
    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
    foreach ($segments as $key => $value) {
        if (($key == 'uker' && $value ==1)or($key == 'timer' && $value ==1)) {
            $segment_name = substr($key, 0, -1);
} elseif ($key == '&aring;r') {
                $segment_name = $key;
            } else {
        $segment_name = substr($key, 0, -2);
        }
        $segment = $value . ' ' . $segment_name;
        if ($value != 1) {
//            $segment .= 's';
            $segment .= 'er';
        }
        $array[] = $segment;
    }

    $str = implode(', ', $array);
    return $str;
}
?>

<?php
echo time_duration($sekunder);
// echo time_duration(100000000, null, true);
// echo time_duration(100000000, 'yMw');
// echo time_duration(100000000, 'd');
?>

// Prints dates ala 3 m���¥neder, 3 uker, 19 timer, 1 minutt

Revision: 17281
at September 8, 2009 12:51 by stavelin


Updated Code
<?
  $day   = 21;     // Day of the countdown
  $month = 12;      // Month of the countdown
  $year  = 2009;   // Year of the countdown
  $hour  = 23;     // Hour of the day (east coast time)

  $sekunder = ((mktime ($hour,0,0,$month,$day,$year)-time(void))); // sekunder

// s�¥ Aidans kode:

/**
 * A function for making time periods readable
 *
 * @author      Aidan Lister <[email protected]>
 * @version     2.0.0
 * @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 (
        '&aring;r'      => 31556926,
        'm&aring;neder' => 2629743,
        'uker'          => 604800,
        'dager'         => 86400,
        'timer'         => 3600,
        'minutter'      => 60,
        'sekunder'      => 1
        );

    // Break into periods
    $seconds = (float) $seconds;
    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
    foreach ($segments as $key => $value) {
        if (($key == 'uker' && $value ==1)or($key == 'timer' && $value ==1)) {
            $segment_name = substr($key, 0, -1);
        } else {
        $segment_name = substr($key, 0, -2);
        }
        $segment = $value . ' ' . $segment_name;
        if ($value != 1) {
//            $segment .= 's';
            $segment .= 'er';
        }
        $array[] = $segment;
    }

    $str = implode(', ', $array);
    return $str;
}
?>

<?php
echo time_duration($sekunder);
// echo time_duration(100000000, null, true);
// echo time_duration(100000000, 'yMw');
// echo time_duration(100000000, 'd');
?>

// Prints dates ala 3 m�¥neder, 3 uker, 19 timer, 1 minutt

Revision: 17280
at September 8, 2009 12:50 by stavelin


Updated Code
<?
  $day   = 21;     // Day of the countdown
  $month = 12;      // Month of the countdown
  $year  = 2009;   // Year of the countdown
  $hour  = 23;     // Hour of the day (east coast time)

  $sekunder = ((mktime ($hour,0,0,$month,$day,$year)-time(void))); // sekunder

// så Aidans kode:

/**
 * A function for making time periods readable
 *
 * @author      Aidan Lister <[email protected]>
 * @version     2.0.0
 * @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 (
        '&aring;r'      => 31556926,
        'm&aring;neder' => 2629743,
        'uker'          => 604800,
        'dager'         => 86400,
        'timer'         => 3600,
        'minutter'      => 60,
        'sekunder'      => 1
        );

    // Break into periods
    $seconds = (float) $seconds;
    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
    foreach ($segments as $key => $value) {
        if (($key == 'uker' && $value ==1)or($key == 'timer' && $value ==1)) {
            $segment_name = substr($key, 0, -1);
        } else {
        $segment_name = substr($key, 0, -2);
        }
        $segment = $value . ' ' . $segment_name;
        if ($value != 1) {
//            $segment .= 's';
            $segment .= 'er';
        }
        $array[] = $segment;
    }

    $str = implode(', ', $array);
    return $str;
}
?>

<?php
echo time_duration($sekunder);
// echo time_duration(100000000, null, true);
// echo time_duration(100000000, 'yMw');
// echo time_duration(100000000, 'd');
?>

// Prints dates ala 3 måneder, 3 uker, 19 timer, 1 minutt

Revision: 17279
at August 30, 2009 15:32 by stavelin


Initial Code
<?
  $day   = 21;     // Day of the countdown
  $month = 12;      // Month of the countdown
  $year  = 2009;   // Year of the countdown
  $hour  = 23;     // Hour of the day (east coast time)

  $sekunder = ((mktime ($hour,0,0,$month,$day,$year)-time(void))); // sekunder

// så Aidans kode:

/**
 * A function for making time periods readable
 *
 * @author      Aidan Lister <[email protected]>
 * @version     2.0.0
 * @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 (
        '&aring;r'      => 31556926,
        'm&aring;neder' => 2629743,
        'uker'          => 604800,
        'dager'         => 86400,
        'timer'         => 3600,
        'minutter'      => 60,
        'sekunder'      => 1
        );

    // Break into periods
    $seconds = (float) $seconds;
    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
    foreach ($segments as $key => $value) {
        $segment_name = substr($key, 0, -2);
//        $segment_name = substr($key, 0, -1);
        $segment = $value . ' ' . $segment_name;
        if ($value != 1) {
//            $segment .= 's';
            $segment .= 'er';
        }
        $array[] = $segment;
    }

    $str = implode(', ', $array);
    return $str;
}
?>

<?php
echo time_duration($sekunder);
// echo time_duration(100000000, null, true);
// echo time_duration(100000000, 'yMw');
// echo time_duration(100000000, 'd');
?>

// Prints dates ala 3 måneder, 3 uker, 19 timer, 1 minutt

Initial URL
http://aidanlister.com/2004/04/making-time-periods-readable/

Initial Description
This is the Aidan Lister PHP countdown, translated for use in Norway.
No  more 133 days untill christmas, but insted 3 months and 3 weeks.

Initial Title
Pen PHP nedteller

Initial Tags
php

Initial Language
PHP