Solved

convert to time (ebay time left)

Posted on 2011-03-01
10
941 Views
Last Modified: 2012-06-27
P2DT16H2M40S
P20DT6H2M4S

P-> I dont know
DT->Days
H->Hours
M->Minutes
S->Seconds
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35007585
http://www.mrkent.com/ebaytools/index.php
Look at the source code, it is written in javascript, if you need to convert it in php just say so.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35007629
You could use my suggestion from your last question, just change the words accordingly within the regex pattern.
0
 
LVL 5

Expert Comment

by:Kendor
ID: 35007678
exactly as in the question before... use regex and get the things out that you are looking for...
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:rgb192
ID: 35007685
I cant find the source code on that page
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35007780
I guess I'd have to go with kaufmed's suggestion - use regex to convert.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 35007797
Sure wish we could find a definition of what that field actually contains.  This seems intuitively correct.
<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);
date_default_timezone_set('America/New_York');


// WHAT DOES THIS STRING MEAN?
$str = 'P2DT16H2M40S';


// GUESSING IT MEANS THIS:
// P = Pending
// 2D = Two Days
// T = Time
// 16H = Sixteen hours
// 2M = Two minutes
// 40S = Forty seconds


// TESTED HERE: http://www.mrkent.com/ebaytools/index.php
// RESULT DID NOT MAKE SENSE - IT WAS EXACTLY 24 HOURS IN THE FUTURE
// Your Ebay deadline of (P2DT16H2M40S):
// Wednesday, 03/02/2011 - 9:41 AM EST . . . !


// EXPAND THE STRING INTO SOMETHING SENSIBLE
$new = $str;
$new = str_replace('S', 'seconds ', $new);
$new = str_replace('M', 'minutes ', $new);
$new = str_replace('H', 'hours ',   $new);
$new = str_replace('T', ' ',        $new);
$new = str_replace('D', 'days',     $new);
$new = str_replace('P', 'now + ',   $new);

// PRODUCE A HUMAN-READABLE DATE
$dat = date('r', strtotime($new));

// CONVERT TO SECONDS
$sec = strtotime($new) - strtotime('now');

// SHOW THE WORK PRODUCTS
echo "<br/>$str";
echo "<br/>$new";
echo "<br/>$sec";
echo "<br/>$dat";

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35007948
Blast!  Overruled again    ; )
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 35008681
I think we guessed right.  See "duration" on this page:
http://developer.ebay.com/devzone/merchandising/docs/callref/types/simpleTypes.html

Here is a slightly more comprehensive version, packaged as a function.  It does not cover the PnW or the Pdate formats, nor does it account for goofy things like fractional periods.
<?php // RAY_duration_strtotime.php
error_reporting(E_ALL);
date_default_timezone_set('America/New_York');


// WHAT DOES THIS STRING MEAN?
$str = 'P1Y3M2DT16H2M40S';

// IT IS THE ISO8601 FORMAT FOR A DURATION.
// SEE http://en.wikipedia.org/wiki/ISO_8601

// IT MEANS THIS:
// P   = Pending (INDICATOR OF ISO8601 DURATION)
// 1Y  = 1 Year
// 2M  = 2 Months
// 2D  = Two Days
// T   = Time Separator (M is ambiguous)
// 16H = Sixteen hours
// 2M  = Two minutes
// 40S = Forty seconds



// STRTOTIME CANNOT HANDLE ISO-8601 DURATIONS
$dur = strtotime($str);
var_dump($dur);
echo "<br/>";

// GET THE DURATION IN SECONDS FOR USE IN ARITHMETIC
$dur = duration_strtotime($str);
echo "<br/>" . number_format($dur) . ' SECONDS';

// USE THE DURATION IN ARITHMETIC
echo "<br/>" . date('r', strtotime("NOW + $dur SECONDS"));



// A FUNCTION TO MAKE A DURATION STRING INTO A NUMBER OF SECONDS
function duration_strtotime($str, $sho=FALSE)
{
    // REMOVE THE AMBIGUITY OF MONTH AND MINUTE -- MAKE MONTH = X
    $arr = explode('T', $str);
    $arr[0] = str_replace('M', 'X', $arr[0]);
    $new = implode('T', $arr);

    // EXPAND THE STRING INTO SOMETHING SENSIBLE
    $new = str_replace('S', 'seconds ', $new);
    $new = str_replace('M', 'minutes ', $new);
    $new = str_replace('H', 'hours ',   $new);
    $new = str_replace('T', ' ',        $new);
    $new = str_replace('D', 'days',     $new);
    $new = str_replace('X', 'months ',  $new);
    $new = str_replace('Y', 'years ',   $new);
    $new = str_replace('P', NULL,       $new);

    if ($sho) var_dump($new);

    // RETURN THE NUMBER OF SECONDS IN THE DURATION
    return strtotime($new) - strtotime('NOW');
}

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 35010475
Best answer, thank you
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 35010750
Thanks for the points.  I had never seen the "duration" format before.  Very interesting question, ~Ray
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question