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:
objectThis 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.dateinstance, then you can pass it as_adargument to the constructor like this:>>> samwat(2074, 11, 30, date(2018, 3, 14))
Doing so will cache the AD equivalent of the
samwatinstance and provide a faster access through theadproperty for future access.samwatalso supports date operations, comparison etc. with othersamwatobjects anddatetime.dateobjects. It also supports arithmetic operations withdatetime.timedeltaobjects.Compare two
samwatdate:>>> samwat(2074, 10, 30) < samwat(2074, 11, 30) True
Comparison with
datetime.dateobject:>>> samwat(2074, 10, 30) == date(2018, 3, 14) True
Subtract 10 days from a
samwatusingdatetime.timedeltaobject.>>> samwat(2074, 10, 30) - timedelta(days=10) samwat(2074, 10, 20)
Subtract two
samwatdates and getdatetime.timedeltarepresentation.>>> 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.pyfile. As warned in the usage guide, you will need to handleValueErrorexception if the date falls outside the range.-
ad¶ Return a
datetime.dateinstance, that is, this date converted to AD. Accessing theadproperty automatically tries to calculate the AD date.It caches the
datetiem.dateobject as_adto avoid expensive calculation for the next time.>>> samwat(2074, 11, 30).ad datetime.date(2018, 3, 14)
-
as_tuple()[source]¶ Return a
samwatinstance 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
samwatby 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.