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.
Install
Section titled “Install”dotnet add package NepDate --version 2.0.7Convert and format
Section titled “Convert and format”using NepDate;
var date = new NepaliDate(2081, 4, 15);Console.WriteLine(date.EnglishDate.ToString("yyyy-MM-dd")); // 2024-07-30Console.WriteLine(date.ToLongDateString()); // Shrawan 15, 2081
var fromAd = new DateTime(2024, 7, 30).ToNepaliDate(); // 2081/04/15var today = NepaliDate.Today;Parse and do arithmetic
Section titled “Parse and do arithmetic”var parsed = NepaliDate.Parse("2081/04/15"); // equals datebool ok = NepaliDate.TryParse("2081-13-01", out _); // false: there is no month 13
date.AddDays(1000); // 2084/01/13date.AddMonths(13); // 2082/05/15Tithi, holidays and events
Section titled “Tithi, holidays and events”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; // trueday.EventsEn; // ["Vijaya Dashami", "Devi Visarjan"]How it relates to the ports
Section titled “How it relates to the ports”- 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).