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 for lang=eng

Format Specifier Meaning lang='eng' (default) lang='nep'
%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 १९७५, १९७६, ..., २०७५, २०७६, २०७७, २०७८, ..., २१००
dt = NepaliDate(2076, 4, 7)
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.1.tar.gz (9.3 kB view details)

Uploaded Source

File details

Details for the file nepali-date-2.0.1.tar.gz.

File metadata

  • Download URL: nepali-date-2.0.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for nepali-date-2.0.1.tar.gz
Algorithm Hash digest
SHA256 86052ce8d9cb1c1790ff3a7e422579436d5dc3f18b46bcd614996dad5da9a640
MD5 9430de990326350d5004191755ca9e5b
BLAKE2b-256 5dbefba0c466a2fd08023e97af9c03f76da5cb8ab8c90794513c26ae4156bc4a

See more details on using hashes here.

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