[gitg] Move date formatting into Gitg.Date
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Move date formatting into Gitg.Date
- Date: Sat, 6 Jul 2013 13:55:26 +0000 (UTC)
commit ff9df209008df78399b537ebd0ef2f8f06806b8e
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sat Jul 6 15:53:54 2013 +0200
Move date formatting into Gitg.Date
libgitg/gitg-commit.vala | 37 ++++---------------------------------
libgitg/gitg-date.vala | 45 +++++++++++++++++++++++++++++++++++++++++++++
po/POTFILES.in | 2 +-
3 files changed, 50 insertions(+), 34 deletions(-)
---
diff --git a/libgitg/gitg-commit.vala b/libgitg/gitg-commit.vala
index 593d529..fa0b51a 100644
--- a/libgitg/gitg-commit.vala
+++ b/libgitg/gitg-commit.vala
@@ -93,42 +93,12 @@ public class Commit : Ggit.Commit
}
}
- private string date_for_display(DateTime dt)
- {
- TimeSpan t = (new DateTime.now_local()).difference(dt);
-
- if (t < TimeSpan.MINUTE * 29.5)
- {
- int rounded_minutes = (int) Math.round((float) t / TimeSpan.MINUTE);
- return ngettext(_("A minute ago"), _("%d minutes ago"),
rounded_minutes).printf(rounded_minutes);
- }
- else if (t < TimeSpan.MINUTE * 45)
- {
- return _("Half an hour ago");
- }
- else if (t < TimeSpan.HOUR * 23.5)
- {
- int rounded_hours = (int) Math.round((float) t / TimeSpan.HOUR);
- return ngettext(_("An hour ago"), _("%d hours ago"),
rounded_hours).printf(rounded_hours);
- }
- else if (t < TimeSpan.DAY * 7)
- {
- int rounded_days = (int) Math.round((float) t / TimeSpan.DAY);
- return ngettext(_("A day ago"), _("%d days ago"), rounded_days).printf(rounded_days);
- }
- // FIXME: Localize these date formats, Bug 699196
- else if (dt.get_year() == new DateTime.now_local().get_year())
- {
- return dt.format("%h %e, %I:%M %P");
- }
- return dt.format("%h %e %Y, %I:%M %P");
- }
-
public string committer_date_for_display
{
owned get
{
- return date_for_display(get_committer().get_time());
+ var dt = get_committer().get_time();
+ return (new Date.for_date_time(dt)).for_display();
}
}
@@ -136,7 +106,8 @@ public class Commit : Ggit.Commit
{
owned get
{
- return date_for_display(get_author().get_time());
+ var dt = get_author().get_time();
+ return (new Date.for_date_time(dt)).for_display();
}
}
diff --git a/libgitg/gitg-date.vala b/libgitg/gitg-date.vala
index cb65a9c..776632b 100644
--- a/libgitg/gitg-date.vala
+++ b/libgitg/gitg-date.vala
@@ -302,6 +302,51 @@ public class Date : Object, Initable
((Initable)this).init(null);
}
+ public string for_display()
+ {
+ var dt = d_datetime;
+ TimeSpan t = (new DateTime.now_local()).difference(dt);
+
+ if (t < TimeSpan.MINUTE * 29.5)
+ {
+ int rounded_minutes = (int) Math.round((float) t / TimeSpan.MINUTE);
+
+ if (rounded_minutes == 0)
+ {
+ return _("Now");
+ }
+ else
+ {
+ return ngettext(_("A minute ago"), _("%d minutes ago"),
rounded_minutes).printf(rounded_minutes);
+ }
+ }
+ else if (t < TimeSpan.MINUTE * 45)
+ {
+ return _("Half an hour ago");
+ }
+ else if (t < TimeSpan.HOUR * 23.5)
+ {
+ int rounded_hours = (int) Math.round((float) t / TimeSpan.HOUR);
+ return ngettext(_("An hour ago"), _("%d hours ago"),
rounded_hours).printf(rounded_hours);
+ }
+ else if (t < TimeSpan.DAY * 7)
+ {
+ int rounded_days = (int) Math.round((float) t / TimeSpan.DAY);
+ return ngettext(_("A day ago"), _("%d days ago"), rounded_days).printf(rounded_days);
+ }
+ // FIXME: Localize these date formats, Bug 699196
+ else if (dt.get_year() == new DateTime.now_local().get_year())
+ {
+ return dt.format("%h %e, %I:%M %P");
+ }
+ return dt.format("%h %e %Y, %I:%M %P");
+ }
+
+ public Date.for_date_time(DateTime dt)
+ {
+ d_datetime = dt;
+ }
+
public static DateTime parse(string date) throws Error
{
return (new Date(date)).date;
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 537af5a..0a1a416 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,7 +11,7 @@ gitg/history/gitg-history-navigation.vala
gitg/history/gitg-history.vala
gitg/preferences/gitg-preferences-history.vala
gitg/preferences/gitg-preferences-interface.vala
-libgitg/gitg-commit.vala
+libgitg/gitg-date.vala
libgitg/gitg-diff-view.vala
libgitg/gitg-stage.vala
plugins/diff/gitg-diff.vala
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]