developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 12 years ago

Closed 11 years ago

#654 closed enhancement (fixed)

jTPL - date_format modifier doesn't accept TS

Reported by: CreatixEA Owned by: foxmask
Priority: low Milestone: Jelix 1.2 beta
Component: jelix:plugins Version: 1.0.5
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:

Description

The modifier date_format doesn't accept timestamps :

function jtpl_modifier_common_date_format( $string, $format="%b %e, %Y",
                                    $default_date=null) {

    if (substr(PHP_OS,0,3) == 'WIN') {
        $_win_from = array ('%e',  '%T',	   '%D');
        $_win_to   = array ('%#d', '%H:%M:%S', '%m/%d/%y');
        $format	= str_replace($_win_from, $_win_to, $format);
    }

    if($string != '') {

        return strftime($format, strtotime($string));

    } elseif (isset($default_date) && $default_date != '') {

        return strftime($format, strtotime($default_date));

    } else {

        return '';
    }
}

The string is parsed using strtotime, timestamps are long... then strtotime(ALongNumber) returns 01/01/1970 ...

Attachments (1)

ticket_654.patch (591 bytes) - added by foxmask 11 years ago.
patch pour le modifier date_format

Download all attachments as: .zip

Change History (8)

comment:1 Changed 12 years ago by laurentj

  • Milestone set to Jelix 1.0.7

comment:2 Changed 12 years ago by laurentj

Could you explain what happen precisely ? I don't understand your problem. Have you got an example which doesn't work ?

comment:3 Changed 12 years ago by laurentj

  • Milestone Jelix 1.0.8 deleted

comment:4 Changed 11 years ago by laurentj

  • Milestone set to Jelix 1.1.5

comment:5 Changed 11 years ago by foxmask

  • Owner set to foxmask
  • Status changed from new to assigned

le probleme se produit quand on fait ceci :

toto est vide donc $now va etre utilise à la place mais $now est un timestamp et le modifier ne peut pas gerer celui ci avec strtotime :

{assign $toto=''}
{assign $now = time()}
{$toto|date_format:"%b %e, %Y":$now}

un patch suit ;)

Changed 11 years ago by foxmask

patch pour le modifier date_format

comment:6 Changed 11 years ago by foxmask

  • review set to review?

comment:7 Changed 11 years ago by laurentj

  • Milestone changed from Jelix 1.1.5 to Jelix 1.2
  • Resolution set to fixed
  • review changed from review? to review+
  • Status changed from assigned to closed
  • Type changed from bug to enhancement

ok, but I also improved a bit the code of this plugin. http://hg.jelix.org/jelix/jelix-trunk/rev/881e94d5d8a8

Note that, for the current time, you can pass "now" to strtotime, so, in the 1.1.x branch, you can do

{$toto|date_format:"%b %e, %Y":"now"}
Note: See TracTickets for help on using tickets.