def format_time(date): return { '12:00AM': 'Midnight', '12:00PM': 'Midday' }.get( gmt_timezones(date).strftime('%-I:%M%p'), gmt_timezones(date).strftime('%-I:%M%p')).lower()
def get_human_day(time): # Add 1 hour to get ‘midnight today’ instead of ‘midnight tomorrow’ time_as_day = (gmt_timezones(time) - timedelta(hours=1)).strftime('%A') six_days_ago = gmt_timezones( (datetime.utcnow() + timedelta(days=-6)).isoformat()) if gmt_timezones(time) < six_days_ago: return format_date_short(time) if time_as_day == (datetime.utcnow() + timedelta(days=1)).strftime('%A'): return 'tomorrow' if time_as_day == datetime.utcnow().strftime('%A'): return 'today' if time_as_day == (datetime.utcnow() + timedelta(days=-1)).strftime('%A'): return 'yesterday' return format_date_short(time)
def format_delta(date): delta = (datetime.now(timezone.utc)) - (gmt_timezones(date)) if delta < timedelta(seconds=30): return "just now" if delta < timedelta(seconds=60): return "in the last minute" return ago.human( delta, future_tense='{} from now', # No-one should ever see this past_tense='{} ago', precision=1)
def get_human_day(time): # Add 1 minute to transform 00:00 into ‘midnight today’ instead of ‘midnight tomorrow’ date = (gmt_timezones(time) - timedelta(minutes=1)).date() if date == (datetime.utcnow() + timedelta(days=1)).date(): return 'tomorrow' if date == datetime.utcnow().date(): return 'today' if date == (datetime.utcnow() - timedelta(days=1)).date(): return 'yesterday' return _format_datetime_short(date)
def present_row(user): logged_in_at = getattr(user, 'logged_in_at', None) if logged_in_at: logged_in_at = gmt_timezones(logged_in_at) return [ user.email_address, getattr(user, 'name', None), # does not exist on invited user getattr(user, 'mobile_number', None), # does not exist on invited user logged_in_at, user.auth_type, ';'.join(user_permissions(user)) ]
def present_row(user): logged_in_at = getattr(user, 'logged_in_at', None) if logged_in_at: logged_in_at = gmt_timezones(logged_in_at) return { "email_address": user.email_address, "name": getattr(user, 'name', None), # does not exist on invited user "mobile_number": getattr(user, 'mobile_number', None), # does not exist on invited user "last_login": logged_in_at, "auth_type": user.auth_type, "permissions": list(user_permissions(user)), }
def format_date_short(date): return _format_datetime_short(gmt_timezones(date))
def format_date_normal(date): return gmt_timezones(date).strftime('%d %B %Y').lstrip('0')
def format_date(date): return gmt_timezones(date).strftime('%A %d %B %Y')
def format_time_24h(date): return gmt_timezones(date).strftime('%H:%M')
def format_date_numeric(date): return gmt_timezones(date).strftime('%Y-%m-%d')
def format_date_short(date): return gmt_timezones(date).strftime('%d %B').lstrip('0')