Get Windows Uptime/Load with PHP? - php

Our billing system supports network monitoring and shows uptime and load percentage, however, the PHP status script they provide says it is Linux only. Configuring PHP to work with Server 2008 is not an issue, but I don't know PHP. Would it be possible to manipulate this code to work on Windows?
<?php
/*
*************************************************************************
* *
* WHMCompleteSolution - Client Management, Billing & Support System *
* Copyright (c) 2007-2008 WHMCS. All Rights Reserved, *
* Release Date: 12th December 2008 *
* Version 3.8.1 Stable *
* *
*************************************************************************
* *
* Email: info#whmcs.com *
* Website: htttp://www.whmcs.com *
* *
*************************************************************************
This file can be uploaded to each of your linux web servers in order to
display current load and uptime statistics for the server in the Server
Status page of the WHMCS Client Area and Admin Area Homepage
*/
error_reporting(0);
if (ini_get('disable_functions')) {
$disabled_funcs=array_map('trim',explode(',',ini_get('disable_functions')));
}
$action=$_GET["action"];
if ($action=="phpinfo") {
} else {
$users[0]="Unavailable";
$users[1]="--";
$loadnow="Unavailable";
$load15="--";
$load30="--";
if (in_array('exec',$disabled_funcs)) {
$load=file_get_contents("/proc/loadavg");
$load=explode(' ',$load);
$loadnow=$load[0];
$load15=$load[1];
$load30=$load[2];
} else {
$reguptime=trim(exec("uptime"));
if ($reguptime) {
if (preg_match("/, *(\d) (users?), .*: (.*), (.*), (.*)/",$reguptime,$uptime)) {
$users[0]=$uptime[1];
$users[1]=$uptime[2];
$loadnow=$uptime[3];
$load15=$uptime[4];
$load30=$uptime[5];
}
}
}
if (in_array('shell_exec',$disabled_funcs)) {
$uptime_text=file_get_contents("/proc/uptime");
$uptime=substr($uptime_text,0,strpos($uptime_text," "));
} else {
$uptime=shell_exec("cut -d. -f1 /proc/uptime");
}
$days=floor($uptime/60/60/24);
$hours=str_pad($uptime/60/60%24,2,"0",STR_PAD_LEFT);
$mins=str_pad($uptime/60%60,2,"0",STR_PAD_LEFT);
$secs=str_pad($uptime%60,2,"0",STR_PAD_LEFT);
$phpver=phpversion();
if(function_exists("mysql_get_client_info()")) $mysqlver=mysql_get_client_info();
if(function_exists("zend_version()")) $zendver=zend_version();
echo "<load>$loadnow</load>\n";
echo "<uptime>$days Days $hours:$mins:$secs</uptime>\n";
echo "<phpver>$phpver</phpver>\n";
echo "<mysqlver>$mysqlver</mysqlver>\n";
echo "<zendver>$zendver</zendver>\n";
}
?>

This version combines some of the ideas suggested here and some of my own into a file that should work roughly the same on both *nix and Windows. Also corrected a few glaring errors/lazy codes in the original.
Will not work on Windows if exec() is disabled. There is no way around this that I can see.
Let me know how you get on.
<?php
/*
*************************************************************************
* *
* WHMCompleteSolution - Client Management, Billing & Support System *
* Copyright (c) 2007-2008 WHMCS. All Rights Reserved, *
* Release Date: 12th December 2008 *
* Version 3.8.1 Stable *
* *
*************************************************************************
* *
* Email: info#whmcs.com *
* Website: htttp://www.whmcs.com *
* *
*************************************************************************
Modified by DaveRandom, Sept 2011
This file can be uploaded to each of your linux/Windows web servers in
order to display current load and uptime statistics for the server in the
Server Status page of the WHMCS Client Area and Admin Area Homepage
*/
error_reporting(0);
if (ini_get('disable_functions')) {
$disabled_funcs = array_map('trim',explode(',',ini_get('disable_functions')));
}
$action = (isset($_GET["action"])) ? $_GET["action"] : NULL;
if ($action == "phpinfo") {
// Seems as though something is missing here - maybe phpinfo() ?
} else {
// Stuff that works everywhere
$phpver = phpversion();
$mysqlver = (function_exists("mysql_get_client_info")) ? mysql_get_client_info() : '';
$zendver = (function_exists("zend_version")) ? zend_version() : '';
// Default values
$users[0] = $loadnow = "Unavailable";
$users[1] = $load15 = $load30 = "--";
$uptime_str = '';
if (strpos(strtolower(PHP_OS),'win') !== FALSE) {
// For Windaz
if (!in_array('exec',$disabled_funcs)) {
set_time_limit(150); // 'systeminfo' command can take a while...
$uptime = exec('systeminfo | find "System Up"');
$parts = explode(':',$uptime);
$parts = array_pop($parts);
$parts = explode(',',trim($parts));
foreach (array('days','hours','mins','secs') as $k => $v) {
$parts[$k] = explode(' ',trim($parts[$k]));
$$v = ($k) ? str_pad(array_shift($parts[$k]),2,'0',STR_PAD_LEFT) : array_shift($parts[$k]);
}
$uptime_str = "$days Days $hours:$mins:$secs";
exec('typeperf -sc 1 "\Processor(*)\% Processor Time"',$result);
for ($i = 0; trim($result[$i]) == ''; $i++) continue;
$parts = explode(',',$result[++$i]);
$loadnow = (is_numeric($loadnow = trim(trim(array_pop($parts)),'"\''))) ? $loadnow : 'Unavailable';
}
} else {
// For *nix
if (in_array('exec',$disabled_funcs)) {
$load = file_get_contents("/proc/loadavg");
$load = explode(' ',$load);
$loadnow = $load[0];
$load15 = $load[1];
$load30 = $load[2];
} else if (($reguptime = trim(exec("uptime"))) && preg_match("/, *(\\d) (users?), .*: (.*), (.*), (.*)/",$reguptime,$uptime)) {
$users[0] = $uptime[1];
$users[1] = $uptime[2];
$loadnow = $uptime[3];
$load15 = $uptime[4];
$load30 = $uptime[5];
}
if (in_array('shell_exec',$disabled_funcs)) {
$uptime_text = file_get_contents("/proc/uptime");
$uptime = substr($uptime_text,0,strpos($uptime_text," "));
} else {
$uptime = shell_exec("cut -d. -f1 /proc/uptime");
}
$days = floor($uptime/60/60/24);
$hours = str_pad($uptime/60/60%24,2,"0",STR_PAD_LEFT);
$mins = str_pad($uptime/60%60,2,"0",STR_PAD_LEFT);
$secs = str_pad($uptime%60,2,"0",STR_PAD_LEFT);
$uptime_str = "$days Days $hours:$mins:$secs";
}
echo "<load>$loadnow</load>\n";
echo "<uptime>$uptime_str</uptime>\n";
echo "<phpver>$phpver</phpver>\n";
echo "<mysqlver>$mysqlver</mysqlver>\n";
echo "<zendver>$zendver</zendver>\n";
}

