Methods
date.is_same()
Check whether two dates match across a specified granularity such as year, month, or day.
The is_same method compares the current NepaliDate instance with another date at a specified level of granularity, such as year, month, day, hour, or minute. It returns true if both dates match within that specific unit, simplifying range checks and calendar filters.
Import
from nepali_date_library import NepaliDateSignature
def is_same(self, date: NepaliDate, unit: str) -> bool:Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
date | NepaliDate | Yes | Date instance to compare with. |
unit | str | Yes | Granularity: "year", "month", "date", "day". |
Return Value
- Type:
bool - Description: Returns
Trueif the specified unit matches.
Example
from nepali_date_library import NepaliDate
d1 = NepaliDate("2081-07-05")
d2 = NepaliDate("2081-07-20")
# Same month and year
print(d1.is_same(d2, "month")) # True
# Different day
print(d1.is_same(d2, "date")) # FalseRelated
date.is_equal(): Compare full date equality.date.diff(): Quantitative difference.
Advertisement
date.is_equal()
Check whether two date instances share the exact same calendar date coordinates regardless of time.
date.is_valid_instance()
Validate whether the current NepaliDate instance represents a legitimate calendar date within supported bounds.