-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"From now" format for datetime columns #1043
Comments
For date delta use PeriodBetween function: Only affected function - TMainForm.TorrentDateTimeToString |
Localization and option to enable this format needed. But something like: function PeriodName(per: word; pername: string): string;
begin
if per=0 then Result:='' else Result:=IntToStr(per) + ' ' + pername + ' ';
end;
function TMainForm.TorrentDateTimeToString(d: Int64): string;
var dt, dt1: TDateTime;
dd, dm, dy: word;
s: string;
begin
if d = 0 then
Result:=''
else
begin
// Result:=DateTimeToStr(UnixToDateTime(d) + GetTimeZoneDelta);
dt:=UnixToDateTime(d) + GetTimeZoneDelta;
dt1:=Now;
PeriodBetween(dt1, dt, dy, dm, dd);
dt1:=Abs(Frac(dt-dt1));
s:=PeriodName(dy, 'y') + PeriodName(dm, 'mo') + PeriodName(dd, 'd') + PeriodName(Trunc(dt1*24), 'h') + PeriodName(Trunc(dt1*24*60) mod 60, 'm') + PeriodName(Trunc(dt1*24*60*60) mod 60, 's');
if Length(s)=0 then s:='0 s';
s:=s+'ago';
Result:=s;
end;
end; |
Or (even better): function TMainForm.TorrentDateTimeToString(d: Int64): string;
var dt, dt1: TDateTime;
dd, dmo, dy, dh, dm, ds: word;
s: string;
begin
if d = 0 then
Result:=''
else
begin
// Result:=DateTimeToStr(UnixToDateTime(d) + GetTimeZoneDelta);
dt:=UnixToDateTime(d) + GetTimeZoneDelta;
dt1:=Now;
PeriodBetween(dt1, dt, dy, dmo, dd);
dt1:=Abs(Frac(dt-dt1));
s:=PeriodName(dy, 'y') + PeriodName(dmo, 'mo') + PeriodName(dd, 'd');
if dy+dmo=0 then
begin
dh:=Trunc(dt1*24);
s:=s+PeriodName(dh, 'h');
if dd=0 then
begin
dm:=Trunc(dt1*24*60) mod 60;
s:=s+PeriodName(dm, 'm');
if dh=0 then
begin
ds:=Trunc(dt1*24*60*60) mod 60;
PeriodName(ds, 's');
end;
end;
end;
if Length(s)=0 then s:='0 s';
s:=s+'ago';
Result:=s;
end;
end; |
ok, thanks 👍 |
I'm working on this... function TorrentDateTimeToString(d: Int64; FromNow:Boolean = false): string; And modify the function like this: function TMainForm.TorrentDateTimeToString(d: Int64; FromNow: Boolean): string;
begin
if d = 0 then
Result:=''
else
if FromNow then
Result := HumanReadableTime(Now,UnixToDateTime(d) + GetTimeZoneDelta) else
Result:=DateTimeToStr(UnixToDateTime(d) + GetTimeZoneDelta);
end; Then make a new boolean value in transgui.ini and read it in Oncreate of the form. FFromNow := Ini.ReadBool('MainForm','FromNow',false); To make localizable you have to define sYears, sMonths (sDays, sHours, sMins, sSecs are already defined) sMonths = '%dmo';
sYears = '%dy'; And then make the HumanReadableTime function: function HumanReadableTime(ANow,AThen: TDateTime): string;
var
Years, Months, Days, Hours, Minutes, Seconds, Discard: Word;
begin
Try
PeriodBetween(ANow,AThen,Years,Months,Days);
DecodeDateTime(Anow-AThen,Discard,Discard,Discard,Hours,Minutes,Seconds,Discard);
if Years > 0 then begin
Result := Format(sYears,[Years]) + ' ' + Format(sMonths,[Months]);
end else if Months > 0 then begin
Result := Format(sMonths,[Months]) + ' ' + Format(sDays,[Days]);
end else if Days > 0 then begin
Result := Format(sDays,[Days]) + ' ' + Format(sHours,[Hours]);
end else if Hours > 0 then begin
Result := Format(sHours,[Hours]) + ' ' + Format(sMins,[Minutes]);
end else if Minutes > 0 then begin
Result := Format(sMins,[Minutes]) + ' ' + Format(sSecs,[Seconds]);
end else begin
Result := Format(sSecs,[Seconds])
end;
Except
Result := 'An Eternity';
End;
end; So, then you have to replace every call to TorrentDateTimeToString with the new optional parameter like this: procedure TMainForm.gTorrentsCellAttributes(Sender: TVarGrid; ACol, ARow, ADataCol: integer;
AState: TGridDrawState; var CellAttribs: TCellAttributes);
...
Text:=TorrentDateTimeToString(Sender.Items[ADataCol, ARow],FFromNow);
... |
@antekgla - try :) good luck to you ! |
I wrote that it needs localization and option support. And I think there is no need to add additional parameter to function, we can read option directly in TMainForm.TorrentDateTimeToString function |
I also consider that, but for example in my current Transmission setup with 300 torrents and columns Completed On, Added On & Last Active that would be 900 reads to the ini file every time TransGUI draw the torrent grid (in my case each 5 seconds) |
New property like TMainForm.FFromNow solves this. And arguments of TMainForm.TorrentDateTimeToString untouched. And again, I dont wrote "read directly from file"... |
Wel... I finally implement this. If you want to display the Date/Times in a Relative Way (to Now) add a new value in transgui.ini in the [Mainform] section:
where 1= Relative Times and 0 or missing= MM/DD/YY HH:MM:SS In both cases I implement the possibility of view the Date/Time in the other way. If you view Relative Times the hint shows you Absolute Times: If you view Absolute Times the hints shows Relative Times: |
@antekgla awesome 👍 |
New Feature: #1043 Implement the Display of Relative Dates/Times (to Now)
Maybe optional.
Added/completed/last activity columns format like a "1h 33m ago" or "1d 11h 5m ago" and so on (w - week, m - month, y - year).
The text was updated successfully, but these errors were encountered: