Menu

#3 DateTime() problem...

v1.0 (example)
open
nobody
None
5
2013-10-23
2013-10-16
No

Although you had the code fix to the numeric pdt to a date, it was wrong. The original said:

    $pdt = new DateTime();
    $pdt->setTimestamp($pdt);

As you can see, you use $pdt as the input number after assigning a DateTime object to it. I would suggest something more like this:

# workaround for import
if(is_numeric($pdt)){
    # >= php 5.3
    $time = $pdt;
    $pdt = new DateTime();
    $pdt->setTimestamp($time);
    #$f = setDateFormat(null,1);
    #$time = date($f,$pdt);
    #$pdt = new DateTime($time);
}

Also, I have PHP 5.4.9 and the other code did not work completely preventing the creation of new fields in the database. I'm thinking that you could enhance the code by adding a test of the PHP version and select one or the other of the code based on that.

Discussion

  • Axel Westhagen

    Axel Westhagen - 2013-10-17

    Yes, I think php <= 5.3 is not longer needed for this ..
    I changed it in svn

     
  • Alexis Wilke

    Alexis Wilke - 2013-10-17

    Cool! I see that you use a new name for the parameter: $stamp. Only the commented out code still uses $pdt as input of date(). You may want to change that, just in case someone needs it in their version.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    #!/usr/bin/php
    # workaround for import
    if(is_numeric($stamp)){
        # >= php 5.3
        #$pv = explode('.',phpversion());
        #if($pv[0] >= 5 && $pv[1] >= 3){
            $pdt = new DateTime();
            $pdt->setTimestamp($stamp);
        #}else{
            #$f = setDateFormat(null,1);
            #$time = date($f,$pdt); <-- use $stamp here too!
            #$pdt = new DateTime($time);
        #}
    }else{
        $pdt = $stamp;
    }
    
     
  • Axel Westhagen

    Axel Westhagen - 2013-10-23

    Yes thanks for improve
    I change it

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.