rejetto forum

Software => HFS ~ HTTP File Server => HTML & templates => Topic started by: TSG on February 08, 2009, 12:58:18 PM

Title: Showing the Age value in a different way.
Post by: TSG on February 08, 2009, 12:58:18 PM
Some people might want this, I am thinking of using it in a new template idea.

I would like to show the 'Age' of a file in a different format to the the current %item-modified% value. The suggested equation would be current date - modification date...

The format I am thinking of showing is somewhat common, basically we start off with 1m up to 59m then 1h.... then when it gets to 24h, it switches to 1d. This would be its simplest form.

A slight change to it would add weeks, so at 7 days, you get 1w. The next upgrade to this method would be to show a decimal value, so you end up with 1.1d, 1.1w.

Who is brave enough to work out an elegant method of doing this with macro ;)
Title: Re: Showing the Age value in a different way.
Post by: Mars on February 08, 2009, 02:25:12 PM
Have we the right to use some lines of javascript? :D ;D
(http://www.rejetto.com/forum/index.php?topic=6622.msg1040593#msg1040593)
Title: Re: Showing the Age value in a different way.
Post by: TSG on February 08, 2009, 02:59:21 PM
lol no, this must be macro/server side only, that's why its a challenge ;)

It might require something new in HFS, or it might be possible with macro. I don't know.
Title: Re: Showing the Age value in a different way.
Post by: rejetto on February 08, 2009, 05:24:23 PM
mmm, i think it would be too hard without adding something new.
you need to get the timestamp before it gets converted to human form, when it is just a number. it is then easy to calculate the difference.

then, i need to expand {.time.} to let you specify the timestamp (at the moment it works only with the current time).

if you plan to work on it, i will implement these features.
Title: Re: Showing the Age value in a different way.
Post by: TSG on February 08, 2009, 05:50:15 PM
This idea is for the same template I'm thinking of making the download only selected feature around. But it is an age display seen on many torrent and usenet search engines. So if implemented I can see other people using it also.
Title: Re: Showing the Age value in a different way.
Post by: Mars on February 08, 2009, 05:55:33 PM
Quote
I'm thinking of making the download only selected feature around.

Do not get tired to look, the solution is already in my sources modified since the build 214, Quite as the possibility to rename, comment, delete,  restore, or destroy definitively and individually a file.

It will be soon available for all.

The template is already ready in several versions, only the management of the rights for the users is to be strengthened so as to leave no possible fault in case of error in a template
Title: Re: Showing the Age value in a different way.
Post by: rejetto on February 08, 2009, 11:04:05 PM
@tsg
i didn't understand from your reply if you want me to make them or not
Title: Re: Showing the Age value in a different way.
Post by: Mars on February 08, 2009, 11:05:48 PM
I am working on it
Title: Re: Showing the Age value in a different way.
Post by: bacter on February 09, 2009, 01:30:47 AM
it would be nice to have two macros:

{.dtetim2nbr|21/08/2007 22:00:56.} returns numeric time from number of day (from 1-1-1900 for example) and time.

{.nbr2dtetim|numeric time.} returns a datetimestring.

I would love this functions because now y have to do some numeric macro acrobatics to create filenames based on inverse of time (higher datetime -> lower number) to have the files inverse ordered by filname. (Most recent files first)

i suppose that such functions are already part of delphi or exist in some lib.
Title: Re: Showing the Age value in a different way.
Post by: rejetto on February 09, 2009, 01:33:47 AM
is not HFS already able to sort by time (inverted) ? o.o
Title: Re: Showing the Age value in a different way.
Post by: TSG on February 09, 2009, 08:46:10 AM
@bacter This feature would be nice, however those macros suggested are very ugly...

@rejetto Something nicer is needed, something universal even, and yes my reply was intended as a 'yes, do want'. You are correct rejetto, you can invert by age, however I do not understand the problem bacter is having.

@mars NICE, if you can get the 'download only selected items' in the latest public beta I would start to work on my new template :) keeping myself busy while looking for work.
Title: Re: Showing the Age value in a different way.
Post by: bacter on February 10, 2009, 01:06:18 PM

@rejetto: i'am working on a template-module for small forums, where i already use the sort by date/time to show threads with most recent activities, but in the filename i maintain the creation-date of the thread and i wanted last created threads on top...  It happens, that when working on some project trying to solve one problem, i forget the KISS principle  ;D (this only happens to me, i'am sure  ! ;D). So instead of rearranging time simply to yymmddhhmm and sorting inverse, y used 31days months to get a number for mmdd etc..    all to avoid inverse sorting! (just thrown that stuff to the wastebasket!)

but as there remains the problem that @TSG pointed out (for me it is: las post  3 days ago, 25 minutos ago etc.) i proposed this two ugly macros, as i suppose that some timeconverting and calculation would be available in delphi.

As we can make with macros easy strings like  (yy)yymmddhhmm(ss) , perhaps it would be better and less ugly (this would serve to me and TSG i suppose) , if we could have a macro difftime.

{.difftime|0902101349|0901051050.}     that returns a string  like ddddhhmm

optional the macro could could admit only one parameter:

{.difftime|0902101349.}     that would return the difftime to system time.

Title: Re: Showing the Age value in a different way.
Post by: rejetto on February 11, 2009, 04:15:08 PM
ok, next build should have everything you need.

+ new template symbols: %now% %item-added-dt% %item-modified-dt%
+ {.time.} supports new parameter "when" to use a different time than the current one
+ new template macro: trunc

the numeric format will be 1.0 for a day (then 1/24 for an hour).
to make non-integer computations you must use {.calc.}

