Skip to content

Commit

Permalink
use 'min' for minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
Divkix committed Feb 27, 2023
1 parent c3951c9 commit b424c83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/formatters.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ print(humanbytes_size)
human_time = Formatters.time_formatter(15000)
print(human_time)

# time being in m/h/d/w/m/y.
# time being in s/min/h/d/w/m/y.
# Note: use 'min' for minutes
seconds = Formatters.get_time_in_seconds("2w")
print(seconds)
```
10 changes: 6 additions & 4 deletions pypers/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ def time_formatter(
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
months, days = divmod(days, 30)
tmp = (
((str(days) + "d, ") if days else "")
((str(months) + "m, ") if months else "")
+ ((str(days) + "d, ") if days else "")
+ ((str(hours) + "h, ") if hours else "")
+ ((str(minutes) + "m, ") if minutes else "")
+ ((str(minutes) + "min, ") if minutes else "")
+ ((str(seconds) + "s, ") if seconds else "")
)
return tmp[:-2]
Expand All @@ -59,14 +61,14 @@ def get_time_in_seconds(time: str) -> int:
Convert time in a string format to seconds.
Args:
time: The time in string format with m/h/d/w/m/y.
time: The time in string format with s/min/h/d/w/m/y. Note: use 'min' for minutes.
Returns:
The time in seconds.
"""
times = {
"s": 1,
"m": 60,
"min": 60,
"h": 3600,
"d": 86400,
"w": 604800,
Expand Down

0 comments on commit b424c83

Please sign in to comment.