npdatetime 0.1.1__tar.gz → 0.1.2.post2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- npdatetime-0.1.2.post2/.github/workflows/python-publish.yml +54 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/.gitignore +3 -1
- npdatetime-0.1.2.post2/CONTRIBUTING.md +122 -0
- npdatetime-0.1.2.post2/PKG-INFO +273 -0
- npdatetime-0.1.2.post2/README.md +236 -0
- npdatetime-0.1.2.post2/build.sh +41 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/npdatetime/__init__.py +9 -1
- npdatetime-0.1.2.post2/npdatetime/utils.py +9 -0
- npdatetime-0.1.2.post2/npdatetime.egg-info/PKG-INFO +273 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/npdatetime.egg-info/SOURCES.txt +3 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/pyproject.toml +1 -1
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/setup.py +1 -1
- npdatetime-0.1.1/CONTRIBUTING.md +0 -25
- npdatetime-0.1.1/PKG-INFO +0 -180
- npdatetime-0.1.1/README.md +0 -143
- npdatetime-0.1.1/npdatetime.egg-info/PKG-INFO +0 -180
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/.github/workflows/FUNDING.yml +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/.travis.yml +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/LICENSE +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/MANIFEST.in +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/npdatetime/__init__.pyi +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/npdatetime/_custom_strptime.py +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/npdatetime/config.py +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/npdatetime/data/calendar_bs.csv +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/npdatetime.egg-info/dependency_links.txt +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/npdatetime.egg-info/top_level.txt +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/setup.cfg +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/tests/__init__.py +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/tests/conftest.py +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/tests/test_conversions.py +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/tests/test_init.py +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/tests/test_methods.py +0 -0
- {npdatetime-0.1.1 → npdatetime-0.1.2.post2}/tests/test_strftime_strptime.py +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: Upload Python Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
release-build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.9" # Specify a precise Python version
|
|
20
|
+
|
|
21
|
+
- name: Build release distributions
|
|
22
|
+
run: |
|
|
23
|
+
python -m pip install --upgrade pip
|
|
24
|
+
python -m pip install build
|
|
25
|
+
python -m build
|
|
26
|
+
|
|
27
|
+
- name: Upload distributions
|
|
28
|
+
uses: actions/upload-artifact@v4
|
|
29
|
+
with:
|
|
30
|
+
name: release-dists
|
|
31
|
+
path: dist/
|
|
32
|
+
|
|
33
|
+
pypi-publish:
|
|
34
|
+
runs-on: ubuntu-latest
|
|
35
|
+
needs:
|
|
36
|
+
- release-build
|
|
37
|
+
permissions:
|
|
38
|
+
id-token: write
|
|
39
|
+
|
|
40
|
+
environment:
|
|
41
|
+
name: pypi
|
|
42
|
+
|
|
43
|
+
steps:
|
|
44
|
+
- name: Retrieve release distributions
|
|
45
|
+
uses: actions/download-artifact@v4
|
|
46
|
+
with:
|
|
47
|
+
name: release-dists
|
|
48
|
+
path: dist/
|
|
49
|
+
|
|
50
|
+
- name: Publish release distributions to PyPI
|
|
51
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
52
|
+
with:
|
|
53
|
+
packages-dir: dist/
|
|
54
|
+
token: ${{ secrets.PYPI_API_TOKEN }}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# CONTRIBUTING
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to the **npdatetime** project! 🎉
|
|
4
|
+
We welcome contributions that improve functionality, fix bugs, enhance documentation, or add new features. Follow the guidelines below to get started.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Getting Started
|
|
9
|
+
|
|
10
|
+
1. **Fork the Repository**
|
|
11
|
+
Create your own copy of the repository by clicking the "Fork" button on GitHub.
|
|
12
|
+
|
|
13
|
+
2. **Clone Your Fork**
|
|
14
|
+
Clone your forked repository to your local machine:
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/4mritGiri/npdatetime.git
|
|
17
|
+
cd npdatetime
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
3. **Install in Editable Mode**
|
|
21
|
+
Install the package in editable mode to reflect your changes immediately:
|
|
22
|
+
```bash
|
|
23
|
+
pip install -e .
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
4. **Install Development Dependencies**
|
|
27
|
+
Install the necessary tools for testing and formatting:
|
|
28
|
+
```bash
|
|
29
|
+
pip install pytest flake8
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Contribution Workflow
|
|
35
|
+
|
|
36
|
+
### 1. Run Tests
|
|
37
|
+
Before making any changes, ensure all existing tests pass:
|
|
38
|
+
```bash
|
|
39
|
+
pytest
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. Format Your Code
|
|
43
|
+
Check for code formatting issues:
|
|
44
|
+
```bash
|
|
45
|
+
flake8 npdatetime --max-line-length=120
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 3. Create a New Branch
|
|
49
|
+
Create a new branch for your changes based on the `develop` branch:
|
|
50
|
+
```bash
|
|
51
|
+
git checkout develop
|
|
52
|
+
git checkout -b feature/<your-feature-name>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 4. Make Your Changes
|
|
56
|
+
- Write clear, maintainable, and well-documented code.
|
|
57
|
+
- Add tests for new features or bug fixes, if applicable.
|
|
58
|
+
- Address any *TODOs* in the code if relevant.
|
|
59
|
+
|
|
60
|
+
### 5. Verify Your Changes
|
|
61
|
+
Before committing, ensure all tests pass and there are no formatting issues:
|
|
62
|
+
```bash
|
|
63
|
+
pytest
|
|
64
|
+
flake8 npdatetime --max-line-length=120
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 6. Commit Your Changes
|
|
68
|
+
Write descriptive commit messages following this format:
|
|
69
|
+
```bash
|
|
70
|
+
git commit -m "Fix: Correct calculation in npdatetime function"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 7. Push and Open a Pull Request
|
|
74
|
+
Push your changes to your fork and open a Pull Request (PR) against the `develop` branch of the original repository:
|
|
75
|
+
```bash
|
|
76
|
+
git push origin <your-branch-name>
|
|
77
|
+
```
|
|
78
|
+
In your PR:
|
|
79
|
+
- Provide a clear description of the changes made.
|
|
80
|
+
- Reference any related issues or bugs.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Preparing a New Release
|
|
85
|
+
|
|
86
|
+
### 1. Create a Release Branch
|
|
87
|
+
Checkout from the `develop` branch and create a new branch for the release:
|
|
88
|
+
```bash
|
|
89
|
+
git checkout develop
|
|
90
|
+
git checkout -b release/v0.2.2
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 2. Tag the Release
|
|
94
|
+
Use Git tags for versioning:
|
|
95
|
+
```bash
|
|
96
|
+
git tag -a v0.2.2 -m "Release version 0.2.2"
|
|
97
|
+
git push origin --tags
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Additional Notes
|
|
103
|
+
|
|
104
|
+
- **Finding Tasks**: Look for *TODO* comments in the code to identify areas needing attention.
|
|
105
|
+
- **Style Guide**: Follow PEP 8 for Python code formatting.
|
|
106
|
+
- **Communication**: For significant changes, please open an issue to discuss your ideas before submitting a PR.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
**Thank you for contributing to npdatetime!**
|
|
111
|
+
Your efforts help make this project better for everyone. 💪
|
|
112
|
+
If you have any questions, feel free to open an issue or reach out on the project's discussion board.
|
|
113
|
+
|
|
114
|
+
#### 🎉 ***Happy Coding!*** 🎉
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
### Improvements in This Version
|
|
119
|
+
1. Removed redundant steps in the release process to align with Git tag-based versioning.
|
|
120
|
+
2. Simplified and clarified branching instructions.
|
|
121
|
+
3. Organized sections for better readability.
|
|
122
|
+
4. Encouraged contributor engagement with a friendly tone.
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: npdatetime
|
|
3
|
+
Version: 0.1.2.post2
|
|
4
|
+
Summary: A Python package that provides advanced functionality for handling Nepali dates and times, including support for the Bikram Sambat calendar system and Nepal Time (NPT). Ideal for developers working with Nepali date-related applications, offering seamless conversion, manipulation, and formatting of dates and times in the Nepali calendar.
|
|
5
|
+
Home-page: https://github.com/4mritGiri/npdatetime
|
|
6
|
+
Author: Amrit Giri
|
|
7
|
+
Author-email: Amrit Giri <amritgiri02595@gmail.com>
|
|
8
|
+
License: The MIT License (MIT)
|
|
9
|
+
Copyright © 2020 AMRIT GIRI
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the “Software”), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in
|
|
19
|
+
all copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
27
|
+
THE SOFTWARE.
|
|
28
|
+
Project-URL: Homepage, https://github.com/4mritGiri/npdatetime#readme
|
|
29
|
+
Project-URL: Issues, https://github.com/4mritGiri/npdatetime/issues
|
|
30
|
+
Keywords: Nepali Date,Date Conversion,Datetime,Bikram Sambat,Bikram Samvat,nepali,B.S.,BS,bs,b.s,date,NpDateTime,datetime,time,timezone,nepal,bikram,sambat,samvat,nepali-date,nepali-datetime,nepal-time,npt,nepal-timezone,npdatetime,npdt
|
|
31
|
+
Classifier: Programming Language :: Python :: 3
|
|
32
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
33
|
+
Classifier: Operating System :: OS Independent
|
|
34
|
+
Requires-Python: >=3.5
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
License-File: LICENSE
|
|
37
|
+
|
|
38
|
+
# **Nepali Datetime (Bikram Sambat Date & Nepal Time)**
|
|
39
|
+
|
|
40
|
+
A Python library inspired by Python's core `datetime` module, designed specifically for operations based on the **Bikram Sambat (B.S.)** calendar and **Nepal Time (NPT)** timezone (`UTC+05:45`).
|
|
41
|
+
|
|
42
|
+
This library bridges the gap between traditional Nepali dates and modern software development, allowing developers to handle Nepali dates with ease while maintaining compatibility with Python's `datetime`.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## **Key Features**
|
|
47
|
+
|
|
48
|
+
- Full support for Bikram Sambat (B.S.) date operations.
|
|
49
|
+
- Handles Nepal Time (NPT) seamlessly (`UTC+05:45`).
|
|
50
|
+
- Built-in compatibility with Python's `datetime` module.
|
|
51
|
+
- Supports date formatting with Nepali Unicode for localized output.
|
|
52
|
+
- Conversion between Bikram Sambat and Gregorian calendars.
|
|
53
|
+
- Convenient utilities for date parsing, arithmetic, and calendars.
|
|
54
|
+
- Compatible with Python 3.5 and above.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## **Installation**
|
|
59
|
+
|
|
60
|
+
Install the package via `pip`:
|
|
61
|
+
```bash
|
|
62
|
+
pip install npdatetime
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## **Quick Start**
|
|
68
|
+
|
|
69
|
+
Here's how you can use `npdatetime` alongside Python's standard `datetime` module:
|
|
70
|
+
|
|
71
|
+
### **Importing**
|
|
72
|
+
```python
|
|
73
|
+
import datetime
|
|
74
|
+
import npdatetime
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### **Getting Today's Date**
|
|
78
|
+
```python
|
|
79
|
+
# Gregorian date
|
|
80
|
+
datetime.date.today()
|
|
81
|
+
|
|
82
|
+
# Bikram Sambat date
|
|
83
|
+
npdatetime.date.today()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### **Current Date and Time**
|
|
87
|
+
```python
|
|
88
|
+
# Gregorian datetime
|
|
89
|
+
datetime.datetime.now()
|
|
90
|
+
|
|
91
|
+
# Bikram Sambat datetime
|
|
92
|
+
npdatetime.datetime.now()
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## **Key Functionalities**
|
|
98
|
+
|
|
99
|
+
### **Creating Date and Datetime Objects**
|
|
100
|
+
```python
|
|
101
|
+
# Gregorian date
|
|
102
|
+
datetime.date(2020, 9, 4)
|
|
103
|
+
|
|
104
|
+
# Bikram Sambat date
|
|
105
|
+
npdatetime.date(2077, 5, 19)
|
|
106
|
+
|
|
107
|
+
# Gregorian datetime
|
|
108
|
+
datetime.datetime(2020, 9, 4, 8, 26, 10, 123456)
|
|
109
|
+
|
|
110
|
+
# Bikram Sambat datetime
|
|
111
|
+
npdatetime.datetime(2077, 5, 19, 8, 26, 10, 123456)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### **Date Formatting with Localization**
|
|
115
|
+
```python
|
|
116
|
+
# Formatting a Bikram Sambat date
|
|
117
|
+
npdatetime.datetime(2077, 5, 19).strftime("%d %B %Y")
|
|
118
|
+
# Output: 19 Bhadau 2077
|
|
119
|
+
|
|
120
|
+
# Formatting with Nepali Unicode
|
|
121
|
+
npdatetime.date(2077, 10, 25).strftime('%K-%n-%D (%k %N %G)')
|
|
122
|
+
# Output: २०७७-१०-२५ (२५ माघ आइतबार)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### **Parsing Dates from Strings**
|
|
126
|
+
```python
|
|
127
|
+
npdatetime.datetime.strptime('2077-09-12', '%Y-%m-%d')
|
|
128
|
+
# Output: npdatetime.datetime(2077, 9, 12, 0, 0)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### **Timedelta Operations**
|
|
132
|
+
```python
|
|
133
|
+
# Adding days to a date
|
|
134
|
+
npdatetime.date(1990, 5, 10) + datetime.timedelta(days=350)
|
|
135
|
+
# Output: npdatetime.date(1991, 4, 26)
|
|
136
|
+
|
|
137
|
+
# Adding hours and minutes to a datetime
|
|
138
|
+
npdatetime.datetime(1990, 5, 10, 5, 10) + datetime.timedelta(hours=3, minutes=15)
|
|
139
|
+
# Output: npdatetime.datetime(1990, 5, 10, 8, 25)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### **Bikram Sambat <-> Gregorian Conversion**
|
|
143
|
+
```python
|
|
144
|
+
# Convert Bikram Sambat to Gregorian
|
|
145
|
+
npdatetime.date(1999, 7, 25).to_datetime_date()
|
|
146
|
+
# Output: datetime.date(1942, 11, 10)
|
|
147
|
+
|
|
148
|
+
# Convert Gregorian to Bikram Sambat
|
|
149
|
+
npdatetime.date.from_datetime_date(datetime.date(1942, 11, 10))
|
|
150
|
+
# Output: npdatetime.date(1999, 7, 25)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### **Bikram Sambat Monthly Calendar**
|
|
154
|
+
```python
|
|
155
|
+
npdatetime.date(2078, 1, 1).calendar()
|
|
156
|
+
|
|
157
|
+
# Output:
|
|
158
|
+
Baishakh 2078
|
|
159
|
+
Sun Mon Tue Wed Thu Fri Sat
|
|
160
|
+
1 2 3 4
|
|
161
|
+
5 6 7 8 9 10 11
|
|
162
|
+
12 13 14 15 16 17 18
|
|
163
|
+
19 20 21 22 23 24 25
|
|
164
|
+
26 27 28 29 30 31
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## **Fiscal Year Calculations**
|
|
170
|
+
|
|
171
|
+
The **npdatetime** library provides methods to easily calculate the current fiscal year and convert dates to their corresponding fiscal year. Fiscal years in Nepal start from **Shrawan (month 4)** and end at **Ashadh (month 12)**.
|
|
172
|
+
|
|
173
|
+
### **Getting the Current Fiscal Year**
|
|
174
|
+
You can get the current fiscal year using the `current_fiscal_year()` method. It returns the fiscal year as a tuple in the format `(start_year, end_year)`.
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
import npdatetime
|
|
178
|
+
|
|
179
|
+
# Get current fiscal year
|
|
180
|
+
npdatetime.datetime.current_fiscal_year()
|
|
181
|
+
# Output: (2081, 2082)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Alternatively, you can use it directly from the `datetime` class:
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from npdatetime import datetime
|
|
188
|
+
|
|
189
|
+
# Get current fiscal year
|
|
190
|
+
datetime.current_fiscal_year()
|
|
191
|
+
# Output: (2081, 2082)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### **Getting Fiscal Year for a Specific Date**
|
|
195
|
+
You can also calculate the fiscal year for any specific Nepali date using the `get_fiscal_year_by_date()` function. This takes a `datetime` object as input and returns the fiscal year for that date.
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
from npdatetime import get_fiscal_year_by_date
|
|
199
|
+
from npdatetime import datetime
|
|
200
|
+
|
|
201
|
+
# Example date
|
|
202
|
+
date_obj = datetime(2079, 12, 1)
|
|
203
|
+
|
|
204
|
+
# Get fiscal year for a specific date
|
|
205
|
+
get_fiscal_year_by_date(date_obj)
|
|
206
|
+
# Output: (2079, 2080)
|
|
207
|
+
|
|
208
|
+
# You can also directly pass a Nepali datetime object to the function
|
|
209
|
+
get_fiscal_year_by_date(datetime(2080, 4, 1))
|
|
210
|
+
# Output: (2080, 2081)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### **Examples**
|
|
214
|
+
|
|
215
|
+
Here are a few examples of how you can use the `get_fiscal_year_by_date()` method to calculate the fiscal year for various dates:
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
# For 2079-12-01
|
|
219
|
+
get_fiscal_year_by_date(datetime(2079, 12, 1))
|
|
220
|
+
# Output: (2079, 2080)
|
|
221
|
+
|
|
222
|
+
# For 2080-03-01
|
|
223
|
+
get_fiscal_year_by_date(datetime(2080, 3, 1))
|
|
224
|
+
# Output: (2079, 2080)
|
|
225
|
+
|
|
226
|
+
# For 2080-04-01
|
|
227
|
+
get_fiscal_year_by_date(datetime(2080, 4, 1))
|
|
228
|
+
# Output: (2080, 2081)
|
|
229
|
+
|
|
230
|
+
# For 2080-06-01
|
|
231
|
+
get_fiscal_year_by_date(datetime(2080, 6, 1))
|
|
232
|
+
# Output: (2080, 2081)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### **Note**
|
|
236
|
+
- The fiscal year is based on the Nepali date system, which is different from the Gregorian calendar. In Nepal, the fiscal year runs from **Shrawan (month 4)** to **Ashadh (month 12)**.
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## **Documentation**
|
|
241
|
+
|
|
242
|
+
Comprehensive usage examples and detailed documentation can be found on the [official website](https://4mritGiri.github.io/npdatetime/).
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## **Contributing**
|
|
247
|
+
|
|
248
|
+
We welcome contributions! If you'd like to contribute, check out the [CONTRIBUTING.md](https://github.com/4mritGiri/npdatetime/blob/master/CONTRIBUTING.md) guide for details on how to get started.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## **License**
|
|
253
|
+
|
|
254
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## **Feedback & Support**
|
|
259
|
+
|
|
260
|
+
For feature requests, bug reports, or feedback, please create an issue on the [GitHub repository](https://github.com/4mritGiri/npdatetime/issues).
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
### 🌟 **Made for Developers, by Developers** 🌟
|
|
265
|
+
Your feedback and support are invaluable in making **npdatetime** the go-to library for working with Nepali dates. Thank you! 🙌
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
### **Improvements in This Version**
|
|
270
|
+
1. Enhanced structure with logical sections for better readability.
|
|
271
|
+
2. Highlighted key functionalities for quick reference.
|
|
272
|
+
3. Added friendly language to engage contributors and users.
|
|
273
|
+
4. Updated examples to be more illustrative and user-friendly.
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# **Nepali Datetime (Bikram Sambat Date & Nepal Time)**
|
|
2
|
+
|
|
3
|
+
A Python library inspired by Python's core `datetime` module, designed specifically for operations based on the **Bikram Sambat (B.S.)** calendar and **Nepal Time (NPT)** timezone (`UTC+05:45`).
|
|
4
|
+
|
|
5
|
+
This library bridges the gap between traditional Nepali dates and modern software development, allowing developers to handle Nepali dates with ease while maintaining compatibility with Python's `datetime`.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## **Key Features**
|
|
10
|
+
|
|
11
|
+
- Full support for Bikram Sambat (B.S.) date operations.
|
|
12
|
+
- Handles Nepal Time (NPT) seamlessly (`UTC+05:45`).
|
|
13
|
+
- Built-in compatibility with Python's `datetime` module.
|
|
14
|
+
- Supports date formatting with Nepali Unicode for localized output.
|
|
15
|
+
- Conversion between Bikram Sambat and Gregorian calendars.
|
|
16
|
+
- Convenient utilities for date parsing, arithmetic, and calendars.
|
|
17
|
+
- Compatible with Python 3.5 and above.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## **Installation**
|
|
22
|
+
|
|
23
|
+
Install the package via `pip`:
|
|
24
|
+
```bash
|
|
25
|
+
pip install npdatetime
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## **Quick Start**
|
|
31
|
+
|
|
32
|
+
Here's how you can use `npdatetime` alongside Python's standard `datetime` module:
|
|
33
|
+
|
|
34
|
+
### **Importing**
|
|
35
|
+
```python
|
|
36
|
+
import datetime
|
|
37
|
+
import npdatetime
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### **Getting Today's Date**
|
|
41
|
+
```python
|
|
42
|
+
# Gregorian date
|
|
43
|
+
datetime.date.today()
|
|
44
|
+
|
|
45
|
+
# Bikram Sambat date
|
|
46
|
+
npdatetime.date.today()
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### **Current Date and Time**
|
|
50
|
+
```python
|
|
51
|
+
# Gregorian datetime
|
|
52
|
+
datetime.datetime.now()
|
|
53
|
+
|
|
54
|
+
# Bikram Sambat datetime
|
|
55
|
+
npdatetime.datetime.now()
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## **Key Functionalities**
|
|
61
|
+
|
|
62
|
+
### **Creating Date and Datetime Objects**
|
|
63
|
+
```python
|
|
64
|
+
# Gregorian date
|
|
65
|
+
datetime.date(2020, 9, 4)
|
|
66
|
+
|
|
67
|
+
# Bikram Sambat date
|
|
68
|
+
npdatetime.date(2077, 5, 19)
|
|
69
|
+
|
|
70
|
+
# Gregorian datetime
|
|
71
|
+
datetime.datetime(2020, 9, 4, 8, 26, 10, 123456)
|
|
72
|
+
|
|
73
|
+
# Bikram Sambat datetime
|
|
74
|
+
npdatetime.datetime(2077, 5, 19, 8, 26, 10, 123456)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### **Date Formatting with Localization**
|
|
78
|
+
```python
|
|
79
|
+
# Formatting a Bikram Sambat date
|
|
80
|
+
npdatetime.datetime(2077, 5, 19).strftime("%d %B %Y")
|
|
81
|
+
# Output: 19 Bhadau 2077
|
|
82
|
+
|
|
83
|
+
# Formatting with Nepali Unicode
|
|
84
|
+
npdatetime.date(2077, 10, 25).strftime('%K-%n-%D (%k %N %G)')
|
|
85
|
+
# Output: २०७७-१०-२५ (२५ माघ आइतबार)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### **Parsing Dates from Strings**
|
|
89
|
+
```python
|
|
90
|
+
npdatetime.datetime.strptime('2077-09-12', '%Y-%m-%d')
|
|
91
|
+
# Output: npdatetime.datetime(2077, 9, 12, 0, 0)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### **Timedelta Operations**
|
|
95
|
+
```python
|
|
96
|
+
# Adding days to a date
|
|
97
|
+
npdatetime.date(1990, 5, 10) + datetime.timedelta(days=350)
|
|
98
|
+
# Output: npdatetime.date(1991, 4, 26)
|
|
99
|
+
|
|
100
|
+
# Adding hours and minutes to a datetime
|
|
101
|
+
npdatetime.datetime(1990, 5, 10, 5, 10) + datetime.timedelta(hours=3, minutes=15)
|
|
102
|
+
# Output: npdatetime.datetime(1990, 5, 10, 8, 25)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### **Bikram Sambat <-> Gregorian Conversion**
|
|
106
|
+
```python
|
|
107
|
+
# Convert Bikram Sambat to Gregorian
|
|
108
|
+
npdatetime.date(1999, 7, 25).to_datetime_date()
|
|
109
|
+
# Output: datetime.date(1942, 11, 10)
|
|
110
|
+
|
|
111
|
+
# Convert Gregorian to Bikram Sambat
|
|
112
|
+
npdatetime.date.from_datetime_date(datetime.date(1942, 11, 10))
|
|
113
|
+
# Output: npdatetime.date(1999, 7, 25)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### **Bikram Sambat Monthly Calendar**
|
|
117
|
+
```python
|
|
118
|
+
npdatetime.date(2078, 1, 1).calendar()
|
|
119
|
+
|
|
120
|
+
# Output:
|
|
121
|
+
Baishakh 2078
|
|
122
|
+
Sun Mon Tue Wed Thu Fri Sat
|
|
123
|
+
1 2 3 4
|
|
124
|
+
5 6 7 8 9 10 11
|
|
125
|
+
12 13 14 15 16 17 18
|
|
126
|
+
19 20 21 22 23 24 25
|
|
127
|
+
26 27 28 29 30 31
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## **Fiscal Year Calculations**
|
|
133
|
+
|
|
134
|
+
The **npdatetime** library provides methods to easily calculate the current fiscal year and convert dates to their corresponding fiscal year. Fiscal years in Nepal start from **Shrawan (month 4)** and end at **Ashadh (month 12)**.
|
|
135
|
+
|
|
136
|
+
### **Getting the Current Fiscal Year**
|
|
137
|
+
You can get the current fiscal year using the `current_fiscal_year()` method. It returns the fiscal year as a tuple in the format `(start_year, end_year)`.
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
import npdatetime
|
|
141
|
+
|
|
142
|
+
# Get current fiscal year
|
|
143
|
+
npdatetime.datetime.current_fiscal_year()
|
|
144
|
+
# Output: (2081, 2082)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Alternatively, you can use it directly from the `datetime` class:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from npdatetime import datetime
|
|
151
|
+
|
|
152
|
+
# Get current fiscal year
|
|
153
|
+
datetime.current_fiscal_year()
|
|
154
|
+
# Output: (2081, 2082)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### **Getting Fiscal Year for a Specific Date**
|
|
158
|
+
You can also calculate the fiscal year for any specific Nepali date using the `get_fiscal_year_by_date()` function. This takes a `datetime` object as input and returns the fiscal year for that date.
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from npdatetime import get_fiscal_year_by_date
|
|
162
|
+
from npdatetime import datetime
|
|
163
|
+
|
|
164
|
+
# Example date
|
|
165
|
+
date_obj = datetime(2079, 12, 1)
|
|
166
|
+
|
|
167
|
+
# Get fiscal year for a specific date
|
|
168
|
+
get_fiscal_year_by_date(date_obj)
|
|
169
|
+
# Output: (2079, 2080)
|
|
170
|
+
|
|
171
|
+
# You can also directly pass a Nepali datetime object to the function
|
|
172
|
+
get_fiscal_year_by_date(datetime(2080, 4, 1))
|
|
173
|
+
# Output: (2080, 2081)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### **Examples**
|
|
177
|
+
|
|
178
|
+
Here are a few examples of how you can use the `get_fiscal_year_by_date()` method to calculate the fiscal year for various dates:
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
# For 2079-12-01
|
|
182
|
+
get_fiscal_year_by_date(datetime(2079, 12, 1))
|
|
183
|
+
# Output: (2079, 2080)
|
|
184
|
+
|
|
185
|
+
# For 2080-03-01
|
|
186
|
+
get_fiscal_year_by_date(datetime(2080, 3, 1))
|
|
187
|
+
# Output: (2079, 2080)
|
|
188
|
+
|
|
189
|
+
# For 2080-04-01
|
|
190
|
+
get_fiscal_year_by_date(datetime(2080, 4, 1))
|
|
191
|
+
# Output: (2080, 2081)
|
|
192
|
+
|
|
193
|
+
# For 2080-06-01
|
|
194
|
+
get_fiscal_year_by_date(datetime(2080, 6, 1))
|
|
195
|
+
# Output: (2080, 2081)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### **Note**
|
|
199
|
+
- The fiscal year is based on the Nepali date system, which is different from the Gregorian calendar. In Nepal, the fiscal year runs from **Shrawan (month 4)** to **Ashadh (month 12)**.
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## **Documentation**
|
|
204
|
+
|
|
205
|
+
Comprehensive usage examples and detailed documentation can be found on the [official website](https://4mritGiri.github.io/npdatetime/).
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## **Contributing**
|
|
210
|
+
|
|
211
|
+
We welcome contributions! If you'd like to contribute, check out the [CONTRIBUTING.md](https://github.com/4mritGiri/npdatetime/blob/master/CONTRIBUTING.md) guide for details on how to get started.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## **License**
|
|
216
|
+
|
|
217
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## **Feedback & Support**
|
|
222
|
+
|
|
223
|
+
For feature requests, bug reports, or feedback, please create an issue on the [GitHub repository](https://github.com/4mritGiri/npdatetime/issues).
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
### 🌟 **Made for Developers, by Developers** 🌟
|
|
228
|
+
Your feedback and support are invaluable in making **npdatetime** the go-to library for working with Nepali dates. Thank you! 🙌
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
### **Improvements in This Version**
|
|
233
|
+
1. Enhanced structure with logical sections for better readability.
|
|
234
|
+
2. Highlighted key functionalities for quick reference.
|
|
235
|
+
3. Added friendly language to engage contributors and users.
|
|
236
|
+
4. Updated examples to be more illustrative and user-friendly.
|