Skip to main content

nepalidatetime compatible with python's datetime feature. Converting nepali date to english, parsing nepali datetime, nepali timezone, and timedelta support in nepali datetime

Project description

Nepali

Python package for converting nepali date time to python's datetime easily. Also supports parsing and timezone features.

Requirements

Python >= 3

Installation

pip install nepali

Features

  1. Nepali datetime support
  2. Parse nepali datetime
  3. Nepali Characters (Months, Days, etc)
  4. Number to nepali numbers and nepali numbers to english.

nepalidate

Represents nepali date, converts English date to nepali date and nepali date to english date

from nepali.datetime import nepalidate  

Creating new object

# object with current date
np_date = nepalidate(year, month, day)

# object with today's date
np_date = nepalidate.today()

# parse date
np_date = nepalidate.strptime('2078-01-12', format='%Y-%m-%d')

Object from python's datetime.date

import datetime

date = datetime.date.today()
np_date = nepalidate.from_date(date)

Get python's datetime.date object

np_date.to_date()

Get python's datetime.datetime object

np_date.to_datetime()

nepalidatetime

Represents nepali date time

from nepali.datetime import nepalidatetime  

Creating new object

# object with specific datetime
np_datetime = nepalidatetime(year, month, day[, hour[, minute[, second]]]) # arguments must be nepali

# object with current datetime
np_datetime = nepalidatetime.now()

# parse datetime
np_datetime = nepalidatetime.strptime('2078-01-12 13:12', format='%Y-%m-%d %H:%M')

Object from python's datetime.datetime

import datetime

dt = datetime.datetime.now()
np_datetime = nepalidatetime.from_datetime(dt)

Get nepalidate object

np_datetime.date()

Get python's datetime.time object

np_datetime.time()

Get python's datetime.datetime object

np_datetime.to_datetime()

Date String Format
Equivalent to python's datetime strftime format

npDateTime = nepalidatetime.now()
print(npDateTime.strftime('%a %A %w %d %b %B %m %y %Y %H %I %p %M %S'))
print(npDateTime.strftime_en('%a %A %w %d %b %B %m %y %Y %H %I %p %M %S'))
बुध बुधबार ३ २६ मंसिर मंसिर ०८ ७५ २०७५ ११ ११ शुभप्रभात ०६ १३
Wed Wednesday 3 26 Mangsir Mangsir 08 75 2075 11 11 AM 06 13

timedelta operations

ndt = nepalidatetime.now()
print(ndt + datetime.timedelta(hours=5))
print(ndt - datetime.timedelta(hours=5))

parse

Parses datetime from a string.

parse uses very high cost method, so avoid this as much as you can.

from nepali.datetime import parser as nepalidatetime_parser
ndt = nepalidatetime_parser.parse('29 Jestha, 2078, 1:30 PM')

nepalihumanize

nepalihumanize converts nepalidatetime to nepali human readable form

from nepali.datetime import nepalihumanize  

Creating new object

# object from nepali datetime
ndt = nepalidatetime.now()
humanize_str = nepalihumanize(ndt)

# object from python datetime
dt = datetime.datetime.now()
humanize_str = nepalihumanize(dt)

Humanize with threshold
returns date in nepali characters if more than threshold(in seconds) else returns humanize form

humanize_str = nepalihumanize(ndt, threshold=60) # 60 seconds

# custom format after threshold
humanize_str = nepalihumanize(ndt, threshold=60, format='%Y-%m-%d') # 60 seconds

For Django Template

Add 'nepali' to your INSTALLED_APPS setting.

INSTALLED_APPS = [
	...
	'nepali',
	...
]

IN your Template

{% load nepalidatetime %}
{% nepalinow %}
{% nepalinow '%Y-%m-%d' %}
{{ datetimeobj|nepalidate:"%Y-%m-%d" }}
{{ datetimeobj|nepalidate_en:"%Y-%m-%d" }}
{{ datetimeobj|nepalihumanize }}

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-0.5.5.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nepali-0.5.5-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file nepali-0.5.5.tar.gz.

File metadata

  • Download URL: nepali-0.5.5.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for nepali-0.5.5.tar.gz
Algorithm Hash digest
SHA256 f8f976d6d5283285e3874cff1a9f7860860d15a0e23bf8f31f3aa42ac8ae67d2
MD5 a58a5bc2947cc49b47437234b86b6fe6
BLAKE2b-256 1a7980070110292da9885259a959e0276e2505bc4f223acdfbc6061b0a20f79f

See more details on using hashes here.

File details

Details for the file nepali-0.5.5-py3-none-any.whl.

File metadata

  • Download URL: nepali-0.5.5-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for nepali-0.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 273eaeb51251c5152f4c5e3c5563d96aa3268c2527508e0492d21b2863c8b5cd
MD5 f0681b25a853f9ebb0c5f7debeb86930
BLAKE2b-256 547a3334270a97da472235da1215d21890d1a24ec1d10d26bbf4b5887acd9b03

See more details on using hashes here.

Supported by

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