Commit 1c9bce43 authored by Guido Gunther's avatar Guido Gunther Committed by Sebastian Krzyszkowiak

timestamp-label: Unbreak relative years

So far there always was fallback, drop that.
Signed-off-by: Guido Gunther's avatarGuido Günther <guido.gunther@puri.sm>
parent 544e97bf
......@@ -44,6 +44,9 @@ G_DEFINE_TYPE (PhoshTimestampLabel, phosh_timestamp_label, GTK_TYPE_LABEL)
#define SECONDS_PER_DAY 86400.0
#define SECONDS_PER_MONTH 2592000.0
#define SECONDS_PER_YEAR 31536000.0
#define MINUTES_PER_DAY 1440.0
#define MINUTES_PER_YEAR 525600.0
#define MINUTES_PER_QUARTER 131400.0
/**
* phosh_time_diff_in_words:
......@@ -73,8 +76,6 @@ phosh_time_diff_in_words (GDateTime *dt, GDateTime *dt_now)
int number, seconds, minutes, hours, days, months, years, offset, remainder;
gboolean show_date = FALSE;
double dist_in_seconds;
str_about = "~";
......@@ -181,30 +182,25 @@ phosh_time_diff_in_words (GDateTime *dt, GDateTime *dt_now)
unit = (number == 1) ? str_year : str_years;
offset = (int)((float)years / 4.0) * 1440.0;
offset = ((float)years / 4.0) * MINUTES_PER_DAY;
remainder = (minutes - offset) % 525600;
show_date = TRUE;
remainder = (minutes - offset) % (int)MINUTES_PER_YEAR;
if (remainder < 131400) {
if (remainder < MINUTES_PER_QUARTER) {
prefix = str_about;
} else if (remainder < 394200) {
} else if (remainder < (3 * MINUTES_PER_QUARTER)) {
/* Translators: Timestamp prefix (e.g. Over 5h) */
prefix = _("Over");
prefix = _("Over ");
} else {
++number;
unit = str_years;
/* Translators: Timestamp prefix (e.g. Almost 5h) */
prefix = _("Almost");
prefix = _("Almost ");
}
break;
}
if (show_date) {
return g_strdup (fallback);
} else {
return prefix ? g_strdup_printf ("%s%d%s", prefix, number, unit) : g_strdup(_("now"));
}
return prefix ? g_strdup_printf ("%s%d%s", prefix, number, unit) : g_strdup(_("now"));
}
/**
......
......@@ -129,7 +129,22 @@ test_phosh_time_diff_in_words (void)
g_date_time_unref (dt);
dt = g_date_time_new_local (2019, 12, 31, 21, 00, 00);
str = phosh_time_diff_in_words (dt, dt_now);
g_assert_cmpstr (str, ==, "12/31/19");
g_assert_cmpstr (str, ==, "~1y");
g_date_time_unref (dt);
dt = g_date_time_new_local (2019, 3, 30, 21, 00, 00);
str = phosh_time_diff_in_words (dt, dt_now);
g_assert_cmpstr (str, ==, "Almost 2y");
g_date_time_unref (dt);
dt = g_date_time_new_local (2018, 12, 31, 21, 00, 00);
str = phosh_time_diff_in_words (dt, dt_now);
g_assert_cmpstr (str, ==, "~2y");
g_date_time_unref (dt);
dt = g_date_time_new_local (2018, 6, 30, 21, 00, 00);
str = phosh_time_diff_in_words (dt, dt_now);
g_assert_cmpstr (str, ==, "Over 2y");
/* Restore previous locale */
uselocale (save_locale);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment