from files.helpers.lazy import lazy import math import random import time class Stndrd: @property @lazy def created_date(self): return time.strftime("%d %B %Y", time.gmtime(self.created_utc)) @property @lazy def created_datetime(self): return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) class Age_times: @property def age(self): now = int(time.time()) return now - self.created_utc @property def created_date(self): return time.strftime("%d %b %Y", time.gmtime(self.created_utc)) @property def created_datetime(self): return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) @property def age_string(self): age = self.age if age < 60: return "just now" elif age < 3600: minutes = int(age / 60) return f"{minutes}m ago" elif age < 86400: hours = int(age / 3600) return f"{hours}hr ago" elif age < 2678400: days = int(age / 86400) return f"{days}d ago" now = time.gmtime() ctd = time.gmtime(self.created_utc) # compute number of months months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year) # remove a month count if current day of month < creation day of month if now.tm_mday < ctd.tm_mday: months -= 1 if months < 12: return f"{months}mo ago" else: years = int(months / 12) return f"{years}yr ago" @property def edited_string(self): if not self.edited_utc: return "never" age = int(time.time()) - self.edited_utc if age < 60: return "just now" elif age < 3600: minutes = int(age / 60) return f"{minutes}m ago" elif age < 86400: hours = int(age / 3600) return f"{hours}hr ago" elif age < 2678400: days = int(age / 86400) return f"{days}d ago" now = time.gmtime() ctd = time.gmtime(self.edited_utc) months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year) if months < 12: return f"{months}mo ago" else: years = now.tm_year - ctd.tm_year return f"{years}yr ago" @property def edited_date(self): return time.strftime("%d %B %Y", time.gmtime(self.edited_utc)) @property def edited_datetime(self): return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.edited_utc)))