Changeset 26220ba in OpenWorkouts-current for ow/utilities.py


Ignore:
Timestamp:
Jan 25, 2019, 12:48:51 AM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
d0fc76b, ed7e9d7
Parents:
c6219ed (diff), 5bdfbfb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge patches from darcs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/utilities.py

    rc6219ed r26220ba  
    33import logging
    44import subprocess
    5 from datetime import datetime
     5from datetime import datetime, timedelta
    66from decimal import Decimal
    77from shutil import copyfileobj
     
    212212
    213213    return False
     214
     215
     216def timedelta_to_hms(value):
     217    """
     218    Return hours, minutes, seconds from a timedelta object
     219    """
     220    hours, remainder = divmod(int(value.total_seconds()), 3600)
     221    minutes, seconds = divmod(remainder, 60)
     222    return hours, minutes, seconds
     223
     224
     225def get_week_days(day, start_day=1):
     226    """
     227    Return a list of datetime objects for the days of the week "day" is in.
     228
     229    day is a datetime object (like in datetime.now() for "today")
     230
     231    start_day can be used to set if week starts on monday (1) or sunday (0)
     232    """
     233    first_day = day - timedelta(days=day.isoweekday() - start_day)
     234    week_days = [first_day + timedelta(days=i) for i in range(7)]
     235    return week_days
Note: See TracChangeset for help on using the changeset viewer.