AlirezaMahDev.Extensions.PersianTimestamp 0.0.1-alpha7

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

AlirezaMahDev.Extensions.PersianTimestamp

Project Description

This project provides a comprehensive implementation of Persian (Jalali) date and time functionality for .NET applications. It offers a strongly-typed, high-performance implementation of Persian calendar operations, including date parsing, formatting, and arithmetic operations.

Key Features

  • PersianDateTime Struct: A value type representing dates and times in the Persian calendar
  • Type Safety: Strongly-typed API for working with Persian dates and times
  • High Performance: Optimized for performance with minimal allocations
  • Modern .NET Integration: Implements modern .NET interfaces like ISpanFormattable, IUtf8SpanFormattable
  • Calendar Support: Built on top of .NET's GregorianCalendar with Persian calendar rules

Core Components

PersianDateTime

A value type that represents a point in time in the Persian calendar system:

  • Implements standard .NET interfaces for consistent behavior
  • Supports parsing and formatting in various formats
  • Provides methods for date and time arithmetic
  • Thread-safe and immutable

PersianDefault

Provides default calendar instances and settings:

  • Calendar: Default GregorianCalendar instance configured for Persian calendar operations

Usage Example

// Create a new PersianDateTime
var persianDate = new PersianDateTime(
    year: 1402,
    month: 10,
    day: 17,
    hour: 14,
    minute: 30,
    second: 0,
    millisecond: 0,
    microsecond: 0,
    DateTimeKind.Local);

// Format the date
string formatted = persianDate.ToString("yyyy/MM/dd HH:mm:ss");
// Output: "1402/10/17 14:30:00"

// Parse a Persian date string
if (PersianDateTime.TryParse("1402/10/17 14:30:00", out var parsedDate))
{
    // Use the parsed date
    Console.WriteLine(parsedDate);
}

// Date arithmetic
var tomorrow = persianDate.AddDays(1);
var lastMonth = persianDate.AddMonths(-1);

Dependencies

  • .NET 10.0: Base framework requirements
  • System.Globalization: For calendar and culture-specific operations

Design Principles

  1. Immutability: All types are immutable for thread safety and predictable behavior
  2. Performance: Optimized for high-performance scenarios with minimal allocations
  3. Consistency: Follows .NET's design patterns for date and time handling
  4. Extensibility: Designed to be extended with additional functionality as needed

Implementation Notes

  • The implementation uses .NET's built-in calendar system for accurate date calculations
  • All operations are culture-aware and respect Persian calendar rules
  • The API is designed to be familiar to .NET developers while providing Persian-specific functionality
  • The code is annotated with nullability attributes for better static analysis

Best Practices

  1. Use Value Types: PersianDateTime is a value type, so it's best used for local variables and method parameters
  2. Format Strings: Use standard .NET format strings for consistent formatting
  3. Error Handling: Always use the TryParse pattern when parsing user input
  4. Time Zones: Be mindful of time zone considerations when working with Persian dates and times
  5. Performance: For high-performance scenarios, use the ISpanFormattable interface to avoid string allocations

Extension Methods

This project also provides extension methods for working with Persian dates and times:

// Convert DateTime to PersianDateTime
var now = DateTime.Now.ToPersianDateTime();

// Convert PersianDateTime to DateTime
DateTime gregorian = now.ToDateTime();

// Get Persian month name
string monthName = now.GetPersianMonthName();

Contributing

Contributions are welcome! Please ensure that any changes maintain backward compatibility and include appropriate unit tests.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.
  • net10.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
0.0.1-alpha7 402 12/8/2025
0.0.1-alpha 275 12/7/2025