Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Variable per day

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
sebsimappus
Smarty n00b


Joined: 04 Feb 2021
Posts: 2

PostPosted: Thu Feb 04, 2021 11:49 am    Post subject: Variable per day Reply with quote

Hello,

I am coming to you following a need to set up a date, we need to put the current week in prestashop on a TPL file, for example: today we are 04/02/2021 and we need 'to have :

from 02/01/2021 to 02/07/2021

Impossible to get the result, the objective and to have from next Monday:

from 02/08/2021 to 02/14/2021

Thank you in advance for your advice and for your help.

cordially
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Feb 04, 2021 2:34 pm    Post subject: Reply with quote

If all you need is to have "+7 days" date, then write a date modifier using intl DateFormatter.
Smth. like
Code:
$tz = date_default_timezone_get() ?: "UTC";
$locale = "ru_RU.UTF-8";
$df = \IntlDateFormatter::create($locale, \IntlDateFormatter::FULL, \IntlDateFormatter::SHORT, $tz);
$cs = ini_get('output_encoding') ?: ini_get('iconv.output_encoding') ?: ini_get('default_charset') ?: 'ISO-8859-1';
$mf = function($date, $dateFormat = null, $timeFormat = null, $timeZone = null)
use($df, $cs, $tz, $locale)
{
  if(isset($dateFormat) || isset($timeFormat) || isset($timeZone))
  {
    $f = \IntlDateFormatter::create(
      $locale,
      isset($dateFormat) ? $dateFormat : $df->getDateType(),
      isset($timeFormat) ? $timeFormat : $df->getTimeType(),
      isset($timeZone) ? $timeZone : $df->getTimeZone()
    )->format($date);
  }
  else
  {
    $f = $df->format($date);
  }

  return iconv('UTF-8', "$cs//IGNORE", $f);;
};

$tpl->registerPlugin('modifier', 'date', $mf);
unset($df, $mf);


then

Code:
{"today +7 days"|date}
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Fri Feb 12, 2021 8:32 pm    Post subject: Reply with quote

Quote:
today we are 04/02/2021
we need 'to have :
from 02/01/2021 to 02/07/2021

to have from next Monday:
from 02/08/2021 to 02/14/2021

You have mixed your data formats.

Is 04/02/2021 April 2, or 4 Feb?
Is 02/01/2021 Feb 1, or 2 Jan?
Etc.

Try:
Code:
{assign 'last_monday' 'd-m-Y'|date:strtotime("last monday")}
From: {$last_monday}
To: {'d-m-Y'|date:strtotime("$last_monday +6 days")}
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP