Parity with datetime and calendar¶
sambat.date, sambat.datetime and sambat.calendar implement every public
name of the running Python’s datetime and calendar modules. The
test suite enforces this: when a new Python version adds a public name, the
parity tests fail until sambat implements it or it is listed below.
Intentional differences¶
- Separate types
sambat.datedoes not subclassdatetime.date. A BS date never compares equal to a Gregorian date, and ordering or subtracting across the two raisesTypeError. Convert explicitly withto_gregorian()andfrom_gregorian().- Supported range
MINYEARandMAXYEARcome from the calendar table. Constructors raiseValueErroroutside it; arithmetic raisesOverflowError, as the standard library does at its limits.- ISO weeks
isocalendar(),fromisocalendar(),%G,%Vand ISO week strings use a BS week calendar: Monday-start weeks, week 1 contains the first Thursday of the BS year. The Gregorian ISO week isto_gregorian().isocalendar(). For the first days ofMINYEARthe week-year is not representable andisocalendar()raisesValueError.timetuple()Returns BS fields (
tm_ydayis the day of the BS year). Do not pass it totime.mktime().strftimeandstrptimePure Python with a fixed directive set, a
localekeyword and the%Omodifier; unknown directives raiseValueError. See Format directives.ctime()Uses English BS month abbreviations, e.g.
Thu Ash 15 14:05:09 2083.- Time zones
tzinfomethods are always called with the equivalent standard-library datetime, never with asambat.datetime.utcnow()andutcfromtimestamp()Emit
DeprecationWarningon every Python version (they are deprecated since Python 3.12).sambat.calendarBS month constants (
BAISHAKH…CHAITRA) replaceJANUARY…DECEMBER.isleap(year)means “has 366 days”; there is no leap rule in BS.LocaleTextCalendarandLocaleHTMLCalendartake a sambatLocaleinstead of a C locale name, anddifferent_localeis not provided.Iterators that yield date objects (
itermonthdates,monthdatescalendar, …) raiseValueErrorwhen a padding day falls outside the supported range, just as the standard library does at year 9999.