convert time in an object oriented format

(minutes and hours in () )
1 has no 'S' (minuteS, hrS, dayS, weekS)


(1 min ago)
(17 mins ago)
(1 hr ago)

(12 hrs ago)
1 day ago
2 days ago
1 week ago

Could you please create an object oriented class and method where I could create an object that converts this time length to current time in mysql format
Y-m-d H:i:s

one value at a time
LVL 1
rgb192Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rgb192Author Commented:
I am currently not involved in a school.

In my free time I watch videos from
lynda.com paid (but not an .edu school)
youtube (free)

Because of experts-exchange and your help, AngelIII, I can now ask questions that look like homework assignments.
0
Ray PaseurCommented:
Check out this PHP built-in:
http://php.net/manual/en/class.datetime.php

<?php // RAY_temp_rgb192.php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);
echo '<pre>';


// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28236754.html


// TEST DATA
$lapse = array
( '(1 min ago)'
, '(17 mins ago)'
, '(1 hr ago)'
, '(12 hrs ago)'
, '1 day ago'
, '2 days ago'
, '1 week ago'
, 'Bozo'
)
;

Class MyDateTime extends Datetime
{
    // OVERRIDE THE CONSTRUCTOR METHOD TO TAILOR OUR INPUT STRINGS
    public function __construct($str)
    {
        // SAVE THE INITIAL STRING
        $this->s = $str;

        // REMOVE UNWANTED CHARACTERS
        $str = str_replace('(', NULL, $str);
        $str = str_replace(')', NULL, $str);

        // TRANSLATE TO 'HOUR'
        $str = str_replace('hr', 'hour', $str);

        // CALL THE PARENT CONSTRUCTOR
        try
        {
            $this->e = NULL;
            parent::__construct($str);
        }

        // CATCH THE EXCEPTION MESSAGE
        catch (Exception $e)
        {
            $this->e = $e->getMessage();

            // OPTIONAL - SHOW MESSAGE?
            // echo $this->e;
        }
    }

    // OVERRIDE THE FORMAT METHOD TO MAKE A MORE MEANINGFUL ERROR MESSAGE
    public function format($pattern)
    {
        if ($this->e) return $this->s . ': ' . $this->e;
        return parent::format($pattern);
    }
}


// MAN PAGE: http://php.net/manual/en/class.datetime.php
foreach ($lapse as $str)
{
    echo PHP_EOL . "$str => ";
    $dat = new MyDateTime($str);
    echo $dat->format('Y-m-d H:i:s');
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgb192Author Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.