[polari] utils: Move formatTimePassed() from UserList
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] utils: Move formatTimePassed() from UserList
- Date: Mon, 8 Jun 2020 18:31:39 +0000 (UTC)
commit 6917565c807a380930b39091db49ca28b86c41bc
Author: Roberto Sánchez Fernández <robertosanchez_9 hotmail com>
Date: Tue Mar 24 17:03:44 2020 +0100
utils: Move formatTimePassed() from UserList
It will be used elsewhere to implement the WHOIS command.
https://gitlab.gnome.org/GNOME/polari/-/merge_requests/152
src/userList.js | 45 +++------------------------------------------
src/utils.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 53 insertions(+), 43 deletions(-)
---
diff --git a/src/userList.js b/src/userList.js
index d439f8f3..ea320eab 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -4,6 +4,8 @@ const {
Gio, GLib, GObject, Gtk, Pango, Polari, TelepathyGLib: Tp,
} = imports.gi;
+const Utils = imports.utils;
+
const FILTER_ENTRY_THRESHOLD = 8;
const MAX_USERS_WIDTH_CHARS = 17;
@@ -250,47 +252,6 @@ var UserDetails = GObject.registerClass({
this._cancellable = null;
}
- _formatLast(seconds) {
- if (seconds < 60) {
- return ngettext(
- '%d second ago',
- '%d seconds ago', seconds).format(seconds);
- }
-
- let minutes = seconds / 60;
- if (minutes < 60) {
- return ngettext(
- '%d minute ago',
- '%d minutes ago', minutes).format(minutes);
- }
-
- let hours = minutes / 60;
- if (hours < 24) {
- return ngettext(
- '%d hour ago',
- '%d hours ago', hours).format(hours);
- }
-
- let days = hours / 24;
- if (days < 7) {
- return ngettext(
- '%d day ago',
- '%d days ago', days).format(days);
- }
-
- let weeks = days / 7;
- if (days < 30) {
- return ngettext(
- '%d week ago',
- '%d weeks ago', weeks).format(weeks);
- }
-
- let months = days / 30;
- return ngettext(
- '%d month ago',
- '%d months ago', months).format(months);
- }
-
_onContactInfoReady() {
this._initialDetailsLoaded = true;
@@ -309,7 +270,7 @@ var UserDetails = GObject.registerClass({
this._fullnameLabel.label = fn;
if (last) {
- this._lastLabel.label = this._formatLast(last);
+ this._lastLabel.label = Utils.formatTimePassed(last);
this._lastLabel.show();
} else {
this._lastLabel.hide();
diff --git a/src/utils.js b/src/utils.js
index 4931024f..90c7880c 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -2,7 +2,9 @@
findUrls findChannels openURL updateTerms gpaste imgurPaste
storeAccountPassword storeIdentifyPassword
lookupAccountPassword lookupIdentifyPassword
- clearAccountPassword clearIdentifyPassword */
+ clearAccountPassword clearIdentifyPassword
+ updateTerms gpaste imgurPaste formatTimePassed*/
+
/*
* Copyright (c) 2011 Red Hat, Inc.
*
@@ -364,3 +366,50 @@ function imgurPaste(pixbuf, title, callback) {
callback(null);
});
}
+
+function formatTimePassed(seconds) {
+ if (seconds === 0)
+ return _('Now');
+
+ if (!seconds)
+ return _('Unavailable');
+
+ if (seconds < 60) {
+ return ngettext(
+ '%d second ago',
+ '%d seconds ago', seconds).format(seconds);
+ }
+
+ let minutes = seconds / 60;
+ if (minutes < 60) {
+ return ngettext(
+ '%d minute ago',
+ '%d minutes ago', minutes).format(minutes);
+ }
+
+ let hours = minutes / 60;
+ if (hours < 24) {
+ return ngettext(
+ '%d hour ago',
+ '%d hours ago', hours).format(hours);
+ }
+
+ let days = hours / 24;
+ if (days < 7) {
+ return ngettext(
+ '%d day ago',
+ '%d days ago', days).format(days);
+ }
+
+ let weeks = days / 7;
+ if (days < 30) {
+ return ngettext(
+ '%d week ago',
+ '%d weeks ago', weeks).format(weeks);
+ }
+
+ let months = days / 30;
+ return ngettext(
+ '%d month ago',
+ '%d months ago', months).format(months);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]