date format in smarty (months without leading zero) - smarty

right now, I have a date that is displayed like this:
19\06\2013
what I want is this :
19\6\2013
my current smarty code is :
{$variable|date_format:"%e\%m\%Y"}
I tried using %n for the month (I assumed that anything that works on php will work in smarty) but it did not give me any result.
How can I display the month without a leading zero in Smarty? is there any workaround solutions? I do not want to edit and format the date in my php file.

Today I have the same problem and this works for me…
Windows server
This solution seems to work only on windows based servers (localhost in my case).
{$variable|date_format:"%d\%#m\%Y"}
Just put hash # before letter 'm'.
I'm using Smarty v3
Linux server:
I moved my project to remote server (probably linux) and hash sign stop to work. I found another solution, just put hyphen - before letter 'm':
{$variable|date_format:"%d\%-m\%Y"}
And this works on linux, but not on windows.
Cross-platform PHP-based solution:
But because smarty is a PHP plugin we can use all of PHP functions. So this is another solution I found, maybe not so elegant but it seems to work everywhere.
{assign var="dateTime" value=$variable|strtotime}
{*
or shorter:
{$dateTime=$variable|strtotime}
*}
<p>{"j/n/Y"|date:$dateTime}</p>
Note:
The above solutions work for formatting day with out leading zero also:
{$variable|date_format:"%-d vs %d vs %#d"}

{$variable|date_format:"j. n. Y":"":"any string - not either strftime or auto"}
then you can write date format as in php function date().
smarty_modifier_date_format($string, $format=null, $default_date='', $formatter='auto')

Related

Kamailio 4.4 seturi Only Accepts Explicit Strings?

I've been working at implementing a simple serial forking described in the TM module's documentation (the Q values are stored as a priority weight in a mysql table) where my proxy is querying a database to determine to what domain to forward to.
I've verified through extensive use of xlog that a variable I'm using to build the new URI to use with seturi is getting everything correctly. I use an append_branch call in a subsequent while loop iterating over my sql query results, which doesn't have any problems with taking a very similarly formatted parameter. However, when I go to restart Kamailio it simply gripes at me that a string is expected. The line it corresponds to from console is just the seturi call. I've tried casting as a string, but that doesn't seem to be part of 4.4 (or my syntax is wrong).
I've thought about building the URI strings and storing into avp, but I suspect I'd have the same problem.
For reference, this is what I'm doing:
$var(basedest) = "sip:" + $var(number) + "#" + $(dbr(destination=>[0,0]))+ ":" + $var(port);
seturi($var(basedest));
And what it's outputting when trying to load the config:
<core> [cfg.y:3368]: yyerror_at(): parse error in config file //etc/kamailio/kamailio.cfg, line 570, column 9-22: syntax error
<core> [cfg.y:3371]: yyerror_at(): parse error in config file //etc/kamailio/kamailio.cfg, line 570, column 23: bad argument, string expected
Naturally, when I put $var(basedest) in double quotes, it's literally interpreted as a string. Single quotes behave similarly. Is there something I can do to work around this? When I feed it an explicit hardcoded string, it's happy as a can be and the routing works fine. When I try to do something very simple like the above, it gets upset. If possible, I'd like to avoid updating as I initially grabbed Kamailio from the yum repo.
Thanks in advance - this has been bugging me a good while.
Apparently, not a new problem. I ended up finding out what I can do to work around it.
For reference, seturi and $ru pseudo variable refer to the same thing. So basically you'd just do:
$var(mynewru) = "sip:user#domain:5060";
$ru = $var(mynewru);
This would achieve the same thing I was originally attempting to do before based on the TM module's documentation. For serial forking, issuing some number of append_branch calls is fine.

Bestw.d format syntax in SAS

I am converting a character variable to a numeric variable. I am using a bestw.d format. I also tried just best. as the format in the input statement and this worked fine. I cant find any mention of just using best. instead of bestw. in SAS help, though I know from SAS help that the d can be omitted. I have been playing around with using just the best.and I am wondering if there is a default w assigned when just using best..
All formats have a default w. It is not generally good practice to use best. (or <format>.) in most cases, as you should know and plan for the specific width needed, but it always exists.
Also, informat and format have different defaults in many cases where there are identically named informat and format.
In the case of bestw., the default length is 12. See this documentation page for details.
I always find it's worth using a worked example, this shows the different outcomes when using lengths on the BEST. format:
data _NULL_;
a=1031564321300.302;
put '==================================';
put 'Different "BEST" formats';
put '==================================';
put 'BEST8. - ' a best8.;
put 'BEST12. - ' a best12.;
put 'BEST13. - ' a best13.;
put '==================================';
put 'BEST. - ' a best.;
put '==================================';
run;
You can run this in your environment and check the outcome. On my machine it looks like this:
==================================
Different "BEST" formats
==================================
BEST8. - 1.032E12
BEST12. - 1.0315643E12
BEST13. - 1031564321300
==================================
BEST. - 1.0315643E12
==================================
i.e. It looks like BEST12. is the matching format when no width is specified.

