electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit f971c80d5812b629d00bdd5760a93889a4f6e0ab
parent f40a365186b51331ea4d838618b0a1def15dcb9d
Author: thomasv <thomasv@gitorious>
Date:   Tue, 19 Feb 2013 13:52:18 +0100

use standard indendation in age(), and fix the for loop in it

Diffstat:
Mlib/util.py | 98++++++++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 50 insertions(+), 48 deletions(-)

diff --git a/lib/util.py b/lib/util.py @@ -4,54 +4,7 @@ import shutil from datetime import datetime is_verbose = True -# Takes a timestamp and puts out a string with the approxomation of the age -def age(from_date, since_date = None, target_tz=None, include_seconds=False): - if from_date is None: - return "Unknown" - - from_date = datetime.fromtimestamp(from_date) - if since_date is None: - since_date = datetime.now(target_tz) - - distance_in_time = since_date - from_date - distance_in_seconds = int(round(abs(distance_in_time.days * 86400 + distance_in_time.seconds))) - distance_in_minutes = int(round(distance_in_seconds/60)) - - - if distance_in_minutes <= 1: - if include_seconds: - for remainder in [5, 10, 20]: - if distance_in_seconds < remainder: - return "less than %s seconds ago" % remainder - if distance_in_seconds < 40: - return "half a minute" - elif distance_in_seconds < 60: - return "less than a minute ago" - else: - return "1 minute ago" - else: - if distance_in_minutes == 0: - return "less than a minute ago" - else: - return "1 minute ago" - elif distance_in_minutes < 45: - return "%s minutes ago" % distance_in_minutes - elif distance_in_minutes < 90: - return "about 1 hour ago" - elif distance_in_minutes < 1440: - return "about %d hours ago" % (round(distance_in_minutes / 60.0)) - elif distance_in_minutes < 2880: - return "1 day ago" - elif distance_in_minutes < 43220: - return "%d days ago" % (round(distance_in_minutes / 1440)) - elif distance_in_minutes < 86400: - return "about 1 month ago" - elif distance_in_minutes < 525600: - return "%d months ago" % (round(distance_in_minutes / 43200)) - elif distance_in_minutes < 1051200: - return "about 1 year ago" - else: - return "over %d years ago" % (round(distance_in_minutes / 525600)) + def set_verbosity(b): global is_verbose @@ -138,3 +91,52 @@ def format_satoshis(x, is_diff=False, num_zeros = 0): s += " "*( 9 - ( len(s) - p )) s = " "*( 5 - ( p )) + s return s + + +# Takes a timestamp and returns a string with the approximation of the age +def age(from_date, since_date = None, target_tz=None, include_seconds=False): + if from_date is None: + return "Unknown" + + from_date = datetime.fromtimestamp(from_date) + if since_date is None: + since_date = datetime.now(target_tz) + + distance_in_time = since_date - from_date + distance_in_seconds = int(round(abs(distance_in_time.days * 86400 + distance_in_time.seconds))) + distance_in_minutes = int(round(distance_in_seconds/60)) + + if distance_in_minutes <= 1: + if include_seconds: + for remainder in [5, 10, 20]: + if distance_in_seconds < remainder: + return "less than %s seconds ago" % remainder + if distance_in_seconds < 40: + return "half a minute ago" + elif distance_in_seconds < 60: + return "less than a minute ago" + else: + return "1 minute ago" + else: + if distance_in_minutes == 0: + return "less than a minute ago" + else: + return "1 minute ago" + elif distance_in_minutes < 45: + return "%s minutes ago" % distance_in_minutes + elif distance_in_minutes < 90: + return "about 1 hour ago" + elif distance_in_minutes < 1440: + return "about %d hours ago" % (round(distance_in_minutes / 60.0)) + elif distance_in_minutes < 2880: + return "1 day ago" + elif distance_in_minutes < 43220: + return "%d days ago" % (round(distance_in_minutes / 1440)) + elif distance_in_minutes < 86400: + return "about 1 month ago" + elif distance_in_minutes < 525600: + return "%d months ago" % (round(distance_in_minutes / 43200)) + elif distance_in_minutes < 1051200: + return "about 1 year ago" + else: + return "over %d years ago" % (round(distance_in_minutes / 525600))