We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15871
    • 105 Posts
    I am using the following Ditto Call using the "Sort by Date TV" instructions in the Ditto documentaion.

    <P>Showing <strong>[+news_start+]</strong> - <strong>[+news_stop+]</strong> of <strong>[+news_total+]</strong> Articles | Page <strong>[+news_currentPage+]</strong> of <strong>[+news_totalPages+]</strong></p>
    <ul>
    [[Ditto? &id=`news` &paginate=`1` &tpl=`tpl.news` &sortBy=`myDate` &dateSource=`myDate` &dateFormat=`%A, %b %e, %Y` &sortDir=`ASC` &display=`20`]]
    </ul>
    <div id="ditto_pages"> [+news_previous+] [+news_pages+] [+news_next+] </div>
    


    However as soon as I put the [+date+] placeholder in the chunk,
    <h3>[+date+]</h3>
    <h4><a href="[~[+id+]~]">[+pagetitle+]</a></h4>
    <p>[+introtext+]</p>
    


    It throws this error:

    PHP error debug
      Error: 	strftime() expects parameter 2 to be long, array given	 
      Error type/ Nr.: 	Warning - 2	 
      File: 	/var/www/vhosts/cscus.net/httpdocs/assets/snippets/ditto/classes/ditto.class.inc.php	 
      Line: 	294	 
      Line 294 source: 	$placeholders['date'] = strftime($dateFormat,$timestamp); 
    


    Thoughts?
      • 15871
      • 105 Posts
      OK, weird, I just removed the &dateSource attribute for the Ditto call and it worked. Odd.
        • 15871
        • 105 Posts
        OK, this just happened on another site. using "pub_date" to sort and display works fine, but as soon as I use a custom date TV I get the above error. I need to use a custom date because the event is happening in the future and I need to display it correctly on the list page. If I use pub_date, it won’t display at all until the designated date. I’m using the latest version of Ditto 2.1
          • 16278
          • 928 Posts
          How is your custom date TV defined? I reproduced your error with a date TV of my own by setting it to use the Date Formatter widget. It has to use the Unixtime widget to supply Ditto with a Unix timestamp, the long integer that strftime() is expecting to receive.
          ::) KP
            • 15871
            • 105 Posts
            I’m using "Date" as the input and "unixtime" as the widget. Can you recreate the error using unixtime?

            What version of MODx are you using? I’m at 9.6.1 - Could that be it?
              • 16278
              • 928 Posts
              I’m using 0.9.6.3. Things work for me with Unixtime. The error I get when I set the widget to Date Formatter is slightly different - complaint about "string" rather than "array" being given to strftime().
              Have you tried adding &debug=`1` to your Ditto call? The last two tabs of the debug console will show you what data Ditto is being supplied from your TV (remove the [+date+] placeholder to allow the Ditto call to succeed).
              Another thing you might try is avoiding the &dateSource, &dateFormat and [+date+] business altogether. Drop the source and format parameters from the Ditto call, and just use PHx in your chunk to render your date TV instead of [+date+]:
              [+myDate:date=`%A, %b %e, %Y`+]

              huh KP
                • 15871
                • 105 Posts
                Perfect smiley

                I just used PHx and sorted on myDate. Works like a charm.

                Tnx
                  • 18399
                  • 60 Posts
                  I have exactly the same problem:

                  « MODx Parse Error »
                  MODx encountered the following error while attempting to parse the requested resource:
                  « PHP Parse Error »

                  PHP error debug
                  Error: strftime() expects parameter 2 to be long, array given
                  Error type/ Nr.: Warning - 2
                  File: /xxxx/xxxxxxxxx/public_html/xxxx/assets/snippets/ditto/classes/ditto.class.inc.php
                  Line: 294
                  Line 294 source: $placeholders[’date’] = strftime($dateFormat,$timestamp);

                  The one thing I can add is that this problem only occurs when I use "Server Offset time". Everything was fine until I changed the value from 0 to 7. Does anyone have a fix for this?

                  I really have to use my own date template variable so the solution above doesn’t work for me. I’m using Ditto and the Unixtime widget just as described in the article.

                  Who’d have thunk dealing with time would be so hard.
                    • 16278
                    • 928 Posts
                    I reproduced this error by setting a server offset time on my local install, using a TV date. No error with zero offset, your error when any offset is specified. I did some variable dumps at relevant points in ditto.class.inc.php. I can’t work out where and why it happens, but the value of the date TV in the ditto resource object at this line is an array consisting of the offset and the original value of the TV. The code below fixes it (though I’d rather know what’s actually going wrong). (Replaces lines 292-295)
                    		if (in_array("date",$this->fields["display"]["custom"])) {
                    			$timestamp = ($resource[$dateSource] != "0") ? $resource[$dateSource] : $resource["createdon"];
                    // Inserted to fix timestamp when server offset time is set; kp52 May 2009;
                            if (is_array($timestamp)) {
                                $timestamp = $timestamp[1] + $timestamp[0];
                            }
                    // End of insertion
                    			$placeholders['date'] = strftime($dateFormat,$timestamp);
                    		}
                    

                    Elastoplast is sometimes the best solution for the time being... wink
                    KP
                      • 26931
                      • 2,314 Posts
                      hi everybody,

                      ... i’m getting the same error when i set a server offset time in combination with [+date+]

                      so i try to use the TV ( as suggested above ) instead. The weird thing is, that it won’t show any output at all as soon i set a server offset time?

                      this is the TV:
                      [*startdate*]
                      Input Type: Date
                      Widget: Unixtime

                      [[Ditto? &parents=`2` &depth=`1` &display=`all` &orderBy=`startdate ASC` &dateSource=`startdate` &tpl=`eventTpl` ]]


                      {{eventTpl}}
                      <div class="cal">
                          <h2 class="calheader">[+pagetitle+]: <span >  [+startdate+] </span></h2>
                          <div class="calcontent">[+content+]</div>
                      </div>


                      any ideas?

                      thanks, j

                      // MODx Evolution 1.0.2 // PHP 5.2.9 // Database Version 5.1.33-community

                      *edit: kp52’s change to the ditto.class.inc.php will fix this of course ... i’m just wondering