NepDate 2.0.5

dotnet add package NepDate --version 2.0.5
                    
NuGet\Install-Package NepDate -Version 2.0.5
                    
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="NepDate" Version="2.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NepDate" Version="2.0.5" />
                    
Directory.Packages.props
<PackageReference Include="NepDate" />
                    
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 NepDate --version 2.0.5
                    
#r "nuget: NepDate, 2.0.5"
                    
#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 NepDate@2.0.5
                    
#: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=NepDate&version=2.0.5
                    
Install as a Cake Addin
#tool nuget:?package=NepDate&version=2.0.5
                    
Install as a Cake Tool

NepDate Logo

<div align="center">

NepDate - Fast & Efficient Nepali Date Library for .NET

Modern, High-Performance Bikram Sambat Date Operations for .NET Applications

GitHub Stars NuGet Version NuGet Downloads License: MIT

</div>


NepDate is a super-fast and memory-efficient struct built on .NET Standard 2.0 that offers comprehensive Nepali date functionality in a lightweight package. Designed to closely resemble the DateOnly struct in .NET, NepDate provides a familiar, intuitive API for working with Nepali dates (Bikram Sambat).

📋 Table of Contents

Section Description
📦 Installation How to add NepDate to your project
Key Features What makes NepDate special
🚀 Getting Started Begin using NepDate quickly
📅 Date Operations Core date manipulation functions
🔄 Date Range Operations Operations related to date ranges
🖨️ Formatting & Display Control how dates appear
💼 Fiscal Year Operations Business date calculations
🔍 Advanced Features For power users
Performance Why NepDate is faster
👥 Contributions How to help improve NepDate
📝 Change Log Recent updates

📦 Installation

Using Package Manager Console

Install-Package NepDate

Using .NET CLI

dotnet add package NepDate

✨ Key Features

  • 🔄 Date Conversion: Seamlessly convert between Bikram Sambat (B.S.) and Gregorian (A.D.) dates
  • Robust Validation: Full support for Nepali date validation with correct day limits for each month
  • 🧮 Date Arithmetic: Add or subtract days, months, and years with precision
  • 🔍 Smart Parsing: Intelligent date parsing with support for multiple formats and dialects
  • 🖋️ Date Formatting: Localized date formatting with multiple Nepali dialects and formal/informal styles
  • 📊 Fiscal Year Support: Built-in functions for fiscal year calculations and quarter periods
  • 💾 Serialization Support: Complete integration with System.Text.Json, Newtonsoft.Json, and XML
  • Performance: Benchmarked to be significantly faster than other Nepali date libraries
  • 📦 Memory Efficient: Implemented as a struct to minimize memory footprint

🚀 Getting Started

Initialize NepaliDate

From Nepali year, month, and day values
using NepDate;

var nepDate = new NepaliDate(2079, 12, 16);
From a string
using NepDate;

var nepDate = new NepaliDate("2079/12/16");
// or
var nepDate = NepaliDate.Parse("2079/12/16");
From English DateTime
using NepDate;
using NepDate.Extensions;

var nepDate = new NepaliDate(DateTime.Now);
// or
var nepDate = DateTime.Now.ToNepaliDate();
Get current Nepali date
using NepDate;

var today = NepaliDate.Now; // Initializes with current Nepali date

Accessing Properties

using NepDate;

var nepDate = new NepaliDate("2079/12/16");

// Basic properties
int year = nepDate.Year;        // 2079
int month = nepDate.Month;      // 12
int day = nepDate.Day;          // 16
DateTime engDate = nepDate.EnglishDate;  // 2023/03/30
DayOfWeek weekDay = nepDate.DayOfWeek;   // Thursday
int dayOfYear = nepDate.DayOfYear;       // 245

// Month details
int lastDay = nepDate.MonthEndDay;       // 30
NepaliDate monthEnd = nepDate.MonthEndDate();  // 2079/12/30
NepaliMonths monthName = nepDate.MonthName;  // Chaitra

📅 Date Operations

Adding and Subtracting Time

using NepDate;

var nepDate = new NepaliDate("2081/04/32");

// Add or subtract days
var fiveDaysLater = nepDate.AddDays(5);       // 2081/05/05
var fiveDaysEarlier = nepDate.AddDays(-5);    // 2081/04/27

// Add or subtract months
var twoMonthsLater = nepDate.AddMonths(2);    // 2081/06/30
var twoMonthsEarlier = nepDate.AddMonths(-2); // 2081/02/32

// Fractional months
var twoAndHalfMonths = nepDate.AddMonths(2.5); // 2081/07/15

// Adjust away from month end when needed
var adjustedDate = nepDate.AddMonths(2, awayFromMonthEnd: true); // 2081/07/02

Date Comparison

using NepDate;

var date1 = NepaliDate.Parse("2079/12/16");
var date2 = DateTime.Now.ToNepaliDate();

// Equality comparison
if (date1 == date2) { /* dates are equal */ }

// Less than / greater than
if (date1 < date2) { /* date1 is earlier than date2 */ }
if (date1 > date2) { /* date1 is after date2 */ }

// Get time span between dates
var timeSpan = date2 - date1;  // TimeSpan object
// or
timeSpan = date2.Subtract(date1);

Simple Conversion

using NepDate;

// Convert DateTime to Nepali date string
string nepaliDate = DateTime.Now.ToNepaliDate().ToString();

// Convert Nepali date string to DateTime
DateTime englishDate = NepaliDate.Parse("2079/12/16").EnglishDate;

Bulk Conversion

var engDates = new List<DateTime>();
var nepDatesAsString = new List<string>();

// Convert a collection of English dates to Nepali dates
var nepDates = NepaliDate.BulkConvert.ToNepaliDates(engDates);

// Convert a collection of Nepali dates to English dates
var newEngDates = NepaliDate.BulkConvert.ToEnglishDates(nepDates);

// Convert a collection of Nepali date strings to English dates
var parsedEngDates = NepaliDate.BulkConvert.ToEnglishDates(nepDatesAsString);

🔄 Date Range Operations

Creating Date Ranges

using NepDate;

// Create a range between two dates
var start = new NepaliDate(2080, 1, 1);
var end = new NepaliDate(2080, 3, 15);
var range = new NepaliDateRange(start, end);

// Create a range for a single day
var singleDay = NepaliDateRange.SingleDay(start);

// Create a range with a specific number of days
var tenDays = NepaliDateRange.FromDayCount(start, 10);

// Create ranges for specific periods
var monthRange = NepaliDateRange.ForMonth(2080, 1);      // Full month
var fiscalYear = NepaliDateRange.ForFiscalYear(2080);    // Full fiscal year
var calendarYear = NepaliDateRange.ForCalendarYear(2080); // Full calendar year

// Get current period ranges
var currentMonth = NepaliDateRange.CurrentMonth();
var currentFiscalYear = NepaliDateRange.CurrentFiscalYear();
var currentCalendarYear = NepaliDateRange.CurrentCalendarYear();

Range Properties and Operations

var range = new NepaliDateRange(start, end);

// Basic properties
bool isEmpty = range.IsEmpty;     // Check if range is empty
int length = range.Length;        // Get number of days in range
var startDate = range.Start;      // Get start date
var endDate = range.End;         // Get end date

// Range operations
bool contains = range.Contains(someDate);           // Check if date is in range
bool containsRange = range.Contains(otherRange);    // Check if range contains another range
bool overlaps = range.Overlaps(otherRange);        // Check if ranges overlap
bool adjacent = range.IsAdjacentTo(otherRange);    // Check if ranges are adjacent

// Range manipulation
var intersection = range.Intersect(otherRange);    // Get intersection of two ranges
var excluded = range.Except(otherRange);           // Get range with another range excluded

Splitting and Iterating Ranges

var range = new NepaliDateRange(start, end);

// Split range by periods
var monthRanges = range.SplitByMonth();    // Split into month ranges
var quarterRanges = range.SplitByQuarter(); // Split into quarter ranges

// Iterate through dates
foreach (var date in range)  // Iterate all dates
{
    // Process each date
}

// Get specific date collections
var workingDays = range.WorkingDays();          // Get working days (excluding Saturdays)
var workingDaysNoSunday = range.WorkingDays(excludeSunday: true); // Exclude Sundays too
var weekendDays = range.WeekendDays();          // Get weekend days
var intervalDates = range.DatesWithInterval(7);  // Get dates with 7-day interval

Range Formatting

var range = new NepaliDateRange(start, end);

// Basic string representation
string basic = range.ToString();  // "2080/01/01 - 2080/03/15"

// Formatted string
string formatted = range.ToString(DateFormats.DayMonthYear, Separators.Dash);  // "01-01-2080 - 15-03-2080"

🖨️ Formatting & Display

Formatting Options

