Changeset 9ab0fe3 in OpenWorkouts-current for ow/utilities.py


Ignore:
Timestamp:
Feb 4, 2019, 12:29:21 PM (5 years ago)
Author:
borja <borja@…>
Branches:
current, feature/docs, master
Children:
1d2acd4
Parents:
dbfab70
Message:

Added method to return the number of week a given day is (1, 2, 3, etc),

relative to the month the day is in.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/utilities.py

    rdbfab70 r9ab0fe3  
    22import os
    33import logging
     4import calendar
    45import subprocess
    56from datetime import datetime, timedelta
     
    234235    week_days = [first_day + timedelta(days=i) for i in range(7)]
    235236    return week_days
     237
     238
     239def get_month_week_number(day):
     240    """
     241    Given a datetime object (day), return the number of week the day is
     242    in the current month (week 1, 2, 3, etc)
     243    """
     244    weeks = calendar.monthcalendar(day.year, day.month)
     245    for week in weeks:
     246        if day.day in week:
     247            return weeks.index(week)
     248    return None
Note: See TracChangeset for help on using the changeset viewer.