Solved

convert to time (ebay time left)

Posted on 2011-03-01
10
864 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

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 108

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

914 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now