Skip to content

Commit d1f2a2a

Browse files
authored
Make sure newly created pastes are displayed as "now". (#48)
1 parent 9a02d2b commit d1f2a2a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

core/utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ def validate_discord_token(token: str) -> bool:
100100
else:
101101
return True
102102

103+
103104
def pluralize(count: int, singular: str) -> str:
104105
return singular if count == 1 else singular + "s"
105106

107+
106108
def natural_time(
107109
td: datetime.timedelta,
108110
/,
@@ -114,8 +116,13 @@ def natural_time(
114116
then = now - td
115117
future = then > now
116118

117-
ago = "{delta} from now" if future else "{delta} ago"
118119
seconds = round(td.total_seconds())
120+
121+
if seconds < 60 and not future:
122+
return "now"
123+
124+
ago = "{delta} from now" if future else "{delta} ago"
125+
119126
years, seconds = divmod(seconds, 60 * 60 * 24 * 365)
120127
months, seconds = divmod(seconds, 60 * 60 * 24 * 30)
121128
weeks, seconds = divmod(seconds, 60 * 60 * 24 * 7)
@@ -142,14 +149,7 @@ def natural_time(
142149
if ret:
143150
ret += ", "
144151
ret += f"{hours} {pluralize(hours, 'hour')}"
145-
if (
146-
minutes
147-
and not years
148-
and not months
149-
and not weeks
150-
and not days
151-
and not hours
152-
):
152+
if minutes and not years and not months and not weeks and not days and not hours:
153153
if ret:
154154
ret += ", "
155155
ret += f"{minutes} {pluralize(minutes, 'minute')}"

0 commit comments

Comments
 (0)