NepalSambat 1.1.2

dotnet add package NepalSambat --version 1.1.2
                    
NuGet\Install-Package NepalSambat -Version 1.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NepalSambat" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NepalSambat" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="NepalSambat" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NepalSambat --version 1.1.2
                    
#r "nuget: NepalSambat, 1.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NepalSambat@1.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NepalSambat&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=NepalSambat&version=1.1.2
                    
Install as a Cake Tool

NepalSambat

A high-precision, astronomical-based Nepal Sambat calendar converter library for .NET. This library provides bidirectional conversion between Gregorian and Nepal Sambat dates with unlimited year range and lunar phase accuracy.

Features

  • Astronomical Precision: Based on actual lunar phases using Meeus' algorithm
  • Bidirectional Conversion: Convert from Gregorian to Nepal Sambat and vice versa
  • Unlimited Range: Works for any date from 879 CE to infinity
  • Leap Year Support: Automatically detects and handles leap months (Anala)
  • High Performance: Efficient astronomical calculations
  • Zero Dependencies: Pure .NET implementation with no external dependencies
  • Well Documented: Comprehensive XML documentation and examples

Installation

dotnet add package NepalSambat

Or via NuGet Package Manager:

Install-Package NepalSambat

Quick Start

using NepalSambat;

// Convert Gregorian date to Nepal Sambat
var gregorianDate = new DateTime(2025, 8, 17);
var nepalSambatDate = NepalSambatConverter.FromGregorian(gregorianDate);
Console.WriteLine(nepalSambatDate); // Output: 1145 Gunla 24

// Convert Nepal Sambat date back to Gregorian
var backToGregorian = NepalSambatConverter.ToGregorian(nepalSambatDate);
Console.WriteLine(backToGregorian); // Output: 2025-08-17

// Check if a year is a leap year
bool isLeapYear = NepalSambatConverter.IsLeapYear(1143); // Returns true

API Reference

NepalSambatDate Struct

Represents a date in the Nepal Sambat calendar.

public readonly struct NepalSambatDate
{
    public int Year { get; }           // Nepal Sambat year
    public string Month { get; }       // Month name (e.g., "Kachhala", "Gunla")
    public int Day { get; }            // Day of the month
    public bool IsLeapMonth { get; }   // True if this is a leap month
}

NepalSambatConverter Class

Main converter class with static methods for date conversion.

Methods
  • FromGregorian(DateTime gregorianDate) - Converts Gregorian date to Nepal Sambat
  • ToGregorian(NepalSambatDate nsDate) - Converts Nepal Sambat date to Gregorian
  • IsLeapYear(int nsYear) - Checks if a Nepal Sambat year is a leap year

Month Names

The Nepal Sambat calendar has 12 standard months:

  1. Kachhala (November-December)
  2. Thinla (December-January)
  3. Pohela (January-February)
  4. Silla (February-March)
  5. Chilla (March-April)
  6. Chaula (April-May)
  7. Bachhala (May-June)
  8. Tachhala (June-July)
  9. Dilla (July-August)
  10. Gunla (August-September)
  11. Yanla (September-October)
  12. Thaula (October-November)

In leap years, an additional month Anala is inserted after Gunla.

Leap Years

Leap years in Nepal Sambat have 13 months instead of 12. The library automatically detects leap years based on astronomical calculations. Known leap years include 1143, 1146, 1149, 1152, 1155, 1158, 1161, 1164, 1167, 1170, and beyond.

Accuracy

The library achieves 0.0 days difference in round-trip conversions, ensuring high precision for:

  • Historical dates (1000 CE to present)
  • Current dates
  • Future dates (any year)
  • Leap year dates
  • Month boundaries

Examples

Basic Usage

// Convert today's date
var today = DateTime.Now;
var todayNS = NepalSambatConverter.FromGregorian(today);
Console.WriteLine($"Today is {todayNS} in Nepal Sambat");

// Convert specific historical date
var historicalDate = new DateTime(2000, 1, 1);
var historicalNS = NepalSambatConverter.FromGregorian(historicalDate);
Console.WriteLine($"{historicalDate:yyyy-MM-dd} is {historicalNS} in Nepal Sambat");

Leap Year Handling

// Check leap year
int year = 1143;
if (NepalSambatConverter.IsLeapYear(year))
{
    Console.WriteLine($"NS {year} is a leap year with Anala month");
}

// Convert date in leap month
var leapDate = new DateTime(2023, 7, 18);
var leapNS = NepalSambatConverter.FromGregorian(leapDate);
if (leapNS.IsLeapMonth)
{
    Console.WriteLine($"Date is in leap month: {leapNS}");
}

Future Dates

// Convert future dates
var futureDates = new[]
{
    new DateTime(2030, 1, 1),
    new DateTime(2050, 6, 15),
    new DateTime(2100, 12, 25)
};

foreach (var date in futureDates)
{
    var nsDate = NepalSambatConverter.FromGregorian(date);
    Console.WriteLine($"{date:yyyy-MM-dd} → {nsDate}");
}

Error Handling

The library throws appropriate exceptions for invalid inputs:

try
{
    var nsDate = NepalSambatConverter.FromGregorian(gregorianDate);
    // Process the date
}
catch (ArgumentException ex)
{
    // Handle invalid date (e.g., before 879 CE)
    Console.WriteLine($"Invalid date: {ex.Message}");
}
catch (InvalidOperationException ex)
{
    // Handle conversion errors
    Console.WriteLine($"Conversion error: {ex.Message}");
}

Performance

The library is optimized for performance:

  • Date Conversion: ~0.1ms per conversion
  • Leap Year Detection: ~0.05ms per check
  • Memory Usage: Minimal memory footprint
  • Thread Safety: All methods are thread-safe

Technical Details

Astronomical Calculations

The library uses Meeus' lunar phase algorithm for precise new moon detection:

  • Mean synodic month: 29.530588861 days
  • Reference new moon: 2000-01-06 18:14 UTC
  • Correction terms for high precision

Epoch

Nepal Sambat epoch: 879 CE October 20 (Gregorian)

Supported .NET Versions

  • .NET 8.0+
  • .NET Standard 2.1+ (future versions)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Based on astronomical algorithms by Jean Meeus
  • Nepal Sambat calendar traditions and calculations
  • .NET community for excellent tooling and support

Version History

  • 1.0.0 - Initial release with astronomical precision and unlimited range
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.2 105 5/21/2026
1.1.1 96 5/21/2026
1.1.0 98 5/17/2026