Migrate from nepali-datetime¶
sambat is a clean-room replacement for nepali-datetime. Most code needs only a few changes, but some behaviour differs on purpose because sambat follows the standard library exactly.
API mapping¶
nepali-datetime |
sambat |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The old conversion names are available as deprecated functions in
sambat.compat, which emit DeprecationWarning.
Behaviour changes¶
weekday()starts on Mondaynepali-datetime returned Sunday = 0. sambat returns Monday = 0 like
datetime.date.weekday(); useisoweekday()or(d.weekday() + 1) % 7for Sunday-based numbering.toordinal()matches the standard librarynepali-datetime counted days from BS 1975-01-01. sambat returns the proleptic Gregorian ordinal, so
d.toordinal() == d.to_gregorian().toordinal().now()andtoday()use local timenepali-datetime always used Nepal time. sambat follows the standard library (machine-local time); use
sambat.now_np()andsambat.today_np()for Nepal time.- Years after the last published calendar raise
nepali-datetime shipped projected month lengths up to BS 2100. sambat only ships published years, so later dates raise
ValueErroruntil a release adds them.isocalendar(), hashing and pickling workThey were missing or broken in nepali-datetime.
Format strings¶
nepali-datetime used custom strftime letters that collide with standard
directives (%D, %n, %G, %h, %k, %l, %s, %N, %K). sambat uses
the standard directives with a locale and the %O (Devanagari digits)
modifier instead. sambat.compat.translate_format() converts old format
strings:
>>> from sambat import date
>>> from sambat.compat import translate_format
>>> fmt, locale = translate_format("%K %N %D, %G")
>>> fmt
'%OY %B %Od, %A'
>>> date(2083, 6, 15).strftime(fmt, locale=locale)
'२०८३ असोज १५, बिहीबार'
Calendar differences¶
sambat’s table differs from nepali-datetime’s in a few rows. BS 2082 and 2083 have been verified against the national panchang, and every disputed year is documented in The calendar data. If you stored BS dates produced by nepali-datetime for years after 2083, they were projections; they will need checking once the official calendar for those years is published.