Categories > TinyButStrong general >

BUG? Time formatted incorrectly

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Peter
Date: 2015-10-20
Time: 10:21

BUG? Time formatted incorrectly

It seems the form date parsing is incorrect. What can i do to correct this?

TBS:        [row.Zeit] => [row.Zeit;frm='dd.mm.yyyy']

TEST: 1424905200 => 26.02.2015  RIGHT
TEST: 1420412400 => 20.10.2400  WRONG
TEST: 1416524400 => 20.10.4400 WRONG
By: Peter
Date: 2015-10-20
Time: 10:53

Re: BUG? Time formatted incorrectly

i got it working, but don't know if its a safe fix:


diff --git a/inc/tbs_class_php5.php b/inc/tbs_class_php5.php
index 7ea5936..c4d91d5 100644
--- a/inc/tbs_class_php5.php
+++ b/inc/tbs_class_php5.php
@@ -3430,7 +3430,7 @@ function meth_Misc_Format(&$Value,&$PrmLst) {
         if (is_object($Value)) {
             $Value = $this->meth_Misc_ToStr($Value);
         }
-        if (is_string($Value)) {
+        if (is_string($Value) && !is_numeric($Value)) {
             if ($Value==='') return '';
             $x = strtotime($Value);
             if (($x===-1) || ($x===false)) {

By: Sheepy
Date: 2015-10-22
Time: 07:29

Re: BUG? Time formatted incorrectly

Cannot reproduce:

$tbs = new clsTinyButStrong();
$tbs->Source = "[row.Zeit1;frm='dd.mm.yyyy']<br>[row.Zeit2;frm='dd.mm.yyyy']<br>[row.Zeit3;frm='dd.mm.yyyy']";
$tbs->MergeField( 'row', [ 'Zeit1' => 1424905200, 'Zeit2' => 1420412400, 'Zeit3' => 1416524400 ] );
$tbs->Show();

Result:

26.02.2015
05.01.2015
21.11.2014
By: Peter
Date: 2015-10-22
Time: 09:51

Re: BUG? Time formatted incorrectly

Its on only when the timestamp is a string

$tbs->MergeField( 'row', [ 'Zeit1' => '1424905200', 'Zeit2' => '1420412400', 'Zeit3' => '1416524400' ] );

By: Sheepy
Date: 2015-10-23
Time: 08:39

Re: BUG? Time formatted incorrectly

Ah, I see. A better fix may be to move up the negated is_numeric check at line 3442?
By: Peter
Date: 2015-10-26
Time: 08:27

Re: BUG? Time formatted incorrectly

I don't know. Better would be an check if the string/int is already an timestamp. It could be, that sometime writes this as date 20141121 => 21.11.2014

http://stackoverflow.com/questions/2524680/check-whether-the-string-is-a-unix-timestamp
Something like this:
function isTimestamp($timestamp) {
    if(ctype_digit($timestamp) && strtotime(date('Y-m-d H:i:s',$timestamp)) === (int)$timestamp) {
        return true;
    } else {
        return false;
}
By: Skrol29
Date: 2015-10-28
Time: 11:33

Re: BUG? Time formatted incorrectly

The problem is a value such as 20141121 can be a formated date as well as a timestamp.
So TBS looks at the type of the value to make a choice.
By: Peter
Date: 2015-11-03
Time: 09:39

Re: BUG? Time formatted incorrectly

How was it solved before? It seem one of the last version introduced this, because i upgraded the lib and dates got wrong.