Package: django-weekend
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 contentsInstallationSetupUsageInstallation(Back to top)Download and install latest version of django_weekend:pipinstalldjango_weekendAdd 'django_weekend' application to the INSTALLED_APPS setting of your Django project settings.py file:INSTALLED_APPS=(...'django_weekend',)Create database tables:pythonmanage.pymigratedjango_weekend⚠ Attension: By default django_weekend makes all days is working days. You can change this hereadmin/django_weekend/commonworkingweeksettings/Setup(Back to top)There are three tables for tracking weekends:CommonWorkingWeekSettingsis used to store working daysExcludedWeekendsis used to store dates of days that are usually weekends but not on the saved dateHolidaysis used to store holidays datesFirst of all, you need to set up you common schedule inCommonWorkingWeekSettings. 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,CommonWorkingWeekSettingswill be used as the default schedule. However, if a date is listed in theExcludedWeekendstable, it will be considered a working day regardless of the settings inCommonWorkingWeekSettings.For adding holidays, you can use theHolidaystable. 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:fromdjango_weekend.servicesimportHolidaysWeekendsServiceresult=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=TrueYou 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:fromdjango_weekend.servicesimportHolidaysWeekendsServiceresult=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.