🗓️ Default 2079/02/06 <br> 📆 Custom 6-2-2079 <br> 📝 Long Friday, Jestha 6
📊 Unicode ०६.०२.२०७९ <br> 🌟 Nepali शुक्रबार, जेठ ६

Basic Formatting

using NepDate;

var nepDate = new NepaliDate("2079/02/06");

// Default format
string defaultFormat = nepDate.ToString();  // "2079/02/06"

// Custom format
string customFormat = nepDate.ToString(DateFormats.DayMonthYear, Separators.Dash, leadingZeros: false);  // "6-2-2079"

// Long date format
string longDate = nepDate.ToLongDateString(leadingZeros: false, displayDayName: true, displayYear: false);  // "Friday, Jestha 6"

// Nepali unicode digits
string nepaliDigits = nepDate.ToUnicodeString(DateFormats.DayMonthYear, Separators.Dot, leadingZeros: true);  // "०६.०२.२०७९"

// Long date in Nepali
string nepaliLongDate = nepDate.ToLongDateUnicodeString(leadingZeros: false, displayDayName: true, displayYear: false);  // "शुक्रबार, जेठ ६"

Smart Date Parsing

using NepDate;
using NepDate.Extensions;

// Parse with auto adjustment
var date1 = NepaliDate.Parse("2077_05_25", autoAdjust: true);  // 2077/05/25
var date2 = NepaliDate.Parse("25-05-077", autoAdjust: true);   // 2077/05/25
var date3 = NepaliDate.Parse("05.25.2077", autoAdjust: true);  // 2077/05/25

// Control month position
var date4 = NepaliDate.Parse("05/06/2077", autoAdjust: true);  // 2077/06/05
var date5 = NepaliDate.Parse("05/06/2077", autoAdjust: true, monthInMiddle: false);  // 2077/05/06

// Smart parser supports various formats
var date6 = SmartDateParser.Parse("15 Shrawan 2080");  // DD Month YYYY
var date7 = SmartDateParser.Parse("Shrawan 15, 2080");  // Month DD, YYYY
var date8 = SmartDateParser.Parse("15 Saun 2080");  // With alternate spelling
var date9 = SmartDateParser.Parse("२०८०/०४/१५");  // Nepali digits
var date10 = SmartDateParser.Parse("१५ श्रावण २०८०");  // Full Nepali format

// Extension method
var date11 = "15 Shrawan 2080".ToNepaliDate();

// Safe parsing
if ("15 Shrawan 2080".TryToNepaliDate(out var date12)) {
    // Use date12
}

💼 Fiscal Year Operations

Fiscal Year Support

Operation Result Time Period
Fiscal Year Start 2081/04/01 Beginning of fiscal year
Fiscal Year End 2082/03/31 End of fiscal year
Quarter Start 2081/04/01 Beginning of quarter
Quarter End 2081/06/30 End of quarter
using NepDate;

var nepDate = new NepaliDate("2081/04/15");

// For current date
var fyStartDate = nepDate.FiscalYearStartDate();  // 2081/04/01
var fyEndDate = nepDate.FiscalYearEndDate();  // 2082/03/31
var (start, end) = nepDate.FiscalYearStartAndEndDate();  // (2081/04/01, 2082/03/31)

// Quarter information
var qStartDate = nepDate.FiscalYearQuarterStartDate();  // 2081/04/01
var qEndDate = nepDate.FiscalYearQuarterEndDate();  // 2081/06/30
var (qStart, qEnd) = nepDate.FiscalYearQuarterStartAndEndDate();  // (2081/04/01, 2081/06/30)

// Static methods using fiscal year number
var fy2080Start = NepaliDate.GetFiscalYearStartDate(2080);  // 2080/04/01
var fy2080End = NepaliDate.GetFiscalYearEndDate(2080);  // 2081/03/31
var fy2080Quarter = NepaliDate.GetFiscalYearQuarterStartAndEndDate(2080, 1);  // (2081/01/01, 2081/03/31)

🔍 Advanced Features

Additional Helper Methods

using NepDate;

var nepDate = new NepaliDate("2079/12/16");

// Check if year is leap year
bool isLeap = nepDate.IsLeapYear();  // False/True

// Date comparison helpers
bool isToday = nepDate.IsToday();
bool isYesterday = nepDate.IsYesterday();
bool isTomorrow = nepDate.IsTomorrow();

// Safe parsing
if (NepaliDate.TryParse("2079/13/16", out var result)) {
    // use the result NepaliDate object
}

