Skip to content

C# and .NET

NepDate is the C# library the family started from, by Raju Prasai and contributors. The calendar data and the algorithm every port uses come from it, and the ports’ test vectors were recorded from its NuGet package. It targets .NET Standard 2.0 and .NET 8, with no dependencies.

It is maintained in its own repository with its own version and full documentation at nepdate.rajuprasai.com.np. This page covers the basics.

Terminal window
dotnet add package NepDate --version 2.0.7
using NepDate;
var date = new NepaliDate(2081, 4, 15);
Console.WriteLine(date.EnglishDate.ToString("yyyy-MM-dd")); // 2024-07-30
Console.WriteLine(date.ToLongDateString()); // Shrawan 15, 2081
var fromAd = new DateTime(2024, 7, 30).ToNepaliDate(); // 2081/04/15
var today = NepaliDate.Today;
var parsed = NepaliDate.Parse("2081/04/15"); // equals date
bool ok = NepaliDate.TryParse("2081-13-01", out _); // false: there is no month 13
date.AddDays(1000); // 2084/01/13
date.AddMonths(13); // 2082/05/15

Unlike the other ports, C# NepDate keeps the patro in the same package, as properties on the date:

var day = new NepaliDate(2081, 6, 26);
day.TithiEn; // "Dashami (K)"
day.IsPublicHoliday; // true
day.EventsEn; // ["Vijaya Dashami", "Devi Visarjan"]
  • One package. The ports split the core and the patro so an app that only converts dates ships no almanac data (Core and patro).
  • Its own versions. NepDate follows its own release schedule; the ports’ version numbers are unrelated to it.
  • The reference. Where a port’s behaviour differs from NepDate, every port differs the same way, and the list is written down (Same answer everywhere).
  • Data fixes go here first. A wrong date or holiday is fixed in NepDate, then reaches every port through the hub (Calendar data).