Building a Bikram Sambat ⇄ AD Converter

By Anish Shrestha • • 8 min read

EngineeringBS CalendarRust

The Nepali calendar is not a formula you can derive — it is a table you have to respect. Notes on modelling months, leap behaviour and the days that break naive code.

Why the conversion is not a formula

The Gregorian calendar is arithmetic. Bikram Sambat does not work that way. Month lengths are determined by astronomical observation and published in a table.

Any converter that tries to be clever with averages drifts within a decade.

  • Month lengths come from published data, not from a formula
  • A year in BS begins in mid-April
  • Reference dates must be anchored, not calculated backwards

Edge cases that break naive code

Two cases caused most of my early bugs: the month that can run to thirty-two days, and the year boundary in mid-April.

  • Accept 32-day months where the table says so
  • Do not derive the BS year from the AD year directly
  • Test the last day of every month

Written by Anish Shrestha — https://shresthaanish.com.np

All posts