1
robekras
Last Post date/time issue
  • 2003/12/14 14:01

  • robekras

  • Documentation Writer

  • Posts: 187

  • Since: 2002/12/10


Don't know whether this has been discussed before?
But here I am.

When you take a look at date/time in Recent topics, the date and time is changing sometimes if I do an refresh of the page.

As I understand it works this way:
The page is normaly cached.
Someone is posting something new.
Then if someone is entering (or refreshing) the page,
the page source is generated (and then cached until a new post) and the date/time is calculated according the
time zone of the one which has forced the refresh.
So if I take a look at the page again I see the date/time of someone else's time zone.

How could this behaviour be changed?
Could this be done with javascript?
The page outputs the GMT and a short javascript function
which calculates the correct date/time on client side?

Could this be done?
My knowledge about javascript is very low.
I just know that it exists.

2
Dave_L
Re: Last Post date/time issue
  • 2003/12/18 17:09

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Thanks for explaining why the problem occurs. I had forgotten about the cache.

If I have time, I'll see if I can come up with a Javascript fix.

Maybe a better solution would be to disable caching for blocks such as Recent Topics that depend on user preference settings.

3
robekras
Re: Last Post date/time issue
  • 2003/12/18 18:18

  • robekras

  • Documentation Writer

  • Posts: 187

  • Since: 2002/12/10


I've played around a little with javascript the last days.
I think it isn't too difficult to do.

It would need (of course) some javascript code
which would do the conversion of the original date/time to
the users local time.
Whereas the parsing of the date could be a little problematic,
because of the different possible date formats.

An approach:
If we have to output a date/time for cached content we can output a date/time in a standard date/time format like this.
<div name="gmt_dt">2003-12-18 14:36</div>

The javascript code looks for every element with name gmt_dt and does the conversion.

I looked around the net and found a source for javascript date/time conversion here:

http://www.merlyn.demon.co.uk/js-date1.htm

BTW when speaking of a date/time format we should take a look at the following:
http://www.cl.cam.ac.uk/~mgk25/iso-time.html
and here:
http://www.w3.org/TR/NOTE-datetime

4
Dave_L
Re: Last Post date/time issue
  • 2003/12/18 18:28

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I was thinking of storing the timestamp, rather than a formatted date/time, in the cached content. I know that Javascript can convert that to a formatted date/time string.

Of course, it should also be done in such a way that if the user's browser has Javascript diabled, then the results will still be reasonable.

5
Dave_L
Re: Last Post date/time issue
  • 2004/1/14 7:23

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I've finished the initial version of a hack. I'd like to get a couple of others to confirm that it works before I try to get it incorporated into the base code.

1) modules/newbb/blocks/newbb_new.php, function b_newbb_new_show

Find:
$topic['time'] = formatTimestamp($arr['topic_time'],'m').$tmpuser";


Insert after:
#*#RETOPS_UNCACHE_TS# - start
                
$topic['timestamp'] = $arr['topic_time'];
                
$topic['username']  = $tmpuser;
                
#*#RETOPS_UNCACHE_TS# - end


2) Template for Recent Topics block

Insert at beginning:
<!-- #*#RETOPS_UNCACHE_TS# - start -->
<script language="javascript" type="text/javascript">
  
// emulate PHP function call date(timestamp, 'Y/n/j G:i')
  // timestamp = seconds since 1970-01-01 00:00:00 GMT
  
function formatted_date(timestamp) {
     var 
date    = new Date(timestamp 1000);
     var 
year    date.getFullYear();
     var 
month   date.getMonth() + 1;
     var 
day     date.getDate();
     var 
hours   date.getHours();
     var 
min     date.getMinutes();
     var 
minutes = (min 10) ? '0' min min;
     return 
year '/' month '/' day ' ' hours ':' minutes;
  }
</
script>
<!-- 
#*#RETOPS_UNCACHE_TS# - end -->


Find (two instances):
<td align="right"><{$topic.time}></td>


Replace (each instance) with:
<!-- #*#RETOPS_UNCACHE_TS# - start -->
    
<td align="right">
      <
script language="javascript" type="text/javascript">
        
document.write('<b>J</b>' formatted_date(<{$topic.timestamp}>) + ' <{$topic.username}>');
      </
script>
      <
noscript>
        <
b>P</b><{$topic.time}>
      </
noscript>
    </
td>
<!-- 
#*#RETOPS_UNCACHE_TS# - end -->


For testing purposes only, I've prefixed the dates with J if the date/time is generated by Javascript, and by P if the date/time is generated by PHP. The latter occurs if Javascript is disabled on the client's browser.

6
robekras
Re: Last Post date/time issue
  • 2004/1/15 16:39

  • robekras

  • Documentation Writer

  • Posts: 187

  • Since: 2002/12/10


When can we see it on xoops.org?

I'm getting impatient

7
Mithrandir
Re: Last Post date/time issue

Well, try it, test it and give feedback

if it works, I'll expect it to be a part of the next version of newBB

8
Dave_L
Re: Last Post date/time issue
  • 2004/1/15 23:59

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I'd also like to get feedback on the implementation. E.g., whether there are any changes that would make it more consistent with the XOOPS standard conventions.

And here are a few issues:

1) I don't know of a nice way to automatically pick up the format defined by the constant _MEDIUMDATESTRING in language/english/global.php, so the Javascript uses a hardcoded date/time format.

2) The changes made to the Recent Topics block template also need to be made to the templates for the Most Viewed Topics, Most Active Topics and Recent Private Topics blocks. Is it desirable to put as much as possible of the common code in a single file that all of these templates can include?

3) The Javascript is only needed if the blocks are cached. I don't know if it's worthwhile to try to deal with that case.

Login

Who's Online

221 user(s) are online (129 user(s) are browsing Support Forums)


Members: 0


Guests: 221


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits