bookman53 Posted May 9, 2020 Share Posted May 9, 2020 My announcements page a date of 31 Dec 1969 below the excerpt. On the full article page, it displays the correct date. Any ideas how to correct the date issue on the excerpt page, other than hiding it with CSS? Thanks. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 10, 2020 Share Posted May 10, 2020 18 hours ago, bookman53 said: Any ideas how to correct the date issue on the excerpt page, other than hiding it with CSS? have you edited the announcements.tpl template? I ask because I think uniquely the announcemeents template doesn't receive a formatted date - it's formats it in the template - and so i'm wondering if you've removed / broken the date formatting code in the template ? 0 Quote Link to comment Share on other sites More sharing options...
bookman53 Posted May 10, 2020 Author Share Posted May 10, 2020 The announcements.tpl in my case is part of the theme I bought from WHMCS Themes. This is that line of code in the Six template: {$carbon->createFromTimestamp($announcement.timestamp)->format('jS M Y')} This is that line of code in my template: {$carbon->createFromTimestamp($announcement.timestamp)->format('jS M Y')} To my eye, they appear identical. I just tested them by turning the Six theme on. The same issue exists with the Six theme. 1969 date under the excerpt. Current date under the full article. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 10, 2020 Share Posted May 10, 2020 3 hours ago, bookman53 said: To my eye, they appear identical. I just tested them by turning the Six theme on. The same issue exists with the Six theme. 1969 date under the excerpt. Current date under the full article. that implies that there might be something wrong with the date itself in the array. 0 Quote Link to comment Share on other sites More sharing options...
bear Posted May 10, 2020 Share Posted May 10, 2020 Agree with Brian. That's defaulting to the epoch time in your time zone, meaning it's not getting a proper date from it and it's guessing. 0 Quote Link to comment Share on other sites More sharing options...
bookman53 Posted May 10, 2020 Author Share Posted May 10, 2020 1 hour ago, bear said: Agree with Brian. That's defaulting to the epoch time in your time zone, meaning it's not getting a proper date from it and it's guessing. This is happening not just in the purchased theme that I'm using, but also in the default Six theme. It seems strange that the date on the full article page is correct but the date on the excerpt is wrong. Apparently the code that calls the date on the full article is different than that on the excerpt. How do we go about getting the correct code to display in both places? I could try to hide the date with CSS, but that's rather like a bandage than a cure. Thanks for your help. 0 Quote Link to comment Share on other sites More sharing options...
bear Posted May 10, 2020 Share Posted May 10, 2020 (edited) I'm running an older install here, and it's not using $carbon so I can't check the template. In mine, it shows as expected everywhere, though in the excerpt it's using date/month/year rather then the full day/month/date/year in the full article. [edit] Not sure why, but my text editor wasn't finding $carbon. It's there in the announcements.tpl template. Edited May 10, 2020 by bear 0 Quote Link to comment Share on other sites More sharing options...
bear Posted May 10, 2020 Share Posted May 10, 2020 Looking more closely, these are generated by two different templates, using slightly different methods. announcements.tpl uses: {$carbon->createFromTimestamp($announcement.timestamp)->format('M jS Y')} Where the full article view (viewannouncement.tpl) uses: {$carbon->createFromTimestamp($timestamp)->format('l, F j, Y')} 0 Quote Link to comment Share on other sites More sharing options...
bookman53 Posted May 10, 2020 Author Share Posted May 10, 2020 Do you think it would work if I replaced the the announcements.tpl time code with that from the viewannouncements.tpl? 0 Quote Link to comment Share on other sites More sharing options...
bear Posted May 10, 2020 Share Posted May 10, 2020 Mine works with no change (except I did move the date format around so they match), but I'd wonder why they give different results. You could give it a go, but I don't know if that will adversely affect anything. Worth a look, but save the old line to put it back should things go pear shaped. 0 Quote Link to comment Share on other sites More sharing options...
bookman53 Posted May 10, 2020 Author Share Posted May 10, 2020 14 minutes ago, bear said: Mine works with no change (except I did move the date format around so they match), but I'd wonder why they give different results. You could give it a go, but I don't know if that will adversely affect anything. Worth a look, but save the old line to put it back should things go pear shaped. I tried a variety of changes and none of them worked. I tried copying the entire line from viewannouncement.tpl into announcement.tpl. That made no difference. I then tried copying the time format from viewannouncement.tpl into announcement.tpl. That made no difference, either. Excerpts still show the wonky 1969 date. Full announcements still display the correct date. 0 Quote Link to comment Share on other sites More sharing options...
bear Posted May 10, 2020 Share Posted May 10, 2020 That leads me to think it may be the info in the database, or possibly a stray file from an older version somewhere. Usually when it displays that it's related to data it can't understand, like a string instead of a date. It tries to format it as a date, and gives the default when it can't decipher the input. As an experiment, I'd try changing the call on the one that looks *right* (save the line for putting back) to the one that gives the 1969 date and see if it does it on that page also. This may be a good one to ask support about. 0 Quote Link to comment Share on other sites More sharing options...
bookman53 Posted May 10, 2020 Author Share Posted May 10, 2020 4 minutes ago, bear said: As an experiment, I'd try changing the call on the one that looks *right* (save the line for putting back) to the one that gives the 1969 date and see if it does it on that page also. I copied the 1969 code to viewannouncement.tpl. It displayed the 1969 date where it had been displaying the correct date. I then put back the code that was there and it displayed the correct date. 0 Quote Link to comment Share on other sites More sharing options...
bear Posted May 11, 2020 Share Posted May 11, 2020 Then I'd reach out to WHMCS support and explain that "$announcement.timestamp" and "$timestamp" return different results, and ask how to troubleshoot the "$announcement.timestamp" value being called. 0 Quote Link to comment Share on other sites More sharing options...
bookman53 Posted May 11, 2020 Author Share Posted May 11, 2020 Okay. Thank you. 0 Quote Link to comment Share on other sites More sharing options...
bookman53 Posted May 11, 2020 Author Share Posted May 11, 2020 7 hours ago, brian! said: that implies that there might be something wrong with the date itself in the array. I submitted a ticket to support, then suddenly remembered the hook that you gave me to improve the way announcements displayed. I went back and opened it to see if there was any time-related code in there that might cause the 1969 date. I found some date code that I wondered about. I deleted that hook and the time problem went away. Trouble is, my announcement excerpts display went back to a boring look with no photos on the excerpts. To save you looking it up, here is the hook: <?php # Get More Announcements on Homepage # Written by brian! use Illuminate\Database\Capsule\Manager as Capsule; function homepage_announcements_hook($vars) { $announce = Capsule::table('tblannouncements') ->where('published','<>','0') ->where('published','<>','') ->select('id','date as rawDate','title','announcement as text') ->orderBy('date','desc') ->limit(8) ->get(); $encodedata = json_encode($announce); $decodedata = json_decode($encodedata, true); foreach ($decodedata as $index => $option){ $decodedata[$index]['urlfriendlytitle'] = getModRewriteFriendlyString($decodedata[$index]['title']); $decodedata[$index]['summary'] = mb_strimwidth($decodedata[$index]['text'], 0, 350, "..."); } return array("announcements" => $decodedata); } add_hook("ClientAreaPage", 1, "homepage_announcements_hook"); ?> I wonder if the following line from the hook could be the culprit (date as rawDate). ->select('id','date as rawDate','title','announcement as text') I really like the way my announcement excerpts display with the hook in place. If the line above is not the culprit, is there a line of code we could add that might correct the time issue? Thanks. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 11, 2020 Share Posted May 11, 2020 7 hours ago, bookman53 said: I submitted a ticket to support, then suddenly remembered the hook that you gave me to improve the way announcements displayed. yeah I wondered last night if the hook was the cause of this - though, in my defence, it was written for pages outside of announcements, rather than replacing announcements itself. 👩⚖️ 7 hours ago, bookman53 said: To save you looking it up, here is the hook oh one of the constant thoughts over the last weeks has been thinking about manipulating announcements, blogs etc! 😀 7 hours ago, bookman53 said: If the line above is not the culprit, is there a line of code we could add that might correct the time issue? the problem is the announcements page is expecting to receive an unix timestamp and the hook is giving it a date (and the wrong variable name too) - so i've tweaked this hook to only work on the announcements page (and not every page as your hook currently does), and to pass both a timestamp and a date for each article... by default, the announcements template will want to use the timestamp, but if you wanted to, you could remove that entire carbon line from the template and replace it with {$announcement.date) and the date format should be exactly the same (and can be changed in the hook)... <?php # Announcements Hook @bookman53 # Written by brian! use WHMCS\Database\Capsule; use Carbon\Carbon; function bookman53_announcements_hook($vars) { $announce = Capsule::table('tblannouncements')->where('published','1')->select('id','date','title','announcement as text')->orderBy('date','desc')->limit(8)->get(); $announcements = json_decode(json_encode($announce), true); foreach ($announcements as $key => $option){ $announcements[$key]['urlfriendlytitle'] = getModRewriteFriendlyString($announcements[$key]['title']); $announcements[$key]['summary'] = mb_strimwidth($announcements[$key]['text'], 0, 350, "..."); $announcements[$key]['date'] = Carbon::parse($announcements[$key]['date'])->format('jS M Y'); $announcements[$key]['timestamp'] = Carbon::parse($announcements[$key]['date'])->timestamp; } return array("announcements" => $announcements); } add_hook("ClientAreaPageAnnouncements", 1, "bookman53_announcements_hook"); 0 Quote Link to comment Share on other sites More sharing options...
bear Posted May 11, 2020 Share Posted May 11, 2020 Certainly explains it. Getting a string when expecting a numeric date would definitely do that. Of course, I had no idea there was a hook. 😉 0 Quote Link to comment Share on other sites More sharing options...
bookman53 Posted May 11, 2020 Author Share Posted May 11, 2020 (edited) 22 minutes ago, bear said: Of course, I had no idea there was a hook. 😉 @bear I had forgotten about the hook, then it sprang back into my memory from somewhere. Thanks for your help. Edited May 11, 2020 by bookman53 0 Quote Link to comment Share on other sites More sharing options...
bookman53 Posted May 11, 2020 Author Share Posted May 11, 2020 1 hour ago, brian! said: yeah I wondered last night if the hook was the cause of this - though, in my defence, it was written for pages outside of announcements, rather than replacing announcements itself. 👩⚖️ @brian! You did your magic! The new hook fixed the issue. Correct date on excerpts and full announcements. Thanks a million for your help. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.