Wednesday, December 23, 2009

An excellent PHP script to handle time difference

I am working on a project that involves displaying the time difference between a start and end time on a website.

The following script is lifted directly from: http://aidanlister.com/2004/04/making-time-periods-readable/


/**
* A function for making time periods readable
*
* @author Aidan Lister
* @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 (
'years' => 31556926,
'Months' => 2629743,
'weeks' => 604800,
'days' => 86400,
'hours' => 3600,
'minutes' => 60,
'seconds' => 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, -1);
$segment = $value . ' ' . $segment_name;
if ($value != 1) {
$segment .= 's';
}
$array[] = $segment;
}

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

Tuesday, December 8, 2009

Things to do with an iPod and Fedora

My iPod Nano 8gb. ( not the fancy new one with the video ) works perfectly well inside fedora so long as you bear in mind the following basic points:
  1. The thing doesn't play ogg files so if you have any of those on your system, they can not be synced.
  2. Depending on the application you use, you end up with podcasts being saved under music.
  3. Sometimes you get images sometimes you don't.
  4. Albums with Various Artists do not appear under compilations. Instead your Artists menu shows a long list of artists most of which only have one track.
Applications that ship with fedora and support the iPod:
  1. gtk-pod ( manage your ipod )
  2. gpodder ( download podcasts etc - these actually go into the podcasts menu on the device. )
  3. Amarok
  4. Rythmbox

Other music applications I have played with that support the iPod:
  1. Songbird 2
I should not here that once again, I have found that Amarok 1.4 is still the best player out there. I had to install it using the F11 binaries ( just search for them on google ) and a couple of symlinks:
  1. ln -s /usr/lib64/libssl.so.10 libssl.so.8
  2. ln -s /usr/lib64/libcrypt.so.10 libcrypt.so.8
So there you go!