Skip to content

Persian Data Library is a library that can be converted Gregorian (Milady) year to Solar Hijri (Shamsi) year in the simplest way!

License

Notifications You must be signed in to change notification settings

hootanht/PersianDate

Repository files navigation

Persian Date Library

Persian Date Library

Convert Gregorian (Miladi) dates to Solar Hijri (Shamsi) dates with ease!

NuGet NuGet downloads Build Status Build Status

Features

  • Convert Gregorian dates to Shamsi (Persian) dates
  • Support for both DateTime and DateTimeOffset
  • Get Shamsi year, month, and day components
  • Get Shamsi month and day names
  • Extension methods for easy conversion

Installation

Install the package via NuGet:

dotnet add package PersianDateShamsi

Usage

Basic Conversion

using PersianDate;

PersianDateShamsi persianDate = new PersianDateShamsi();
DateTime now = DateTime.Now;

int shamsiYear = persianDate.GetShamsiYear(now);
string shamsiMonthName = persianDate.GetShamsiMonthName(now);
string shamsiDayString = persianDate.GetShamsiDayString(now);
string shamsiDayName = persianDate.GetShamsiDayName(now);
string shamsiDayShortName = persianDate.GetShamsiDayShortName(now);

Console.WriteLine($"Year: {shamsiYear}");
// Output: Year: 1402

Console.WriteLine($"Month: {shamsiMonthName}");
// Output: Month: فروردین

Console.WriteLine($"Day: {shamsiDayString}");
// Output: Day: 01

Console.WriteLine($"Day Name: {shamsiDayName}");
// Output: Day Name: سه‌شنبه

Console.WriteLine($"Short Day Name: {shamsiDayShortName}");
// Output: Short Day Name: سه‌

Extension Methods

using PersianDate;

DateTime? dateTime = new DateTime(2023, 10, 5);
DateTimeOffset? dateTimeOffset = new DateTimeOffset(2023, 10, 5, 0, 0, 0, TimeSpan.Zero);

Console.WriteLine(dateTime.ToShamsiDate());        
// Output: 1402/07/13

Console.WriteLine(dateTimeOffset.ToShamsiDate());  
// Output: 1402/07/13

Console.WriteLine(dateTime.ToShortShamsiDate());        
// Output: 02/07/13

Console.WriteLine(dateTimeOffset.ToShortShamsiDate());  
// Output: 02/07/13

Console.WriteLine(dateTime.ToLongShamsiDate());        
// Output: پنجشنبه 13 مهر 1402

Console.WriteLine(dateTimeOffset.ToLongShamsiDate());  
// Output: پنجشنبه 13 مهر 1402

Converting to Gregorian

using PersianDate;

ToGregorian toGregorian = new ToGregorian();

int gregorianYear = toGregorian.GetGregorianYear(1402, 1, 1);
DateTime gregorianDate = toGregorian.ToGregorianDate(1402, 1, 1);
int gregorianMonth = toGregorian.GetGregorianMonth(1402, 1, 1);
int gregorianDay = toGregorian.GetGregorianDay(1402, 1, 1);

Console.WriteLine($"Gregorian Year: {gregorianYear}");
// Output: Gregorian Year: 2023

Console.WriteLine($"Gregorian Date: {gregorianDate}");
// Output: Gregorian Date: 2023-03-21

Console.WriteLine($"Gregorian Month: {gregorianMonth}");
// Output: Gregorian Month: 3

Console.WriteLine($"Gregorian Day: {gregorianDay}");
// Output: Gregorian Day: 21

Supported Platforms

  • .NET 8.0

Getting Started

  1. Install .NET 8.0 SDK
  2. Clone the repository:
    git clone https://github.com/hootanht/PersianDate.git
  3. Navigate to the project directory:
    cd PersianDate
  4. Restore dependencies:
    dotnet restore
  5. Build the project:
    dotnet build
  6. Run tests:
    dotnet test

Version History

Version Changes
1.0.8 Added support for DateTimeOffset in ToGregorian class and updated PersianDateShamsi.cs and ToShamsi.cs accordingly
1.0.6 Added support for .NET 8.0
1.0.4 Added support for .NET 5.0 and 6.0
1.0.3 Changed from .NET Standard 2.0 to .NET 7.0
1.0.2 Improved flexibility
1.0.1 Changed from .NET Standard 2.1 to 2.0 for broader platform support

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.

Support

If you encounter any issues or have questions, please open an issue on GitHub.


Made with ❤️ by Hootan Hemmati

About

Persian Data Library is a library that can be converted Gregorian (Milady) year to Solar Hijri (Shamsi) year in the simplest way!

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages