When a payment succeeds in PayBridgeNP’s Nepali checkout, the success page shows the date in Bikram Sambat, in Nepali digits, like २०८३ असार २९.

BS months are between 29 and 32 days long, and the same month can change length from one year to the next. The lengths come from each year’s published calendar, so the conversion uses a table of them rather than a formula.

The table#

The table comes from medic/bikram-sambat, an open-source project under the Apache 2.0 licence. It packs each year’s twelve month lengths into one number and covers BS 1970 to 2090. BS 2090 ends in 2034.

To convert a date, the code starts from 1 Baisakh 1970 BS, which was 13 April 1913, counts the days up to the payment date, and walks through the table month by month.

Edge cases#

Outside the table’s range, the conversion returns nothing, and the page shows the Gregorian date in Nepali digits instead of guessing.

The conversion also has to start from the Nepal date. The servers run on UTC, and a payment at 00:10 in Kathmandu is still the previous day in UTC, so converting the UTC date would put it a day early.