Serialization Support

Supporting Multiple Serialization Formats

JSON (String): "2080-04-15" <br> JSON (Object): {"Year":2080,"Month":4,"Day":15} <br> XML: Custom wrapper

System.Text.Json
using System.Text.Json;
using NepDate;
using NepDate.Serialization;

// Configure for string format (default)
var options = new JsonSerializerOptions()
    .ConfigureForNepaliDate();

// Or for object format
var objectOptions = new JsonSerializerOptions()
    .ConfigureForNepaliDate(useObjectFormat: true);

// Serialize
var date = new NepaliDate(2080, 4, 15);
string jsonString = JsonSerializer.Serialize(date, options);  // "2080-04-15"
string jsonObject = JsonSerializer.Serialize(date, objectOptions);  // {"Year":2080,"Month":4,"Day":15}

// Deserialize
var deserializedDate = JsonSerializer.Deserialize<NepaliDate>(jsonString, options);
Newtonsoft.Json
using Newtonsoft.Json;
using NepDate;
using NepDate.Serialization;

// Configure for string format (default)
var settings = new JsonSerializerSettings()
    .ConfigureForNepaliDate();

// Or for object format
var objectSettings = new JsonSerializerSettings()
    .ConfigureForNepaliDate(useObjectFormat: true);

// Serialize
var date = new NepaliDate(2080, 4, 15);
string jsonString = JsonConvert.SerializeObject(date, settings);  // "2080-04-15"
string jsonObject = JsonConvert.SerializeObject(date, objectSettings);  // {"Year":2080,"Month":4,"Day":15}

// Deserialize
var deserializedDate = JsonConvert.DeserializeObject<NepaliDate>(jsonString, settings);
XML Serialization
using System.Xml.Serialization;
using NepDate;
using NepDate.Serialization;

// Create a wrapper class for XML serialization
public class PersonWithDate
{
    public string Name { get; set; }

    // Use the XML serializer wrapper
    public NepaliDateXmlSerializer BirthDate { get; set; }

    // Helper property for convenience
    [XmlIgnore]
    public NepaliDate ActualBirthDate
    {
        get => BirthDate?.Value ?? default;
        set => BirthDate = new NepaliDateXmlSerializer(value);
    }
}

// Usage
var person = new PersonWithDate
{
    Name = "Ram Sharma",
    ActualBirthDate = new NepaliDate(2040, 2, 15)
};

var serializer = new XmlSerializer(typeof(PersonWithDate));
// Serialize to XML...

⚡ Performance

NepDate is up to 1000x faster than other libraries

NepDate is designed for exceptional performance, significantly outperforming other Nepali date libraries while using minimal memory.

Package Method Mean (ns) Error (ns) StdDev (ns) Rank Allocated (B)
NepDate BS -> AD 62.59 0.295 0.261 1️⃣ -
NepDate AD -> BS 276.83 0.593 0.526 2️⃣ 120
NepaliDateConverter.NETCORE BS -> AD 63,460.38 54.052 42.201 3️⃣ 20176
NepaliDateConverter.NETCORE AD -> BS 186,610.23 420.217 350.901 7️⃣ 20160
NepaliCalendarBS BS -> AD 99,511.43 247.038 231.080 5️⃣ 159328
NepaliCalendarBS AD -> BS 113,258.50 364.280 340.748 6️⃣ 158760
NepaliDateConverter.Net BS -> AD 75,327.75 269.244 251.851 4️⃣ 20176
NepaliDateConverter.Net AD -> BS 212,478.96 4,192.698 5,877.576 8️⃣ 20160

<br>

<div align="center">

👥 Contributions

We welcome contributions from the community

Contributions are welcome! Please check out the CONTRIBUTING guide for more information on how you can help improve NepDate.

📝 Change Log

For a detailed list of changes in each release, visit the releases page.


Made with ❤️ by TheCrossLegCoder

</div>

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on NepDate:

Package Downloads
NEAPES.UI.Components

NEAPES UI Components are enterprise-grade, reusable components that help Blazor developers build full-stack applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.5 493 4/20/2025
2.0.4 1,843 4/3/2025
2.0.3 3,388 1/13/2025
2.0.2 1,197 11/19/2024
2.0.1 440 9/16/2024
2.0.0 1,603 3/31/2024
1.2.0 934 4/22/2023
1.1.0 259 4/14/2023
1.0.1 229 4/13/2023
1.0.0 340 4/13/2023