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

date_format broken!

 
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 -> Bugs
View previous topic :: View next topic  
Author Message
luke
Smarty n00b


Joined: 04 May 2003
Posts: 4

PostPosted: Mon May 05, 2003 5:25 am    Post subject: date_format broken! Reply with quote

i have v2.5.0, and date_format is skipping the day.

all my dates (coming from mysql date type column ie 2003-05-01) are showing up without the day! it is the same whether i use the default formatting or put %e anywhere in the formatting string. is anybody else having this problem? there is nothing wrong with my dates - if i omit the "|date_format", they come out just like 2003-05-01.
Back to top
View user's profile Send private message
Wom.bat
Smarty Pro


Joined: 24 Apr 2003
Posts: 107
Location: Munich, Germany

PostPosted: Mon May 05, 2003 6:18 am    Post subject: Reply with quote

date_format modifier uses the php strftime() function, which expects a unix timestamp. modify your sql query from
SELECT ..., date FROM ...
to
SELECT ..., UNIX_TIMESTAMP(date) FROM ...
so that mysql returns a unix timestamp
that should help Smile
if you need dates before 1970, you may need to write your own modifier and use strtotime()
Back to top
View user's profile Send private message
PaK
Smarty n00b


Joined: 05 May 2003
Posts: 4
Location: Poland, Bialystok

PostPosted: Mon May 05, 2003 2:46 pm    Post subject: Reply with quote

Hello everybody.
I have one quoestion. Why smarty_make_timestamp does not allow to use unix timestamp format, at start of smt function we have these:
$time = strtotime($string);
So if we got
$string = 1051027916 strtotime return -1, and $time will be
$time = (int) $string;
but if we have thise date:
1970.01.03 11:22:13 -> unix_timestamp = 210133 strtotime() return to us 1612220400, but thise is not true right ? I don't know for what date in
unix_timestamp smarty_make_timsetamp (...) return real unix_timestamp or not real, but for this example this is a not valid date. Thise is correctly work of function ?
_________________
It is good day to die() ?
Back to top
View user's profile Send private message
luke
Smarty n00b


Joined: 04 May 2003
Posts: 4

PostPosted: Tue May 06, 2003 4:51 am    Post subject: Reply with quote

thanks Wom, that's a workable workaround

so instead i will report a bug in the documentation, because it says it will accept either
Back to top
View user's profile Send private message
PaK
Smarty n00b


Joined: 05 May 2003
Posts: 4
Location: Poland, Bialystok

PostPosted: Tue May 06, 2003 11:49 am    Post subject: Reply with quote

But... anyone can help me ? Smile
_________________
It is good day to die() ?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue May 06, 2003 1:58 pm    Post subject: Reply with quote

It looks like strtotime() incorrectly parses a date in the format of:

1970.01.03 11:22:13

These, however, work fine:

1970/01/03 11:22:13
1970-01-03 11:22:13
Back to top
View user's profile Send private message Visit poster's website
PaK
Smarty n00b


Joined: 05 May 2003
Posts: 4
Location: Poland, Bialystok

PostPosted: Tue May 06, 2003 11:49 pm    Post subject: Reply with quote

True, but what about unix_timestamp format, smarty_make_timestamp try to convert unix_timestamp to.. unix_timestamp ?!?! I think smarty_make_timestamp should not convert to unix_timestamp when script give argument as unix_timestamp format in to the function, bacous sometimes it returns not real value.
_________________
It is good day to die() ?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed May 07, 2003 12:14 am    Post subject: Reply with quote

Can you show an example? date_format should take a timestamp just fine.

example:

{$smarty.now|date_format}

Monte
Back to top
View user's profile Send private message Visit poster's website
PaK
Smarty n00b


Joined: 05 May 2003
Posts: 4
Location: Poland, Bialystok

PostPosted: Wed May 07, 2003 8:15 am    Post subject: Reply with quote

Code:
   +--------------------------------------------------------------------------+
   | unix_timestamp | date           | smarty_make_timestamp | date_format    |
   |----------------+----------------+-----------------------+----------------|
   | 210133         | 1970/01/03     | 1612220400            | 2021/02/02     |
   |                | 11:22:13       |                       | 00:00:00       |
   |----------------+----------------+-----------------------+----------------|
   | 213456         | 1970/01/03     | 1700866800            | 2023/11/25     |
   |                | 12:17:36       |                       | 00:00:00       |
   +--------------------------------------------------------------------------+

_________________
It is good day to die() ?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed May 07, 2003 2:04 pm    Post subject: Reply with quote

I see what happens. The timestamp 210133 is shorter than your average timestamp, and there is an ambiguity. strtotime() thinks you want to display 21-01-33, which is January 33rd, 2021... which resolves to February 2nd 2021.

But really, what if you passed this to date_format:

990331

Is that March 31, 1999, or a timestamp?

Basically, make_timestamp doesn't work reliably with short timestamps (probably somewhere around 6 chars or less) because of this ambiguity.

Monte
Back to top
View user's profile Send private message Visit poster's website
dthought
Smarty Regular


Joined: 21 Apr 2003
Posts: 55
Location: Melbourne, Australia

PostPosted: Thu May 08, 2003 9:25 am    Post subject: Okay then... Reply with quote

Okay then, figure this one out. I have some text displayed thusly:
{$thread[curItem].date_add|date_format:"%Y.%m.%d %I:%M %p"}

Every once in a while, say every six or eight reloads of a single page (that has not changed!), the %p fails to work. It just prints nothing, instead of printing AM or PM.

I'll try to debug it if I can, to find out what's going on...

Out of interest, I am passing the date as, for example,
"2003-05-06 23:45:11"
Server is running Redhat linux 7.2, and PHP4.2.2

Edit: It would appear there's a problem with strftime() itself - see here:
http://beta.dthought.net/strftime.php
(source): http://beta.dthought.net/strftime.phps

Refresh the page a few times, it appears and disappears sporadically. I'll have to investigate further again, as it's not a Smarty issue Smile
Back to top
View user's profile Send private message Visit poster's website
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 -> Bugs 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