then, you should make your macro to display the elapsed time.
my suggestion is to make something that will take 1 or 2 parameters.
if 2 parameters: subtract.

ok, i spent the last hour making it for you ... ::)

Code: [Select]
{.set|elapsed step|{:
    {.set|t| {.calc|({.^t.}-{.^r.})*$2.} .}
    {.set|r| {.substring||.|{.^t.}.} .}
    {.set|$1| {.^r.} .}
:}.}

{.set|elapsed|{:
    {.set|t| {.calc| {.if|$2| {.calc|$1-$2.} | $1/if.} /30 .} .}
    {.set|r| {.substring||.|{.^t.}.} .}
    {.set|months|{.^r.}.}
    {.^elapsed step|days|30.}   
    {.^elapsed step|hours|24.}   
    {.^elapsed step|minutes|60.}

    Time elapsed:
    {.cut||-1| {.comment|this will remove the last comma.}
    {.if|{.^months.}|{.^months.} month(s), .}
    {.if|{.^days.}|{.^days.} day(s), .}
    {.if|{.^hours.}|{.^hours.} hour(s), .}
    {.if|{.^minutes.}|{.^minutes.} minute(s),.}
    /cut.}
:}.}


usage example
{.^elapsed|%now%|%item-modified-dt%.}
Title: Re: Showing the Age value in a different way.
Post by: TSG on February 12, 2009, 11:56:08 AM
Will give it a go!

What is the difference between %timestamp% and %now%? Don't worry I got it lol.

The macro seems to work nice though...

I hope you weren't working out this macro while driving :)
Title: Re: Showing the Age value in a different way.
Post by: rejetto on February 19, 2009, 02:08:49 AM
i made some changes to the code above: it is not using {.trunc.} anymore.
i noticed {.substring.} is more than enough.
i think i should remove {.trunc.} support. opinions are welcome.
Title: Re: Showing the Age value in a different way.
Post by: Mars on February 19, 2009, 08:55:42 AM
This is a simple personal opinion:

It is sometimes preferable to have several macro which allow to make a very precise action (but not necessarily unique) that to have the macro only one who can make a multitude of things, with a not unimportant number of parameters which most of the time are not useful. What has for consequence often to lengthen the template.

As in the example below:

{.substring|begin|end|it is the begin before the end of text.}     -->> ' before the '


{.substring||end|it is the begin before the end of text.}     -->> 'it is the begin before the '
{.chop begin|end|it is the begin before the end of text.}


{.substring|begin||it is the begin before the end of text.}     -->> ' before the end of text'
{.chop end|begin|it is the begin before the end of text.}

More of macro but fewer parameters every time.

Otherwise, rejetto, I propose you a compromise:
A section [macro] or we could define our personal macro without crossing every time by the macro SET and not use the ^ at every time

[macros]
chop begin=substring||$1|$2     
chop end=substring|$1||$2

[my section]
{.if|{.chop begin|end|it is the begin before the end of text.}|{:one action:}|{:other action:}/if.}

The example is not of the most simplistic, but it is to give an idea of the possibilities.
I am going to try to find of the delphi code to go to this direction
Title: Re: Showing the Age value in a different way.
Post by: rejetto on February 19, 2009, 12:14:55 PM
i like this "compromise".
just changed the name in [special:alias].
implemented. next build.
Title: Re: Showing the Age value in a different way.
Post by: Mars on February 19, 2009, 02:44:29 PM
With this contribution of [special:alias], it will not be necessary to redo all the templates to replace the old macros:

[special:alias]
trunc=substring||.|$1

and other when found.. :D

Rejetto will thus have to watch to add indeed all the macro, which he kills as one goes along, in this new section of the default.tpl ;)

It is obvious that quite macro before being executed, must be looked for for its equivalence in the section alias.

Quote
    p:=par(0); // a handy shortcut for the first parameter

Code: [Select]
    repeat
       if not (p in [special:alias] ) then break;
        replace (p, new macro)
    until false
    // comment it's for comments, or if you just don't want the output a macro to be sent to the browser.
    // the content of comment (the parameter) is executed as anything else, it's not like macro quoting.
    if name = 'comment' then
      begin
      result:='';
      exit;
      end;


Title: Re: Showing the Age value in a different way.
Post by: TSG on February 20, 2009, 06:00:00 AM
mars isn't 'chop' the same as 'slice' in most programming languages?

{.slice|begin|end|it is the begin before the end of text.} etc...

I think that's what you are trying to achieve with this? the ability to 'slice' a string, that's the term that immediately came to my mind...

http://www.w3schools.com/jsref/jsref_obj_array.asp
Title: Re: Showing the Age value in a different way.
Post by: Mars on February 20, 2009, 09:52:38 AM
Quote
mars isn't 'chop' the same as 'slice' in most programming languages?

I make reference only to what rejetto in the sources(springs) of hfs use, it is to him that it is necessary to ask for explanations  ;) :D

Quote
hslib.pas
{ split S in position where SS is found, the first part is returned
  the second part following SS is left in S }
function chop(ss:string; var s:string):string; overload;
// same as before, but separator is I
function chop(i:integer; var s:string):string; overload;
// same as before, but specifying separator length
function chop(i, l:integer; var s:string):string; overload;
// same as chop(lineterminator, s)
function chopLine(var s:string):string; overload;
Title: Re: Showing the Age value in a different way.
Post by: rejetto on February 20, 2009, 12:48:25 PM
i think i borrowed that term from when i was using perl (90s), and just stayed there
:)