1
|
|
|
# Copyright (c) 2017 CorpNewt |
2
|
|
|
# |
3
|
|
|
# This software is released under the MIT License. |
4
|
|
|
# https://opensource.org/licenses/MIT |
5
|
|
|
|
6
|
|
|
def getReadableTimeBetween(first, last): |
7
|
|
|
# A helper function to make a readable string between two times |
8
|
|
|
timeBetween = int(last - first) |
9
|
|
|
weeks = int(timeBetween / 604800) |
10
|
|
|
days = int((timeBetween - (weeks * 604800)) / 86400) |
11
|
|
|
hours = int((timeBetween - (days * 86400 + weeks * 604800)) / 3600) |
12
|
|
|
minutes = int((timeBetween - (hours * 3600 + days * 86400 + weeks * 604800)) / 60) |
13
|
|
|
seconds = int(timeBetween - (minutes * 60 + hours * 3600 + days * 86400 + weeks * 604800)) |
14
|
|
|
msg = "" |
15
|
|
|
|
16
|
|
|
if weeks > 0: |
17
|
|
|
if weeks == 1: |
18
|
|
|
msg = '{}{} week, '.format(msg, str(weeks)) |
19
|
|
|
else: |
20
|
|
|
msg = '{}{} weeks, '.format(msg, str(weeks)) |
21
|
|
|
if days > 0: |
22
|
|
|
if days == 1: |
23
|
|
|
msg = '{}{} day, '.format(msg, str(days)) |
24
|
|
|
else: |
25
|
|
|
msg = '{}{} days, '.format(msg, str(days)) |
26
|
|
|
if hours > 0: |
27
|
|
|
if hours == 1: |
28
|
|
|
msg = '{}{} hour, '.format(msg, str(hours)) |
29
|
|
|
else: |
30
|
|
|
msg = '{}{} hours, '.format(msg, str(hours)) |
31
|
|
|
if minutes > 0: |
32
|
|
|
if minutes == 1: |
33
|
|
|
msg = '{}{} minute, '.format(msg, str(minutes)) |
34
|
|
|
else: |
35
|
|
|
msg = '{}{} minutes, '.format(msg, str(minutes)) |
36
|
|
|
if seconds > 0: |
37
|
|
|
if seconds == 1: |
38
|
|
|
msg = '{}{} second, '.format(msg, str(seconds)) |
39
|
|
|
else: |
40
|
|
|
msg = '{}{} seconds, '.format(msg, str(seconds)) |
41
|
|
|
|
42
|
|
|
if not msg: |
43
|
|
|
return "0 seconds" |
44
|
|
|
else: |
45
|
|
|
return msg[:-2] |