You can try the following on a windows box to get the system uptime in a string:
$uptimeData = shell_exec('systeminfo | find "Time:"');
If you want the data in a different format you'll probably need to use a regex, but it looks like your script is just dumping the information to an xml file.

For uptime, you can do an exec() call against systeminfo | find "System Up" and then process the output.
For load, you can run wmic /namespace:\\root\cimv2 path Win32_Processor get LoadPercentage, though this only gets the current CPU load and not the historical averages.
At any rate, you will have to detect the operating system (see PHP_OS) and run the correct commands for the system your script is running on.

<?php echo shell_exec("systeminfo |find 'Up Time'");?>
But you need to set php max execution time at least to 120 (execution of this command takes some time)

try This :
Code : https://miladworkshop.ir/paste/Uzype9
<?php
/*
This Code Create By Milad Maldar ( miladworkshop )
Website : https://miladworkshop.ir
Telegram : #miladworkshop
*/
function service_uptime()
{
$uptime_sys = exec('net statistics server | find "Statistics since"');
$uptime_sys = str_replace("Statistics since ", "", $uptime_sys);
$uptime_dte = exec('date | find "The current date is:"');
$uptime_dte = str_replace("The current date is: Sat ", "", $uptime_dte);
$uptime_dte = explode("/", $uptime_dte);
$uptime_tme = exec('time | find "The current time is:"');
$uptime_tme = str_replace("The current time is: ", "", $uptime_tme);
$uptime_tme = explode(":", $uptime_tme);
$uptime_date = explode("/", $uptime_sys);
$uptime_time = explode(":", $uptime_sys);
$system_time = strtotime("{$uptime_dte[2]}-{$uptime_dte[0]}-{$uptime_dte[1]} {$uptime_tme[0]}:{$uptime_tme[1]}:{$uptime_tme[2]}");
$y = substr($uptime_date[2], 0, 4);
$m = ($uptime_date[0] < 10) ? "0". $uptime_date[0] : $uptime_date[0];
$d = ($uptime_date[1] < 10) ? "0". $uptime_date[1] : $uptime_date[1];
$i = ($uptime_time[1] < 10) ? "0". $uptime_time[1] : $uptime_time[1];
$h = (substr($uptime_time[0], strpos($uptime_time[0], "{$y} ") + 5) < 10) ? "0". substr($uptime_time[0], strpos($uptime_time[0], "{$y} ") + 5) : substr($uptime_time[0], strpos($uptime_time[0], "{$y} ") + 5);
if (substr($uptime_sys, -2) == "PM")
{
$h = str_replace("01", "13", $h);
$h = str_replace("02", "14", $h);
$h = str_replace("03", "15", $h);
$h = str_replace("04", "16", $h);
$h = str_replace("05", "17", $h);
$h = str_replace("06", "18", $h);
$h = str_replace("07", "19", $h);
$h = str_replace("08", "20", $h);
$h = str_replace("09", "21", $h);
$h = str_replace("10", "22", $h);
$h = str_replace("11", "23", $h);
$h = str_replace("12", "00", $h);
}
$up = strtotime("{$y}-{$m}-{$d} {$h}:{$i}:00");
$string = "";
$seconds = $system_time - $up;
$days = intval(intval($seconds) / (3600*24));
$hours = (intval($seconds) / 3600) % 24;
$minutes = (intval($seconds) / 60) % 60;
$seconds = (intval($seconds)) % 60;
if($days> 0) { $string .= "{$days} days "; }
if($hours > 0) { $string .= "{$hours} hours "; }
if($minutes > 0) { $string .= "{$minutes} minutes "; }
if ($seconds > 0) { $string .= "{$seconds} seconds"; }
return $string;
}
echo service_uptime();
?>

Related

Detecting and storing length of audio files in a table [duplicate]

