-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathSystemdLogEntry.vala
More file actions
46 lines (38 loc) · 1.73 KB
/
Copy pathSystemdLogEntry.vala
File metadata and controls
46 lines (38 loc) · 1.73 KB
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
41
42
43
44
45
46
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
*/
public class About.SystemdLogEntry : GLib.Object {
public string origin { get; construct; }
public string message { get; construct; }
public DateTime dt { get; construct; }
public string relative_time { get; construct; }
public uint section_start { get; set; }
public SystemdLogEntry (string origin, string message, DateTime time) {
Object (
origin: origin, message: message, dt: time,
relative_time: format_time (time)
);
}
public bool matches (string term) {
return origin.contains (term) || message.contains (term);
}
private static string format_time (DateTime time) {
var diff = SystemdLogModel.get_stable_now ().difference (time);
if (diff < TimeSpan.SECOND) {
return _("Now");
} else if (diff < TimeSpan.MINUTE) {
var seconds = diff / TimeSpan.SECOND;
return dngettext (GETTEXT_PACKAGE, "%ds ago", "%ds ago", (ulong) seconds).printf ((int) seconds);
} else if (diff < TimeSpan.HOUR) {
var minutes = diff / TimeSpan.MINUTE;
var seconds = (diff - minutes * TimeSpan.MINUTE) / TimeSpan.SECOND;
if (seconds == 0) {
return dngettext (GETTEXT_PACKAGE, "%dm ago", "%dm ago", (ulong) minutes).printf ((int) minutes);
}
// I think the plural form is according to the last one??
return dngettext (GETTEXT_PACKAGE, "%dm %ds ago", "%dm %ds ago", (ulong) seconds).printf ((int) minutes, (int) seconds);
}
return time.format (Granite.DateTime.get_default_time_format ());
}
}