Nepali Date API
Project description
Nepali Date (Bikram Sambat B.S) API
The API similar to datetime.date() that works on the BS date instead of AD. Now with NEPALI language support for date display.
Installation
You can install the Nepali Date from PyPI: pip install nepali-date
Usage
B.S Date today
from nepali_date import NepaliDate
print(NepaliDate.today())
print(NepaliDate.today(lang='nep')) # for date in nepali language format
Creating NepaliDate object (instance)
from nepali_date import NepaliDate
new_year_2050 = NepaliDate(2050, 1, 1)
new_year_2051 = NepaliDate('2051', '1', '1')
print(new_year_2050, new_year_2051)
# for date in nepali language
new_year_2052 = NepaliDate(2052, 1, 1, lang='nep')
new_year_2053 = NepaliDate('2053', '1', '1', lang='nep')
print(new_year_2052, new_year_2053)
Adding/Subtracting datetime.timedelta to NepaliDate instance
import datetime
from nepali_date import NepaliDate
new_year_2051 = NepaliDate(2051, 1, 1)
hundred_days_after_new_year_2051 = new_year_2051 + datetime.timedelta(days=100)
hundred_days_before_new_year_2051 = new_year_2051 - datetime.timedelta(days=100)
Converting datetime.date to NepaliDate or vice-versa
import datetime
from nepali_date import NepaliDate
my_birthday_in_ad = datetime.date(1995, 10, 15)
my_birthday_in_bs = NepaliDate.to_nepali_date(my_birthday_in_ad)
my_birthday = NepaliDate(2051, 10, 1)
my_birthday_in_ad = my_birthday.to_english_date()
Monthly Calendar
Current nepali month calendar highlighting today's date
from nepali_date import NepaliDate
NepaliDate.calendar()
Justify the output by providing keyword argument justify
NepaliDate.calendar(justify=50)
Display the calendar in nepali language format by providing keyword argument lang
NepaliDate.calendar(lang='nep')
Date in iso-format ie. 'YYYY-MM-DD'
dt = NepaliDate(2076, 4, 2)
print(dt.isoformat())
dt_nep = NepaliDate(2076, 6, 24, lang='nep')
print(dt_nep.isoformat()) # २०७६-०६-२४
Date display formatting
Format Specifier | Meaning | lang='eng' (default) | lang='nep' |
---|---|---|---|
%a |
Weekday abbreviated name. | Sun , Mon , ..., Sat |
आइत , सोम , ..., शनि |
%A |
Weekday full name. | Sunday , Monday , ..., Saturday |
आइतबार , सोमबार , ..., शनिबार |
%d |
Day of the month as a zero-padded decimal number. | 01 , 02 , ..., 32 |
०१ , ०२ , ..., ३२ |
%b |
Month as abbreviated name. | Bai , Jes , ..., Cha |
बैशाख , जेष्ठ , ..., चैत्र |
%B |
Month as full name. | Baishak , Jestha , ..., Chait |
बैशाख , जेष्ठ , ..., चैत्र |
%m |
Month as a zero-padded decimal number. | 01 , 02 , ..., 12 |
०१ , ०२ , ..., १२ |
%y |
Year without century as a zero-padded decimal number. | 00 , 01 , ..., 99 |
०० , ०१ , ..., ९९ |
%Y |
Year with century as a decimal number. | 1975 , 1976 , ..., 2075 , 2076 , 2077 , 2078 , ..., 2100 |
१९७५ , १९७६ , ..., २०७५ , २०७६ , २०७७ , २०७८ , ..., २१०० |
Format specifier for lang='eng'
dt = NepaliDate(2076, 4, 7)
print("{0:B} {0:d}".format(dt))
Format specifier for lang='nep'
dt = NepaliDate(2076, 4, 7, lang='nep')
print("{0:B} {0:d}".format(dt))
strfdate
Similar API to datetime.datetime.strftime
. NepaliDate to formatted string. Follow the formatting table to know the formatting string.
dt = NepaliDate(2075, 10, 10)
print(dt.strfdate('%Y/%m/%d'))
dt_nep = NepaliDate(2076, 6, 24)
print(dt_nep.strfdate('%Y/%m/%d')) # २०७६/०६/२४
strpdate
Similar API to datetime.datetime.strptime
. Return NepaliDate instance if string and format matches. Follow the formatting table to know the formatting string.
nepali_date = NepaliDate.strpdate('06/20/2076', '%m/%d/%Y')
print(nepali_date, type(nepali_date))
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 nepali-date-2.0.4.tar.gz
.
File metadata
- Download URL: nepali-date-2.0.4.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4cccf9eddb9222504a5be96e53660b0ba678202093942b3e46fb0c164607a5e |
|
MD5 | a3a655f0e8ad09ba83fbfd265e3cefcb |
|
BLAKE2b-256 | d17525e94b98809db34527879c47796347e8e05ccf0540d6c5d3d087c0c340c6 |
File details
Details for the file nepali_date-2.0.4-py3-none-any.whl
.
File metadata
- Download URL: nepali_date-2.0.4-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 030e5da011f91d9a587fbde4666db51eed0768b4ad16d27fc3bcf7b6d09bf434 |
|
MD5 | 28dd21f0b1104961351de1a0f820a6c2 |
|
BLAKE2b-256 | d3395a554256486a8e1559c9a0e4b2e41e6f1f2c8a55b6e81601ab1229b63a49 |