how long it is since a forum post was created

Author Message

Angeliki Shearstone

Tuesday 23 June 2009 3:29:00 am

Hi,

We are looking do the following

Display how long it is since a forum post was created in the format days , hours , minutes

E.g. Posted 1 Day 5 Hours 10 Minutes

However we are finding it quite limiting trying to do this using the template language and wonder if any one knows how to do this or has a function or extension we can use that does this

Thanks in Advance

Jon Staines

Tuesday 23 June 2009 6:21:29 am

There are probably much neater solutions but if need be you can do something like:

{def $date_difference = sub( currentdate(), $node.object.published )
     $days = floor( div( $date_difference, 86400 ) )
     $hours_mins = mod( $date_difference, 86400 )
     $hours = floor( div( $hours_mins, 3600 ) )
     $mins = floor( div( mod( $hours_mins, 3600 ), 60) ) }

And display it with:

{$days} Days, {$hours} hours {$mins} minutes ago.

Of course, caching would cause the time to remain frozen. Plus you might want to add some logic to change Days to Day if there is only 1 etc.

Angeliki Shearstone

Tuesday 23 June 2009 7:35:59 am

Thank you!!!! You have actually written the code for me! It works perfect.

Thanks again.

Angelika

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 11:19:04
Script start
Timing: Jan 18 2025 11:19:04
Module start 'layout'
Timing: Jan 18 2025 11:19:04
Module start 'content'
Timing: Jan 18 2025 11:19:05
Module end 'content'
Timing: Jan 18 2025 11:19:05
Script end

Main resources:

Total runtime0.6382 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 589.1641152.6406
Module start 'layout' 0.00600.0032 741.804739.4766
Module start 'content' 0.00920.6269 781.2813501.8906
Module end 'content' 0.63610.0020 1,283.17198.1250
Script end 0.6381  1,291.2969 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.5453160.0002
Check MTime0.00150.2411160.0001
Mysql Total
Database connection0.00080.117710.0008
Mysqli_queries0.583591.4336570.0102
Looping result0.00070.1061550.0000
Template Total0.605894.920.3029
Template load0.00210.325220.0010
Template processing0.603794.595020.3018
Template load and register function0.00020.034510.0002
states
state_id_array0.00090.140310.0009
state_identifier_array0.00080.123320.0004
Override
Cache load0.00170.2725200.0001
Sytem overhead
Fetch class attribute can translate value0.00100.155520.0005
Fetch class attribute name0.00140.226140.0004
XML
Image XML parsing0.00070.116020.0004
class_abstraction
Instantiating content class attribute0.00000.001640.0000
General
dbfile0.00100.1612160.0001
String conversion0.00000.001540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 13
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs