bikram package¶
Submodules¶
bikram.bikram module¶
This module contains the samwat
, a container class for Bikram Samwat dates.
To run the examples in this page, import samwat
like this:
>>> from bikram import samwat
Some examples require the datetime.date
, and datetime.timedelta
objects. Please import them as follows:
>>> from datetime import date, timedelta
-
class
bikram.bikram.
samwat
(year, month, day, ad=None)[source]¶ Bases:
object
This class represents a Bikram Samwat date. It can be used as an independent container, without using the date conversion part.
>>> samwat(2074, 11, 30) samwat(2074, 11, 30)
If you have the equivalent
datetime.date
instance, then you can pass it as_ad
argument to the constructor like this:>>> samwat(2074, 11, 30, date(2018, 3, 14))
Doing so will cache the AD equivalent of the
samwat
instance and provide a faster access through thead
property for future access.samwat
also supports date operations, comparison etc. with othersamwat
objects anddatetime.date
objects. It also supports arithmetic operations withdatetime.timedelta
objects.Compare two
samwat
date:>>> samwat(2074, 10, 30) < samwat(2074, 11, 30) True
Comparison with
datetime.date
object:>>> samwat(2074, 10, 30) == date(2018, 3, 14) True
Subtract 10 days from a
samwat
usingdatetime.timedelta
object.>>> samwat(2074, 10, 30) - timedelta(days=10) samwat(2074, 10, 20)
Subtract two
samwat
dates and getdatetime.timedelta
representation.>>> samwat(2074, 10, 11) - samwat(2070, 10, 11) datetime.timedelta(1461)
Please note that the above operations require that the date be in the range of years specified in the
constants.py
file. As warned in the usage guide, you will need to handleValueError
exception if the date falls outside the range.-
ad
¶ Return a
datetime.date
instance, that is, this date converted to AD. Accessing thead
property automatically tries to calculate the AD date.It caches the
datetiem.date
object as_ad
to avoid expensive calculation for the next time.>>> samwat(2074, 11, 30).ad datetime.date(2018, 3, 14)
-
as_tuple
()[source]¶ Return a
samwat
instance as a tuple of year, month, and day.>>> samwat(2074, 11, 30).as_tuple() (2074, 11, 30)
-
day
¶
-
static
from_ad
(ad_date)[source]¶ Expects a datetime.date then returns an equivalent bikram.samwat instance
-
classmethod
from_iso
(datestr: str)[source]¶ Naive way to parse date from a ISO8601 (YYYY-MM-DD) BS date string and return bikram.samwat instance.
-
month
¶
-
classmethod
parse
(datestr: str, parsestr: str)[source]¶ parse bikram samwat date string and return a bikram.samwat instance.
- “%d”: zero padded day of month, 07
- “%-d”: padded day of month, 7
- “%dne”: zero-padded day of month in devanagari digits, ०७
- “%-dne”: day of month in devanagari digits, ७
- “%m”: zero-padded month number, 01
- “%-m”: month number, 1
- “%mne”: zero-added month number in devanagari digits, ०१
- “%-mne”: month number in devanagari digits, १
- “%y”: two digit year, 73 implies 2073
- “%Y”: four digit year, 2073
- “%yne”: two digit year in devanagari digits, ७३ implies २०७३
- “%Yne”: four digit year in devanagari digits, २०७३
- “%B”: name of bikram samwat months in English spelling, English spelling short
- (abbr. by first three letters), Devanagari spelling. Any one of the list below:
- ```
- [
‘वैशाख’, ‘जेष्ठ’, ‘आषाढ़’, ‘श्रावण’, ‘भाद्र’, ‘आश्विन’, ‘कार्तिक’, ‘मंसिर’, ‘पौष’, ‘माघ’, ‘फाल्गुन’, ‘चैत्र’,
‘Baisakh’, ‘Jestha’, ‘Ashadh’, ‘Shrawan’, ‘Bhadra’, ‘Ashwin’, ‘Kartik’, ‘Mangsir’, ‘Poush’, ‘Magh’, ‘Falgun’, ‘Chaitra’,
‘Bai’, ‘Jes’, ‘Ash’, ‘Shr’, ‘Bha’, ‘Ash’, ‘Kar’, ‘Man’, ‘Pou’, ‘Mag’, ‘Fal’, ‘Cha’,
]
-
replace
(year=None, month=None, day=None)[source]¶ Return a new copy of
samwat
by replacing one or more provided attributes of this date. For example, to replace the year:>>> samwat(2074, 11, 30).replace(year=2073) samwat(2073, 11, 30)
To replace the month:
>>> samwat(2074, 11, 30).replace(month=12) samwat(2074, 12, 30)
-
strftime
(formatstr: str)[source]¶ Format a samwat object to specified date string. The format strings are similar to those accepted by
parse()
with the following additions/modifications:- “%B”: Formats to Nepali month name(Example: Baisakh, Jestha, etc.)
- “%S”: Formats to Punjabi Shahmukhi month name(Example: بیساکھ, جیٹھ, etc.)
- “%Bne”: Formats to Nepali Devnagari month name(Example:’वैशाख’, ‘जेष्ठ’, etc.)
-
year
¶
-
bikram.constants module¶
This file has the necessary constants for date conversion.