Skip to content

Commit f6bec33

Browse files
authored
AgendaEventRow: create get_timespan_label (#915)
1 parent ab2dcfc commit f6bec33

1 file changed

Lines changed: 53 additions & 48 deletions

File tree

src/Widgets/AgendaEventRow.vala

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class Maya.View.AgendaEventRow : Gtk.ListBoxRow {
3939
private Gtk.GestureMultiPress click_gesture;
4040
private Gtk.GestureLongPress long_press_gesture;
4141

42+
private Gtk.Grid main_grid;
4243
private Gtk.Image event_image;
4344
private Gtk.Label name_label;
4445
private Gtk.Label datetime_label;
@@ -212,7 +213,7 @@ public class Maya.View.AgendaEventRow : Gtk.ListBoxRow {
212213
child = location_label
213214
};
214215

215-
var main_grid = new Gtk.Grid () {
216+
main_grid = new Gtk.Grid () {
216217
column_spacing = 6,
217218
margin_top = 6,
218219
margin_end = 12,
@@ -221,7 +222,7 @@ public class Maya.View.AgendaEventRow : Gtk.ListBoxRow {
221222
};
222223
main_grid.attach (event_image, 0, 0);
223224
main_grid.attach (name_label, 1, 0);
224-
main_grid.attach (datetime_label, 1, 1);
225+
// leave space for datetime label
225226
main_grid.attach (location_revealer, 1, 2);
226227

227228
main_grid_context = main_grid.get_style_context ();
@@ -321,55 +322,13 @@ public class Maya.View.AgendaEventRow : Gtk.ListBoxRow {
321322
is_allday = Calendar.Util.datetime_is_all_day (start_date, end_date);
322323
is_multiday = Calendar.Util.icalcomponent_is_multiday (ical_event);
323324

324-
var date_format = Granite.DateTime.get_default_date_format (true, true, false);
325-
string start_date_string = start_date.format (date_format);
326-
string end_date_string = end_date.format (date_format);
327-
string start_time_string = start_date.format (Settings.time_format ());
328-
string end_time_string = end_date.format (Settings.time_format ());
329-
string? datetime_string = null;
330-
331-
var is_same_time = start_time_string == end_time_string;
332-
333-
datetime_label.show ();
334-
datetime_label.no_show_all = false;
335-
if (is_multiday) {
336-
if (is_allday) {
337-
// TRANSLATORS: A range from start date to end date i.e. "Friday, Dec 21 – Saturday, Dec 22"
338-
datetime_string = C_("date-range", "%s%s").printf (start_date_string, end_date_string);
339-
} else {
340-
// TRANSLATORS: A range from start date and time to end date and time i.e. "Friday, Dec 21, 7:00 PM – Saturday, Dec 22, 12:00 AM"
341-
datetime_string = _("%s, %s%s, %s").printf (start_date_string, start_time_string, end_date_string, end_time_string);
342-
}
325+
datetime_label.label = get_timespan_label (start_date, end_date);
326+
if (datetime_label.label != "") {
327+
main_grid.attach (datetime_label, 1, 1);
343328
} else {
344-
if (!is_upcoming) {
345-
if (is_allday) {
346-
datetime_label.hide ();
347-
datetime_label.no_show_all = true;
348-
} else {
349-
if (is_same_time) {
350-
datetime_string = start_time_string;
351-
} else {
352-
// TRANSLATORS: A range from start time to end time i.e. "7:00 PM – 9:00 PM"
353-
datetime_string = C_("time-range", "%s%s").printf (start_time_string, end_time_string);
354-
}
355-
}
356-
} else {
357-
if (is_allday) {
358-
datetime_string = "%s".printf (start_date_string);
359-
} else {
360-
if (is_same_time) {
361-
// TRANSLATORS: A single time from the start date i.e. "Friday, Dec 21 at 7:00 PM"
362-
datetime_string = _("%s at %s").printf (start_date_string, start_time_string);
363-
} else {
364-
// TRANSLATORS: A range from start date and time to end time i.e. "Friday, Dec 21, 7:00 PM – 9:00 PM"
365-
datetime_string = _("%s, %s%s").printf (start_date_string, start_time_string, end_time_string);
366-
}
367-
}
368-
}
329+
main_grid.remove (datetime_label);
369330
}
370331

371-
datetime_label.label = datetime_string;
372-
373332
string location_description, location_uri;
374333
if (location_from_component (event, out location_description, out location_uri)) {
375334
if (location_uri != "") {
@@ -380,6 +339,52 @@ public class Maya.View.AgendaEventRow : Gtk.ListBoxRow {
380339
}
381340
}
382341

342+
private string get_timespan_label (DateTime start_date, DateTime end_date) {
343+
var date_format = Granite.DateTime.get_default_date_format (true, true, false);
344+
var start_date_string = start_date.format (date_format);
345+
var start_time_string = start_date.format (Settings.time_format ());
346+
var end_time_string = end_date.format (Settings.time_format ());
347+
348+
if (is_multiday) {
349+
var end_date_string = end_date.format (date_format);
350+
351+
if (is_allday) {
352+
// TRANSLATORS: A range from start date to end date i.e. "Friday, Dec 21–Saturday, Dec 22"
353+
return C_("date-range", "%s%s").printf (start_date_string, end_date_string);
354+
}
355+
356+
// TRANSLATORS: A range from start date and time to end date and time i.e. "Friday, Dec 21, 7:00 PM–Saturday, Dec 22, 12:00 AM"
357+
return _("%s, %s%s, %s").printf (start_date_string, start_time_string, end_date_string, end_time_string);
358+
}
359+
360+
var is_same_time = start_date.equal (end_date);
361+
362+
if (!is_upcoming) {
363+
if (is_allday) {
364+
return "";
365+
}
366+
367+
if (is_same_time) {
368+
return start_time_string;
369+
}
370+
371+
// TRANSLATORS: A range from start time to end time i.e. "7:00 PM–9:00 PM"
372+
return C_("time-range", "%s%s").printf (start_time_string, end_time_string);
373+
}
374+
375+
if (is_allday) {
376+
return start_date_string;
377+
}
378+
379+
if (is_same_time) {
380+
// TRANSLATORS: A single time from the start date i.e. "Friday, Dec 21 at 7:00 PM"
381+
return _("%s at %s").printf (start_date_string, start_time_string);
382+
}
383+
384+
// TRANSLATORS: A range from start date and time to end time i.e. "Friday, Dec 21, 7:00 PM–9:00 PM"
385+
return _("%s, %s%s").printf (start_date_string, start_time_string, end_time_string);
386+
}
387+
383388
private void find_keywords (Category category, string phrase, ref Category current_category, ref int current_hits) {
384389
int hits = 0;
385390
foreach (string keyword in keyword_map.@get (category)) {

0 commit comments

Comments
 (0)