Skip to main content

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()

Screenshot

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


Download files

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

Source Distribution

nepali-date-2.0.4.tar.gz (10.3 kB view hashes)

Uploaded Source

Built Distribution

nepali_date-2.0.4-py3-none-any.whl (8.7 kB view hashes)

Uploaded Python 3

Supported by

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