1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| function DiffToStr(const ANow, AThen: TDateTime): string;
resourcestring
strLessThanOnMinute = 'Il y a moins d''une minute';
strLessThanOneHour = 'Il y a environ %d minute(s)';
strLessThanForHours = 'Il y a environ %d heure(s).';
strToday = 'Aujourd''hui';
strYesterday = 'Hier';
strBeforeYesterday = 'Avant hier';
strBeforeDays = 'Il y a environ %d jour(s).';
var
LSeconds: Int64;
LHours: Int64;
LToday: TDateTime;
begin
LSeconds := SecondsBetween(ANow, AThen);
LHours := HoursBetween(ANow, AThen);
if LSeconds < 60 then
Result := strLessThanOnMinute
else
if LSeconds < 3600 then
Result := Format(strLessThanOneHour, [Round(LSeconds / 60)])
else
if LHours < 4 then
Result := Format(strLessThanForHours, [LHours])
else
begin
LToday := EncodeDateTime(YearOf(ANow), MonthOf(ANow), DayOf(ANow), 0, 0, 0, 0);
LHours := HoursBetween(LToday, AThen);
if AThen > LToday then
Result := strToday
else
if LHours < 24 then
Result := strYesterday
else
if LHours < 48 then
Result := strBeforeYesterday
else
Result := Format(strBeforeDays, [(LHours div 24) + 1]);
end;
end; |
Partager