Is there any PHP function that will give me the MP3 duration. I looked at ID 3 function but i don't see any thing there for duration and apart from this,id3 is some kind of tag,which will not be there in all MP3 so using this will not make any sense.
This should work for you, notice the getduration function: http://www.zedwood.com/article/127/php-calculate-duration-of-mp3
Install getid3, but if you only need duration, you can delete all but these modules:
module.audio.mp3.php
module.tag.id3v1.php
module.tag.apetag.php
module.tag.id3v2.php
Access the duration with code like this:
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($pathName);
$len= #$ThisFileInfo['playtime_string']; // playtime in minutes:seconds, formatted string
Get it at Sourceforge
I have passed so many time, but without getID3 (http://getid3.sourceforge.net/) to get duration of audio file not possible.
1) First download library of getID3 using below link:
https://github.com/JamesHeinrich/getID3/archive/master.zip
2) Try this below code:
<?php
include("getid3/getid3.php");
$filename = 'bcd4ecc6bf521da9b9a2d8b9616d1505.wav';
$getID3 = new getID3;
$file = $getID3->analyze($filename);
$playtime_seconds = $file['playtime_seconds'];
echo gmdate("H:i:s", $playtime_seconds);
?>
You can get the duration of an mp3 or many other audio/video files by using ffmpeg.
Install ffmpeg in your server.
Make sure that php shell_exec is not restricted in your php.
// Discriminate only the audio/video files you want
if(preg_match('/[^?#]+\.(?:wma|mp3|wav|mp4)/', strtolower($file))){
$filepath = /* your file path */;
// execute ffmpeg form linux shell and grab duration from output
$result = shell_exec("ffmpeg -i ".$filepath.' 2>&1 | grep -o \'Duration: [0-9:.]*\'');
$duration = str_replace('Duration: ', '', $result); // 00:05:03.25
//get the duration in seconds
$timeArr = preg_split('/:/', str_replace('s', '', $duration[0]));
$t = $this->_times[$file] = (($timeArr[3])? $timeArr[3]*1 + $timeArr[2] * 60 + $timeArr[1] * 60 * 60 : $timeArr[2] + $timeArr[1] * 60)*1000;
}
<?php
class MP3File
{
protected $filename;
public function __construct($filename)
{
$this->filename = $filename;
}
public static function formatTime($duration) //as hh:mm:ss
{
//return sprintf("%d:%02d", $duration/60, $duration%60);
$hours = floor($duration / 3600);
$minutes = floor( ($duration - ($hours * 3600)) / 60);
$seconds = $duration - ($hours * 3600) - ($minutes * 60);
return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
}
//Read first mp3 frame only... use for CBR constant bit rate MP3s
public function getDurationEstimate()
{
return $this->getDuration($use_cbr_estimate=true);
}
//Read entire file, frame by frame... ie: Variable Bit Rate (VBR)
public function getDuration($use_cbr_estimate=false)
{
$fd = fopen($this->filename, "rb");
$duration=0;
$block = fread($fd, 100);
$offset = $this->skipID3v2Tag($block);
fseek($fd, $offset, SEEK_SET);
while (!feof($fd))
{
$block = fread($fd, 10);
if (strlen($block)<10) { break; }
//looking for 1111 1111 111 (frame synchronization bits)
else if ($block[0]=="\xff" && (ord($block[1])&0xe0) )
{
$info = self::parseFrameHeader(substr($block, 0, 4));
if (empty($info['Framesize'])) { return $duration; } //some corrupt mp3 files
fseek($fd, $info['Framesize']-10, SEEK_CUR);
$duration += ( $info['Samples'] / $info['Sampling Rate'] );
}
else if (substr($block, 0, 3)=='TAG')
{
fseek($fd, 128-10, SEEK_CUR);//skip over id3v1 tag size
}
else
{
fseek($fd, -9, SEEK_CUR);
}
if ($use_cbr_estimate && !empty($info))
{
return $this->estimateDuration($info['Bitrate'],$offset);
}
}
return round($duration);
}
private function estimateDuration($bitrate,$offset)
{
$kbps = ($bitrate*1000)/8;
$datasize = filesize($this->filename) - $offset;
return round($datasize / $kbps);
}
private function skipID3v2Tag(&$block)
{
if (substr($block, 0,3)=="ID3")
{
$id3v2_major_version = ord($block[3]);
$id3v2_minor_version = ord($block[4]);
$id3v2_flags = ord($block[5]);
$flag_unsynchronisation = $id3v2_flags & 0x80 ? 1 : 0;
$flag_extended_header = $id3v2_flags & 0x40 ? 1 : 0;
$flag_experimental_ind = $id3v2_flags & 0x20 ? 1 : 0;
$flag_footer_present = $id3v2_flags & 0x10 ? 1 : 0;
$z0 = ord($block[6]);
$z1 = ord($block[7]);
$z2 = ord($block[8]);
$z3 = ord($block[9]);
if ( (($z0&0x80)==0) && (($z1&0x80)==0) && (($z2&0x80)==0) && (($z3&0x80)==0) )
{
$header_size = 10;
$tag_size = (($z0&0x7f) * 2097152) + (($z1&0x7f) * 16384) + (($z2&0x7f) * 128) + ($z3&0x7f);
$footer_size = $flag_footer_present ? 10 : 0;
return $header_size + $tag_size + $footer_size;//bytes to skip
}
}
return 0;
}
public static function parseFrameHeader($fourbytes)
{
static $versions = array(
0x0=>'2.5',0x1=>'x',0x2=>'2',0x3=>'1', // x=>'reserved'
);
static $layers = array(
0x0=>'x',0x1=>'3',0x2=>'2',0x3=>'1', // x=>'reserved'
);
static $bitrates = array(
'V1L1'=>array(0,32,64,96,128,160,192,224,256,288,320,352,384,416,448),
'V1L2'=>array(0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384),
'V1L3'=>array(0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320),
'V2L1'=>array(0,32,48,56, 64, 80, 96,112,128,144,160,176,192,224,256),
'V2L2'=>array(0, 8,16,24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160),
'V2L3'=>array(0, 8,16,24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160),
);
static $sample_rates = array(
'1' => array(44100,48000,32000),
'2' => array(22050,24000,16000),
'2.5' => array(11025,12000, 8000),
);
static $samples = array(
1 => array( 1 => 384, 2 =>1152, 3 =>1152, ), //MPEGv1, Layers 1,2,3
2 => array( 1 => 384, 2 =>1152, 3 => 576, ), //MPEGv2/2.5, Layers 1,2,3
);
//$b0=ord($fourbytes[0]);//will always be 0xff
$b1=ord($fourbytes[1]);
$b2=ord($fourbytes[2]);
$b3=ord($fourbytes[3]);
$version_bits = ($b1 & 0x18) >> 3;
$version = $versions[$version_bits];
$simple_version = ($version=='2.5' ? 2 : $version);
$layer_bits = ($b1 & 0x06) >> 1;
$layer = $layers[$layer_bits];
$protection_bit = ($b1 & 0x01);
$bitrate_key = sprintf('V%dL%d', $simple_version , $layer);
$bitrate_idx = ($b2 & 0xf0) >> 4;
$bitrate = isset($bitrates[$bitrate_key][$bitrate_idx]) ? $bitrates[$bitrate_key][$bitrate_idx] : 0;
$sample_rate_idx = ($b2 & 0x0c) >> 2;//0xc => b1100
$sample_rate = isset($sample_rates[$version][$sample_rate_idx]) ? $sample_rates[$version][$sample_rate_idx] : 0;
$padding_bit = ($b2 & 0x02) >> 1;
$private_bit = ($b2 & 0x01);
$channel_mode_bits = ($b3 & 0xc0) >> 6;
$mode_extension_bits = ($b3 & 0x30) >> 4;
$copyright_bit = ($b3 & 0x08) >> 3;
$original_bit = ($b3 & 0x04) >> 2;
$emphasis = ($b3 & 0x03);
$info = array();
$info['Version'] = $version;//MPEGVersion
$info['Layer'] = $layer;
//$info['Protection Bit'] = $protection_bit; //0=> protected by 2 byte CRC, 1=>not protected
$info['Bitrate'] = $bitrate;
$info['Sampling Rate'] = $sample_rate;
$info['Framesize'] = self::framesize($layer, $bitrate, $sample_rate, $padding_bit);
$info['Samples'] = $samples[$simple_version][$layer];
return $info;
}
private static function framesize($layer, $bitrate,$sample_rate,$padding_bit)
{
if ($layer==1)
return intval(((12 * $bitrate*1000 /$sample_rate) + $padding_bit) * 4);
else //layer 2, 3
return intval(((144 * $bitrate*1000)/$sample_rate) + $padding_bit);
}
}
?>
<?php
$mp3file = new MP3File("Chal_Halke.mp3");//http://www.npr.org/rss/podcast.php?id=510282
$duration1 = $mp3file->getDurationEstimate();//(faster) for CBR only
$duration2 = $mp3file->getDuration();//(slower) for VBR (or CBR)
echo "duration: $duration1 seconds"."\n";
?>
There is no native php function to do this.
Depending on your server environment, you may use a tool such as MP3Info.
$length = shell_exec('mp3info -p "%S" sample.mp3'); // total time in seconds
As earlier, I provided a solution for both mp3 and WAV files, Now this solution is specifically for the only WAV file with more precision but with longer evaluation time than the earlier solution.
function calculateWavDuration( $file ) {
$fp = fopen($file, 'r');
if (fread($fp, 4) == "RIFF") {
fseek($fp, 20);
$raw_header = fread($fp, 16);
$header = unpack('vtype/vchannels/Vsamplerate/Vbytespersec/valignment/vbits', $raw_header);
$pos = ftell($fp);
while (fread($fp, 4) != "data" && !feof($fp)) {
$pos++;
fseek($fp, $pos);
}
$raw_header = fread($fp, 4);
$data = unpack('Vdatasize', $raw_header);
$sec = $data[datasize] / $header[bytespersec];
$minutes = intval(($sec / 60) % 60);
$seconds = intval($sec % 60);
return str_pad($minutes, 2, "0", STR_PAD_LEFT) . ":" . str_pad($seconds, 2, "0", STR_PAD_LEFT);
}
}
$file = '1.wav'; //Enter File wav
calculateWavDuration($file);
The MP3 length is not stored anywhere (in the "plain" MP3 format), since MP3 is designed to be "split" into frames and those frames will remain playable.
http://mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm
If you have no ID tag on which to rely, what you would need to do (there are tools and PHP classes that do this) is to read the whole MP3 file and sum the durations of each frame.
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($pathName);
// playtime in minutes:seconds, formatted string
$len = #$ThisFileInfo['playtime_string'];
//don't get playtime_string, but get playtime_seconds
$len = #$ThisFileInfo['playtime_seconds']*1000; //*1000 as calculate millisecond
I hope this helps you.
Finally, I developed a solution with my own calculations. This solution works best for mp3 and WAV files formats. However minor precision variations are expected. The solution is in PHP. I take little bit clue from WAV
function calculateFileSize($file){
$ratio = 16000; //bytespersec
if (!$file) {
exit("Verify file name and it's path");
}
$file_size = filesize($file);
if (!$file_size)
exit("Verify file, something wrong with your file");
$duration = ($file_size / $ratio);
$minutes = floor($duration / 60);
$seconds = $duration - ($minutes * 60);
$seconds = round($seconds);
echo "$minutes:$seconds minutes";
}
$file = 'apple-classic.mp3'; //Enter File Name mp3/wav
calculateFileSize($file);
If you have FFMpeg installed, getting the duration is quite simple with FFProbe
$filepath = 'example.mp3';
$ffprobe = \FFMpeg\FFProbe::create();
$duration = $ffprobe->format($filepath)->get('duration');
echo gmdate('H:i:s', $duration);
FFMpeg is mentioned elsewhere, but here's a fuller explanation and example implementation.
Install ffmpeg for your system. E.g., on Ubuntu:
apt-get update && apt-get -y install ffmpeg
Install php-ffmpeg using Composer:
composer require php-ffmpeg/php-ffmpeg
Example utility class
<?php
namespace App\Utils;
use FFMpeg\FFProbe;
class Audio
{
public static function duration(string $path): float
{
$probe = FFProbe::create();
return $probe->format($path)->get('duration');
}
}
Where $path is the absolute path or URL to your audio file. To use:
$duration = \App\Utils\Audio::duration($path);
echo $duration; // 24.476750
Of course, you can just use it directly where you need it. The point of the utility class example is to show how you use it. You'll want to try/catch calling it in a production setting. If you aren't using composer, see #awavi's answer.

Converting Degree, Minutes, Seconds (DMS) to decimal in PHP

Currently, I'm learning to use Google Maps API. From what I read, the API require the latitude and longitude in Decimal Degree (DD).
In my database, the data is stored as DMS.
Example, 110° 29' 01.1"
I would to ask if you guys have any DMS to DD in php. And, the converter must accept from a single string like the example above.
Regards
You can try if this is working for you.
<?php
function DMStoDD($deg,$min,$sec)
{
// Converting DMS ( Degrees / minutes / seconds ) to decimal format
return $deg+((($min*60)+($sec))/3600);
}
function DDtoDMS($dec)
{
// Converts decimal format to DMS ( Degrees / minutes / seconds )
$vars = explode(".",$dec);
$deg = $vars[0];
$tempma = "0.".$vars[1];
$tempma = $tempma * 3600;
$min = floor($tempma / 60);
$sec = $tempma - ($min*60);
return array("deg"=>$deg,"min"=>$min,"sec"=>$sec);
}
?>
Here's one where you pass in the latitude,longitude in DMS values and returns the converted DMS string. Easy and simnple
function DECtoDMS($latitude, $longitude)
{
$latitudeDirection = $latitude < 0 ? 'S': 'N';
$longitudeDirection = $longitude < 0 ? 'W': 'E';
$latitudeNotation = $latitude < 0 ? '-': '';
$longitudeNotation = $longitude < 0 ? '-': '';
$latitudeInDegrees = floor(abs($latitude));
$longitudeInDegrees = floor(abs($longitude));
$latitudeDecimal = abs($latitude)-$latitudeInDegrees;
$longitudeDecimal = abs($longitude)-$longitudeInDegrees;
$_precision = 3;
$latitudeMinutes = round($latitudeDecimal*60,$_precision);
$longitudeMinutes = round($longitudeDecimal*60,$_precision);
return sprintf('%s%s° %s %s %s%s° %s %s',
$latitudeNotation,
$latitudeInDegrees,
$latitudeMinutes,
$latitudeDirection,
$longitudeNotation,
$longitudeInDegrees,
$longitudeMinutes,
$longitudeDirection
);
}
I wrote a PHP function that does what the question asks: converts a string in degrees/minutes/seconds into decimal degrees. It accepts a number of different formats for the string, and honors direction (NSEW).
Here is the code:
<?php
function convertDMSToDecimal($latlng) {
$valid = false;
$decimal_degrees = 0;
$degrees = 0; $minutes = 0; $seconds = 0; $direction = 1;
// Determine if there are extra periods in the input string
$num_periods = substr_count($latlng, '.');
if ($num_periods > 1) {
$temp = preg_replace('/\./', ' ', $latlng, $num_periods - 1); // replace all but last period with delimiter
$temp = trim(preg_replace('/[a-zA-Z]/','',$temp)); // when counting chunks we only want numbers
$chunk_count = count(explode(" ",$temp));
if ($chunk_count > 2) {
$latlng = $temp; // remove last period
} else {
$latlng = str_replace("."," ",$latlng); // remove all periods, not enough chunks left by keeping last one
}
}
// Remove unneeded characters
$latlng = trim($latlng);
$latlng = str_replace("º","",$latlng);
$latlng = str_replace("'","",$latlng);
$latlng = str_replace("\"","",$latlng);
$latlng = substr($latlng,0,1) . str_replace('-', ' ', substr($latlng,1)); // remove all but first dash
if ($latlng != "") {
// DMS with the direction at the start of the string
if (preg_match("/^([nsewNSEW]?)\s*(\d{1,3})\s+(\d{1,3})\s+(\d+\.?\d*)$/",$latlng,$matches)) {
$valid = true;
$degrees = intval($matches[2]);
$minutes = intval($matches[3]);
$seconds = floatval($matches[4]);
if (strtoupper($matches[1]) == "S" || strtoupper($matches[1]) == "W")
$direction = -1;
}
// DMS with the direction at the end of the string
if (preg_match("/^(-?\d{1,3})\s+(\d{1,3})\s+(\d+(?:\.\d+)?)\s*([nsewNSEW]?)$/",$latlng,$matches)) {
$valid = true;
$degrees = intval($matches[1]);
$minutes = intval($matches[2]);
$seconds = floatval($matches[3]);
if (strtoupper($matches[4]) == "S" || strtoupper($matches[4]) == "W" || $degrees < 0) {
$direction = -1;
$degrees = abs($degrees);
}
}
if ($valid) {
// A match was found, do the calculation
$decimal_degrees = ($degrees + ($minutes / 60) + ($seconds / 3600)) * $direction;
} else {
// Decimal degrees with a direction at the start of the string
if (preg_match("/^(-?\d+(?:\.\d+)?)\s*([nsewNSEW]?)$/",$latlng,$matches)) {
$valid = true;
if (strtoupper($matches[2]) == "S" || strtoupper($matches[2]) == "W" || $degrees < 0) {
$direction = -1;
$degrees = abs($degrees);
}
$decimal_degrees = $matches[1] * $direction;
}
// Decimal degrees with a direction at the end of the string
if (preg_match("/^([nsewNSEW]?)\s*(\d+(?:\.\d+)?)$/",$latlng,$matches)) {
$valid = true;
if (strtoupper($matches[1]) == "S" || strtoupper($matches[1]) == "W")
$direction = -1;
$decimal_degrees = $matches[2] * $direction;
}
}
}
if ($valid) {
return $decimal_degrees;
} else {
return false;
}
}
?>
Here it is on Github with test cases: https://github.com/prairiewest/PHPconvertDMSToDecimal
Solved.
<?php
function DMStoDD($input)
{
$deg = " " ;
$min = " " ;
$sec = " " ;
$inputM = " " ;
print "<br> Input is ".$input." <br>";
for ($i=0; $i < strlen($input); $i++)
{
$tempD = $input[$i];
//print "<br> TempD [$i] is : $tempD";
if ($tempD == iconv("UTF-8", "ISO-8859-1//TRANSLIT", '°') )
{
$newI = $i + 1 ;
//print "<br> newI is : $newI";
$inputM = substr($input, $newI, -1) ;
break;
}//close if degree
$deg .= $tempD ;
}//close for degree
//print "InputM is ".$inputM." <br>";
for ($j=0; $j < strlen($inputM); $j++)
{
$tempM = $inputM[$j];
//print "<br> TempM [$j] is : $tempM";
if ($tempM == "'")
{
$newI = $j + 1 ;
//print "<br> newI is : $newI";
$sec = substr($inputM, $newI, -1) ;
break;
}//close if minute
$min .= $tempM ;
}//close for min
$result = $deg+( (( $min*60)+($sec) ) /3600 );
print "<br> Degree is ". $deg*1 ;
print "<br> Minutes is ". $min ;
print "<br> Seconds is ". $sec ;
print "<br> Result is ". $result ;
return $deg + ($min / 60) + ($sec / 3600);
}
?>
If you also want to include the reference, you might want to use this function:
function DMStoDD($ref, $deg, $min, $sec)
{
$n = $deg + (($min * 60 + $sec) / 3600);
if (($ref == "S") or ($ref == "W")) {
return -$n;
} else {
return $n;
}
}
This works very well:
<?php echo "<td> $deg&#176 $min' $sec&#8243 </td>"; ?>
where deg, min and sec are the angular co-ordinates.