Change Magento decimal field format

I need to change Magento's default decimal format. I mean, when I save '1' to a decimal field, it becomes '10000.0000' with this '.0000' in the end.
I need to change it to another format, which uses ',' instead of '.' to separate decimal (and currency) numbers.
This is the Brazilian standard and it's not being used even after changing the store language. This change should be reflected mainly in the admin side.
Thanks a lot!
==Edited==
I haven't solved the problem yet. I'm using PT-BR (Brazilian Portuguese) as default language and it still using the wrong decimal character.
It seems Magento have some not-localized price formatting (I mean, hard-coded) in a few points of code. For example: magento\js\prototype\validation.js at line 426 have:
|| (!isNaN(parseNumber(v)) && /^\s*-?\d*(\,\d*)?\s*$/.test(v));
but instead it needs to be
|| (!isNaN(parseNumber(v)) && /^\s*-?\d*(\,\d*)?\s*$/.test(v));
to fit into PT-BR format (or other locales to).
Am I right? Does anybody could fix this issue?
if you want to check in admin area for this change
you go to in admin left bottom drop down
and select
Português (Portugal) / português (Portugal)
it will show you currency as you want. Also if you doesn't install you package go to
http://www.magentocommerce.com/translations/list/19
download your package and add it to your
locale folder and select from configuration for front end also
hope this will sure help you.
I've applied the following change to the file magento\js\prototype\validation.js (line 426):
|| (!isNaN(parseNumber(v)) && /^\s*-?\d*(\,\d*)?\s*$/.test(v));
and also, changed the file lib/Varien/Data/Form/Element/Abstract.php by adding the first if statement:
public function getEscapedValue($index=null)
{
$value = $this->getValue($index);
if(is_numeric($value)){
$value= number_format($value, 3, ",", ".");
}
...
this changes have solved the problem so far. Do you see any side-effect?
Comments are welcome! Thanks!
Newer versions of Magento are based on Zend Framework currency locale format so the best way to do this is to change the language.xml from the Zend directory, more information is on this great article.

How to check date in freemarker?

I have date variable in freemarker. i want to check that date is today or yesterday. If that date is today then need to display Today otherwise display Yesterday. Please can any one help me?
If you are sure that these are only possibilities (today and yesterday), then you could define a function like:
<#function isToday(aDate)>
<#return .now?date?iso_local == aDate?date?iso_local>
</#function>
and then you can use it for example as
${isToday(theDate)?string("today", "yesterday")}
Note that you will need FreeMarker 2.3.17 or later for that function to work. Also be careful with the Server time-zone, as that's what it uses in this example (unless you set that in the FreeMarker configuration manually... or with #setting in the templates).
${houradd(date, 1)?string("yyyy-MM-dd HH:mm:ss")}
${houradd(date, -1)?string("yyyy-MM-dd HH:mm:ss")}

Smarty "capitalize" modifier... always capitalizes "L"? ... and "P"?

Quite simply: I'm using Smarty and the |capitalize modifier. It works fine, but when I pass any word with l in it, it capitalizes it, even if it's not at the beginning of the word.
What why?
EDIT: Same happens with p.
Test:
{"abcdefghijklmnopqrstuvwxyz"|capitalize}
{"aaal aala alaa laaa"|capitalize}
{"aaap aapa apaa paaa"|capitalize}
Output:
AbcdefghijkLmnoPqrstuvwxyz
AaaL AaLa ALaa Laaa
AaaP AaPa APaa Paaa
You could also use PHP's ucfirst function
{"aaal aala alaa laaa"|#ucfirst}
This will result in
Aaal aala alaa laaa
Smarty primarily relies on ucfirst() which is affected by the current locale set in PHP. I have been unable to find information on exactly how this affects the capitalization functions (ucfirst, strtolower, strtoupper, etc), but you can try setting your locale to en_US.UTF-8 (what works on my server) and see how that affects the output.
view locale:
var_dump(setlocale(LC_CTYPE, null));
change locale:
setlocale(LC_CTYPE, "en_US.UTF-8");
Update
Some research leads to a few archives where a customer modifier is written to either pick the local for the modifier or a custom function to set the locale from the template file.
Source 1
Source 2
I haven't been able to reproduce this. Could it be the font you are using (some tail the l)? Do you have code examples?
With Smarty v2
{assign value="let go" var="go"}
{$go|capitalize}
<br/>
{assign value="allow me" var="me"}
{$me|capitalize}
Outputs
Let Go
<br/>
Allow me

Resources