Solved

convert to time (ebay time left)

Posted on 2011-03-01
10
845 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
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
exactly as in the question before... use regex and get the things out that you are looking for...
0
 

Author Comment

by:rgb192
Comment Utility
I cant find the source code on that page
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
I guess I'd have to go with kaufmed's suggestion - use regex to convert.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Blast!  Overruled again    ; )
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
Best answer, thank you
0
 
LVL 108

Expert Comment

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now