Skip to main content

A simple library for tracking weekends and working days

Project description

Django_weekend is a Django library that offers a straightforward and adaptable solution for keeping track of weekends and working days. It provides functionality to determine if a particular date falls on a weekend or a working day, making it easy to manage and manipulate dates in Django projects.

Table of contents

Installation

(Back to top)

  • Download and install latest version of django_weekend:
pip install django_weekend
  • Add 'django_weekend' application to the INSTALLED_APPS setting of your Django project settings.py file:
INSTALLED_APPS = (
    ...
    'django_weekend',
)
  • Create database tables:
python manage.py migrate django_weekend

⚠ Attension: By default django_weekend makes all days is working days. You can change this here admin/django_weekend/commonworkingweeksettings/

Setup

(Back to top)

There are three tables for tracking weekends:

  • CommonWorkingWeekSettings is used to store working days
  • ExcludedWeekends is used to store dates of days that are usually weekends but not on the saved date
  • Holidays is used to store holidays dates

First of all, you need to set up you common schedule in CommonWorkingWeekSettings. By default, django_weekend sets up all 7 days as working days. However, you can change it as you want.

NOTE! django_weekend uses the following available days: AVAILABLE_DAYS = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'). Other day names are not available to save.

To add excluded weekends, you can create a new entry in the ExcludedWeekends table. This will allow you to specify dates that are usually weekends but should be treated as working days.

When calculating working days, CommonWorkingWeekSettings will be used as the default schedule. However, if a date is listed in the ExcludedWeekends table, it will be considered a working day regardless of the settings in CommonWorkingWeekSettings.

For adding holidays, you can use the Holidays table. This table will override all other settings and mark the specified dates as holidays.

Usage

(Back to top)

To determine whether a specific date is a weekend or not, you can use the is_weekend_by_date() method provided by the HolidaysWeekendsService class. This method returns a boolean value indicating whether the given date is a weekend or not. Here's an example of how to use it:

After set up all settings you can use this:

from django_weekend.services import HolidaysWeekendsService


result = HolidaysWeekendsService().is_weekend_by_date(date='2023-11-11')

In the above code, date='2023-11-11' is the date for which you want to check if it's a weekend or not. The result variable will contain a boolean value indicating whether the date is a weekend (True) or not (False).

>>result=True

You can also retrieve a list of weekend dates within a specified date range using the get_weekends_by_range() method. To do this, you'll need to import the HolidaysWeekendsService class from the django_weekend.services module.

Here's an example of how to use the get_weekends_by_range() method:

from django_weekend.services import HolidaysWeekendsService

result = HolidaysWeekendsService().get_weekends_by_range(start_date='2023-11-11', end_date='2023-11-15')

In the code above, the start_date parameter is set to '2023-11-11' and the end_date parameter is set to '2023-11-15'. Calling the get_weekends_by_range() method will return a list of weekend dates within that date range.

For example, the result might be:

>>result=['2023-11-11', '2023-11-12']

This means that '2023-11-11' and '2023-11-12' are the weekends within the specified date range.

By utilizing the get_weekends_by_range() method, you can easily obtain a list of weekend dates for a given range in your Django project using the django_weekend library.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_weekend-0.0.6.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_weekend-0.0.6.3-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file django_weekend-0.0.6.3.tar.gz.

File metadata

  • Download URL: django_weekend-0.0.6.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for django_weekend-0.0.6.3.tar.gz
Algorithm Hash digest
SHA256 6779ab538c0a22ff3ff906bb4ffed1ce48710614f46565f25914b27042304b6e
MD5 02ba1d494b8986973ad31085ed15d004
BLAKE2b-256 296f6a8d1ff49c247f35dbf04315dc8f75ad941598a60ab2ac362e1dc2cd6644

See more details on using hashes here.

File details

Details for the file django_weekend-0.0.6.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_weekend-0.0.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c6c21dee5a21c82acc4c624176cb8cb9010f71da47c6b91fd9246b7f566b61dd
MD5 3bc9ad93c60927fa4d854c84db007e91
BLAKE2b-256 09d4fe0f2499b67792b50ea9cc631e8a9ad6b15afd588d04da42245fe1a8b59a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page