Simple and lightweight calendar support for python datetime.date
Project description
calendar-util
Simple calendar support for python datetime.date
Setup
- Install via pip (
pip install calendarutil
) - or via git (
git clone "https://github.com/github-suraj/calendar-util"
)
Usage : 1 : get date on a particular day of month
1. Get first Monday of month
In this module, all the methods take input arguments as year
and month
.
>>> from calendarutil.month import util
>>> util.first_monday_of_month(2021, 4)
datetime.date(2021, 4, 5)
2. Get list of first Monday of month for a year
In this module, all the methods take input argument as year
.
>>> from calendarutil.month import from_year
>>> from_year.first_monday_of_month(2021)
[datetime.date(2021, 1, 4), datetime.date(2021, 2, 1), datetime.date(2021, 3, 1), datetime.date(2021, 4, 5), datetime.date(2021, 5, 3), datetime.date(2021, 6, 7), datetime.date(2021, 7, 5), datetime.date(2021, 8, 2), datetime.date(2021, 9, 6), datetime.date(2021, 10, 4), datetime.date(2021,
11, 1), datetime.date(2021, 12, 6)]
3. Get list of first Monday of month for a date range
In this module, all the methods take input arguments as date object
for start
and end
date.
>>> from datetime import date
>>> from calendarutil.month import from_range
>>> dt1 = date(2021, 3, 1)
>>> dt2 = date(2021, 9, 1)
>>> from_range.first_monday_of_month(dt1, dt2)
[datetime.date(2021, 3, 1), datetime.date(2021, 4, 5), datetime.date(2021, 5, 3), datetime.date(2021, 6, 7), datetime.date(2021, 7, 5), datetime.date(2021, 8, 2), datetime.date(2021, 9, 6)]
Supported frequency
- first
- second
- third
- fourth
- last
Supported weekday
- monday
- tuesday
- wednesday
- thursday
- friday
- saturday
- sunday
Usage : 2 : get date on first/last day/weekday of month
In this module, all the methods take input arguments as year
and month
.
1. Get first day of month
>>> from calendarutil.month import first_day_of_month
>>> first_day_of_month(2021, 5)
datetime.date(2021, 5, 1)
2. Get first weekday of month
>>> from calendarutil.month import first_weekday_of_month
>>> first_weekday_of_month(2021, 5)
datetime.date(2021, 5, 3)
3. Get last day of month
>>> from calendarutil.month import last_day_of_month
>>> last_day_of_month(2021, 2)
datetime.date(2021, 2, 28)
4. Get last weekday of month
>>> from calendarutil.month import last_weekday_of_month
>>> last_weekday_of_month(2021, 2)
datetime.date(2021, 2, 26)
Usage : 3 : get date on first/last day/weekday of quarter
In this module, all the methods take input arguments as year
and quarter number
.
1. Get first day of quarter
>>> from calendarutil.quarter import first_day_of_quarter
>>> first_day_of_quarter(2022, 1)
datetime.date(2022, 1, 1)
2. Get first weekday of quarter
>>> from calendarutil.quarter import first_weekday_of_quarter
>>> first_weekday_of_quarter(2022, 1)
datetime.date(2022, 1, 3)
3. Get last day of quarter
>>> from calendarutil.quarter import last_day_of_quarter
>>> last_day_of_quarter(2022, 4)
datetime.date(2022, 12, 31)
4. Get last weekday of quarter
>>> from calendarutil.quarter import last_weekday_of_quarter
>>> last_weekday_of_quarter(2022, 4)
datetime.date(2022, 12, 30)
Show your Support
Give us a :star2: if this project helped you!
License
Copyright © 2021 Suraj Jaiswal
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file calendarutil-2021.4.1.tar.gz
.
File metadata
- Download URL: calendarutil-2021.4.1.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c74866be0ff30c0eef50bffdb469817ba9ed2dfbc621371f443c8d1b4513b4f1 |
|
MD5 | a27eac907eb8c8f1c798df8fbb616f3f |
|
BLAKE2b-256 | 727886d3478f672d2af4fca548fdf060d5dc508e5bc9d53d6c1681f507258cb6 |
File details
Details for the file calendarutil-2021.4.1-py3-none-any.whl
.
File metadata
- Download URL: calendarutil-2021.4.1-py3-none-any.whl
- Upload date:
- Size: 21.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b247855ff01e36c8be3d356c1cf494738aa50a9f57e5c7470237640431b9e6f6 |
|
MD5 | 522be9b79cf7f17ec04ccec13a40b871 |
|
BLAKE2b-256 | 26542431a49d7a919dd3449ae4edddfc89011850ec9919aa9fda9c12d63fd214 |