Converting GPRMC GPS data to decimal format in PHP

Tracking devices have the data sent in the $GPRMC which is not what I use in my Code would be googling for a PHP converting method to decimal format no avail.
Just got the solution to this had to boil my head on the content of $GPRMC
sample format e.g $GPRMC,001225,A,2832.1834,N,08101.0536,W,12,25,251211,1.2,E,A*03
Where:
RMC Recommended Minimum sentence C
123519 Fix taken at 12:35:19 UTC
A Status A=active or V=Void.
4807.038,N Latitude 48 deg 07.038' N
01131.000,E Longitude 11 deg 31.000' E
022.4 Speed over the ground in knots
084.4 Track angle in degrees True
230394 Date - 23rd of March 1994
003.1,W Magnetic Variation
*6A The checksum data, always begins with *
And the code:
$gps = $_REQUEST['gps'];
if($gps){
$buffer = $gps;
if(substr($buffer, 0, 5)=='GPRMC'){
$gprmc = explode(',',$buffer);
$data1['lattitude_decimal'] = DMStoDEC($gprmc[3],'lattitude');
$data2['longitude_decimal'] = DMStoDEC($gprmc[5],'longitude');
$data = 'http://maps.google.com/maps?q='.$data1['lattitude_decimal'].','.$data2['longitude_decimal'].'+(PHP Decoded)&iwloc=A';
print_r($data);
echo "\n\n";
}
}
function DMStoDEC($dms, $longlat){
if($longlat == 'lattitude'){
$deg = substr($dms, 0, 2);
$min = substr($dms, 2, 8);
$sec = '';
}
if($longlat == 'longitude'){
$deg = substr($dms, 0, 3);
$min = substr($dms, 3, 8);
$sec='';
}
return $deg+((($min*60)+($sec))/3600);
}
?>
Hope this will help someone
That's the typical post request:
POST /RoyS/?acct=1234&dev=null&gprmc=$GPRMC,132201,A,3128.7540,N,14257.6714,W,000.0,000.0,290314,,*e HTTP/1.1" 200 33 "-" "-"
The line should be $gps = $_REQUEST['gprmc'];. Are you sure about this line?
if(substr($buffer, 0, 5)=='GPRMC') {
Shouldn't it be:
if(substr($buffer, 1, 5)=='GPRMC') {
?
and you definitely ignored NWSE letters!
formula acá
list($dato1, $dato2, $dato3, $lat, $dato5, $lon, $dato7, $velocidad, $dato9, $dato10, $dato11, $dato12) = explode(',', $input_gps);
$resultado_lat = $lat / 100;
list ($latitud_entero, $latitud_decimal) = explode('.', $resultado_lat);
$resultado_lat_minutos = $lat - ($latitud_entero * 100);
$resultado_lat_segundos = ($resultado_lat_minutos / 60);
$resultado_lat_final = $latitud_entero + $resultado_lat_segundos;
if ($dato5 == 'S'){
$resultado_lat_final = $resultado_lat_final * -1;
}
$resultado_lon = $lon / 100;
list ($longitud_entero, $longitud_decimal) = explode('.', $resultado_lon);
$resultado_lon_minutos = $lon - ($longitud_entero * 100);
$resultado_lon_segundos = ($resultado_lon_minutos / 60);
$resultado_lon_final = $longitud_entero + $resultado_lon_segundos;
if ($dato7 == 'W'){
$resultado_lon_final = $resultado_lon_final * -1;
}

PHP Function to get MP3 duration

Is there any PHP function that will give me the MP3 duration. I looked at ID 3 function but i don't see any thing there for duration and apart from this,id3 is some kind of tag,which will not be there in all MP3 so using this will not make any sense.
This should work for you, notice the getduration function: http://www.zedwood.com/article/127/php-calculate-duration-of-mp3
Install getid3, but if you only need duration, you can delete all but these modules:
module.audio.mp3.php
module.tag.id3v1.php
module.tag.apetag.php
module.tag.id3v2.php
Access the duration with code like this:
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($pathName);
$len= #$ThisFileInfo['playtime_string']; // playtime in minutes:seconds, formatted string
Get it at Sourceforge
I have passed so many time, but without getID3 (http://getid3.sourceforge.net/) to get duration of audio file not possible.
1) First download library of getID3 using below link:
https://github.com/JamesHeinrich/getID3/archive/master.zip
2) Try this below code:
<?php
include("getid3/getid3.php");
$filename = 'bcd4ecc6bf521da9b9a2d8b9616d1505.wav';
$getID3 = new getID3;
$file = $getID3->analyze($filename);
$playtime_seconds = $file['playtime_seconds'];
echo gmdate("H:i:s", $playtime_seconds);
?>
You can get the duration of an mp3 or many other audio/video files by using ffmpeg.
Install ffmpeg in your server.
Make sure that php shell_exec is not restricted in your php.
// Discriminate only the audio/video files you want
if(preg_match('/[^?#]+\.(?:wma|mp3|wav|mp4)/', strtolower($file))){
$filepath = /* your file path */;
// execute ffmpeg form linux shell and grab duration from output
$result = shell_exec("ffmpeg -i ".$filepath.' 2>&1 | grep -o \'Duration: [0-9:.]*\'');
$duration = str_replace('Duration: ', '', $result); // 00:05:03.25
//get the duration in seconds
$timeArr = preg_split('/:/', str_replace('s', '', $duration[0]));
$t = $this->_times[$file] = (($timeArr[3])? $timeArr[3]*1 + $timeArr[2] * 60 + $timeArr[1] * 60 * 60 : $timeArr[2] + $timeArr[1] * 60)*1000;
}
<?php
class MP3File
{
protected $filename;
public function __construct($filename)
{
$this->filename = $filename;
}
public static function formatTime($duration) //as hh:mm:ss
{
//return sprintf("%d:%02d", $duration/60, $duration%60);
$hours = floor($duration / 3600);
$minutes = floor( ($duration - ($hours * 3600)) / 60);
$seconds = $duration - ($hours * 3600) - ($minutes * 60);
return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
}
//Read first mp3 frame only... use for CBR constant bit rate MP3s
public function getDurationEstimate()
{
return $this->getDuration($use_cbr_estimate=true);
}
//Read entire file, frame by frame... ie: Variable Bit Rate (VBR)
public function getDuration($use_cbr_estimate=false)
{
$fd = fopen($this->filename, "rb");
$duration=0;
$block = fread($fd, 100);
$offset = $this->skipID3v2Tag($block);
fseek($fd, $offset, SEEK_SET);
while (!feof($fd))
{
$block = fread($fd, 10);
if (strlen($block)<10) { break; }
//looking for 1111 1111 111 (frame synchronization bits)
else if ($block[0]=="\xff" && (ord($block[1])&0xe0) )
{
$info = self::parseFrameHeader(substr($block, 0, 4));
if (empty($info['Framesize'])) { return $duration; } //some corrupt mp3 files
fseek($fd, $info['Framesize']-10, SEEK_CUR);
$duration += ( $info['Samples'] / $info['Sampling Rate'] );
}
else if (substr($block, 0, 3)=='TAG')
{
fseek($fd, 128-10, SEEK_CUR);//skip over id3v1 tag size
}
else
{
fseek($fd, -9, SEEK_CUR);
}
if ($use_cbr_estimate && !empty($info))
{
return $this->estimateDuration($info['Bitrate'],$offset);
}
}
return round($duration);
}
private function estimateDuration($bitrate,$offset)
{
$kbps = ($bitrate*1000)/8;
$datasize = filesize($this->filename) - $offset;
return round($datasize / $kbps);
}
private function skipID3v2Tag(&$block)
{
if (substr($block, 0,3)=="ID3")
{
$id3v2_major_version = ord($block[3]);
$id3v2_minor_version = ord($block[4]);
$id3v2_flags = ord($block[5]);
$flag_unsynchronisation = $id3v2_flags & 0x80 ? 1 : 0;
$flag_extended_header = $id3v2_flags & 0x40 ? 1 : 0;
$flag_experimental_ind = $id3v2_flags & 0x20 ? 1 : 0;
$flag_footer_present = $id3v2_flags & 0x10 ? 1 : 0;
$z0 = ord($block[6]);
$z1 = ord($block[7]);
$z2 = ord($block[8]);
$z3 = ord($block[9]);
if ( (($z0&0x80)==0) && (($z1&0x80)==0) && (($z2&0x80)==0) && (($z3&0x80)==0) )
{
$header_size = 10;
$tag_size = (($z0&0x7f) * 2097152) + (($z1&0x7f) * 16384) + (($z2&0x7f) * 128) + ($z3&0x7f);
$footer_size = $flag_footer_present ? 10 : 0;
return $header_size + $tag_size + $footer_size;//bytes to skip
}
}
return 0;
}
public static function parseFrameHeader($fourbytes)
{
static $versions = array(
0x0=>'2.5',0x1=>'x',0x2=>'2',0x3=>'1', // x=>'reserved'
);
static $layers = array(
0x0=>'x',0x1=>'3',0x2=>'2',0x3=>'1', // x=>'reserved'
);
static $bitrates = array(
'V1L1'=>array(0,32,64,96,128,160,192,224,256,288,320,352,384,416,448),
'V1L2'=>array(0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384),
'V1L3'=>array(0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320),
'V2L1'=>array(0,32,48,56, 64, 80, 96,112,128,144,160,176,192,224,256),
'V2L2'=>array(0, 8,16,24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160),
'V2L3'=>array(0, 8,16,24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160),
);
static $sample_rates = array(
'1' => array(44100,48000,32000),
'2' => array(22050,24000,16000),
'2.5' => array(11025,12000, 8000),
);
static $samples = array(
1 => array( 1 => 384, 2 =>1152, 3 =>1152, ), //MPEGv1, Layers 1,2,3
2 => array( 1 => 384, 2 =>1152, 3 => 576, ), //MPEGv2/2.5, Layers 1,2,3
);
//$b0=ord($fourbytes[0]);//will always be 0xff
$b1=ord($fourbytes[1]);
$b2=ord($fourbytes[2]);
$b3=ord($fourbytes[3]);
$version_bits = ($b1 & 0x18) >> 3;
$version = $versions[$version_bits];
$simple_version = ($version=='2.5' ? 2 : $version);
$layer_bits = ($b1 & 0x06) >> 1;
$layer = $layers[$layer_bits];
$protection_bit = ($b1 & 0x01);
$bitrate_key = sprintf('V%dL%d', $simple_version , $layer);
$bitrate_idx = ($b2 & 0xf0) >> 4;
$bitrate = isset($bitrates[$bitrate_key][$bitrate_idx]) ? $bitrates[$bitrate_key][$bitrate_idx] : 0;
$sample_rate_idx = ($b2 & 0x0c) >> 2;//0xc => b1100
$sample_rate = isset($sample_rates[$version][$sample_rate_idx]) ? $sample_rates[$version][$sample_rate_idx] : 0;
$padding_bit = ($b2 & 0x02) >> 1;
$private_bit = ($b2 & 0x01);
$channel_mode_bits = ($b3 & 0xc0) >> 6;
$mode_extension_bits = ($b3 & 0x30) >> 4;
$copyright_bit = ($b3 & 0x08) >> 3;
$original_bit = ($b3 & 0x04) >> 2;
$emphasis = ($b3 & 0x03);
$info = array();
$info['Version'] = $version;//MPEGVersion
$info['Layer'] = $layer;
//$info['Protection Bit'] = $protection_bit; //0=> protected by 2 byte CRC, 1=>not protected
$info['Bitrate'] = $bitrate;
$info['Sampling Rate'] = $sample_rate;
$info['Framesize'] = self::framesize($layer, $bitrate, $sample_rate, $padding_bit);
$info['Samples'] = $samples[$simple_version][$layer];
return $info;
}
private static function framesize($layer, $bitrate,$sample_rate,$padding_bit)
{
if ($layer==1)
return intval(((12 * $bitrate*1000 /$sample_rate) + $padding_bit) * 4);
else //layer 2, 3
return intval(((144 * $bitrate*1000)/$sample_rate) + $padding_bit);
}
}
?>
<?php
$mp3file = new MP3File("Chal_Halke.mp3");//http://www.npr.org/rss/podcast.php?id=510282
$duration1 = $mp3file->getDurationEstimate();//(faster) for CBR only
$duration2 = $mp3file->getDuration();//(slower) for VBR (or CBR)
echo "duration: $duration1 seconds"."\n";
?>
There is no native php function to do this.
Depending on your server environment, you may use a tool such as MP3Info.
$length = shell_exec('mp3info -p "%S" sample.mp3'); // total time in seconds
As earlier, I provided a solution for both mp3 and WAV files, Now this solution is specifically for the only WAV file with more precision but with longer evaluation time than the earlier solution.
function calculateWavDuration( $file ) {
$fp = fopen($file, 'r');
if (fread($fp, 4) == "RIFF") {
fseek($fp, 20);
$raw_header = fread($fp, 16);
$header = unpack('vtype/vchannels/Vsamplerate/Vbytespersec/valignment/vbits', $raw_header);
$pos = ftell($fp);
while (fread($fp, 4) != "data" && !feof($fp)) {
$pos++;
fseek($fp, $pos);
}
$raw_header = fread($fp, 4);
$data = unpack('Vdatasize', $raw_header);
$sec = $data[datasize] / $header[bytespersec];
$minutes = intval(($sec / 60) % 60);
$seconds = intval($sec % 60);
return str_pad($minutes, 2, "0", STR_PAD_LEFT) . ":" . str_pad($seconds, 2, "0", STR_PAD_LEFT);
}
}
$file = '1.wav'; //Enter File wav
calculateWavDuration($file);
The MP3 length is not stored anywhere (in the "plain" MP3 format), since MP3 is designed to be "split" into frames and those frames will remain playable.
http://mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm
If you have no ID tag on which to rely, what you would need to do (there are tools and PHP classes that do this) is to read the whole MP3 file and sum the durations of each frame.
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($pathName);
// playtime in minutes:seconds, formatted string
$len = #$ThisFileInfo['playtime_string'];
//don't get playtime_string, but get playtime_seconds
$len = #$ThisFileInfo['playtime_seconds']*1000; //*1000 as calculate millisecond
I hope this helps you.
Finally, I developed a solution with my own calculations. This solution works best for mp3 and WAV files formats. However minor precision variations are expected. The solution is in PHP. I take little bit clue from WAV
function calculateFileSize($file){
$ratio = 16000; //bytespersec
if (!$file) {
exit("Verify file name and it's path");
}
$file_size = filesize($file);
if (!$file_size)
exit("Verify file, something wrong with your file");
$duration = ($file_size / $ratio);
$minutes = floor($duration / 60);
$seconds = $duration - ($minutes * 60);
$seconds = round($seconds);
echo "$minutes:$seconds minutes";
}
$file = 'apple-classic.mp3'; //Enter File Name mp3/wav
calculateFileSize($file);
If you have FFMpeg installed, getting the duration is quite simple with FFProbe
$filepath = 'example.mp3';
$ffprobe = \FFMpeg\FFProbe::create();
$duration = $ffprobe->format($filepath)->get('duration');
echo gmdate('H:i:s', $duration);
FFMpeg is mentioned elsewhere, but here's a fuller explanation and example implementation.
Install ffmpeg for your system. E.g., on Ubuntu:
apt-get update && apt-get -y install ffmpeg
Install php-ffmpeg using Composer:
composer require php-ffmpeg/php-ffmpeg
Example utility class
<?php
namespace App\Utils;
use FFMpeg\FFProbe;
class Audio
{
public static function duration(string $path): float
{
$probe = FFProbe::create();
return $probe->format($path)->get('duration');
}
}
Where $path is the absolute path or URL to your audio file. To use:
$duration = \App\Utils\Audio::duration($path);
echo $duration; // 24.476750
Of course, you can just use it directly where you need it. The point of the utility class example is to show how you use it. You'll want to try/catch calling it in a production setting. If you aren't using composer, see #awavi's answer.

DateTime diff not working correctly in Wordpress page

All,
I have the following PHP code to determine how many years apart two dates are on my Wordpress page:
<?php
$date1 = new DateTime("2003-03-24");
$current_date = new DateTime(date("Y-m-d"));
$interval = $date1->diff($current_date);
echo $interval->y;
?>
I installed the Exec-PHP plugin for Wordpress to display this properly. However when I try and display my page I get the following error:
Fatal error: Call to undefined method DateTime::diff() in
/home/person/test.website.com/wp-content/plugins/exec-php/includes/runtime.php(42)
: eval()'d code on line 7
How can I get this to work properly? Thanks!
I remember this question a while back: How to calculate the difference between two dates using PHP?
With some small adjustments it looks like this:
function convert_number($number) {
$Gn = floor($number / 1000000); /* Millions (giga) */
$number -= $Gn * 1000000;
$kn = floor($number / 1000); /* Thousands (kilo) */
$number -= $kn * 1000;
$Hn = floor($number / 100); /* Hundreds (hecto) */
$number -= $Hn * 100;
$Dn = floor($number / 10); /* Tens (deca) */
$n = $number % 10; /* Ones */
$res = "";
if ($Gn)
$res .= convert_number($Gn) . " Million";
if ($kn) {
$res .= (empty($res) ? "" : " ") .
convert_number($kn) . " Thousand";
}
if ($Hn) {
$res .= (empty($res) ? "" : " ") .
convert_number($Hn) . " Hundred";
}
$ones = array("", "One", "Two", "Three", "Four", "Five", "Six","Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen","Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen","Nineteen");
$tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty","Seventy", "Eigthy", "Ninety");
if ($Dn || $n) {
if (!empty($res))
$res .= " and ";
if ($Dn < 2)
$res .= $ones[$Dn * 10 + $n];
else {
$res .= $tens[$Dn];
if ($n)
$res .= "-" . $ones[$n];
}
}
if (empty($res))
$res = "zero";
return $res;
}
function yearsFromNow ($date) {
return convert_number(floor(abs(strtotime($date) - strtotime(date("Y-m-d"))) / (365*60*60*24)));
}
echo yearsFromNow("2007-03-24");
echo yearsFromNow("2009-06-26");
Output:
4
2
Number to letters function modified from this site: http://www.phpro.org/examples/Convert-Numbers-to-Words.html
As said in the manual, DateTime::Diff (and all the DateInterval functions) is available in PHP >= 5.3.0 only.
You would need to install that version, or find a workaround that uses another set of functions. Here is an example for how to do this using the old timestamp-based date functions.

Categories