Datereon 3.0.6

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

Datereon

Datereon is a lightweight .NET library for working with dates, times, cultures, and natural language expressions. It provides culture-aware formatting, safe parsing with multiple formats, relative time helpers, integration with TimeProvider, and support for alternative calendars.


Why Datereon

  • No magic strings: use enum Country and enum NaturalExpression for type safety.
  • Natural language: interpret expressions like NextWeek, Tomorrow, Yesterday.
  • Alternative calendars: Persian, Hebrew, Hijri, and Fiscal.
  • Testability: integration with TimeProvider in .NET.
  • Universal holidays: includes New Year, Christmas, and Easter.

Key Features

  • Natural language expressions
    Allows you to use enums like NextWeek, Tomorrow, InTwoWeeks instead of manual calculations with DateTime.AddDays. This makes the code more expressive and type-safe.

  • TimeProvider integration
    Leverages the modern TimeProvider API for easier unit testing and flexible time handling, something not all date libraries support.

  • Alternative calendars
    Direct conversion to Persian, Hebrew, Hijri, and Fiscal calendars. This is not available natively in .NET without external libraries or manual calculations.

  • CultureResolver
    Avoids “magic strings” for cultures ("fr-FR", "en-US") and uses a Country enum instead. This reduces errors and makes the code more maintainable.

  • Relative helpers
    Methods like Yesterday(), Tomorrow(), Past(10), Future(30) or RelativeFromNow() that return phrases such as “in 5 days” or “4 days ago.” This greatly simplifies relative date logic.

  • HolidayProvider
    Includes algorithms to compute dynamic holidays like Easter Sunday, in addition to fixed ones like New Year and Christmas. In plain .NET you’d have to implement this yourself.


Quick Start

dotnet add package Datereon
  1. Culture formatting

This example shows how to format dates according to different cultures using the CultureResolver and DateService. By resolving a CultureInfo from the Country enum, you can display the same DateTime in region-specific formats without relying on hard-coded strings.


Program.cs:

using System;
using Datereon;

class Program
{
    static void Main()
    {
        // Important: enable UTF-8 output to display non-ASCII characters
        // (e.g., Japanese kanji, Persian month names, Hebrew letters, accented characters).
        Console.OutputEncoding = System.Text.Encoding.UTF8;

        var today = DateTime.Now;

        // Culture resolver with DateFormat
        var ukDate = today.ToFormattedString(DateFormat.LongDate, CultureResolver.UnitedKingdom);
        Console.WriteLine($"Date in United Kingdom format: {ukDate}");

        // Formatting in French with DateFormat
        var formattedDateFrance = today.ToFormattedString(DateFormat.LongDate, CultureResolver.France);
        Console.WriteLine($"Date in French format: {formattedDateFrance}");
    }
}

Output:

Date in United Kingdom format (en-GB): Monday, 27 July 2026
Date in French format (fr-FR): lundi 27 juillet 2026


  1. Natural language expressions

This example demonstrates how Datereon interprets common relative time phrases using the NaturalLanguage API. By passing an enum value like NextWeek, NextMonday, or InTwoWeeks, the library calculates the correct future date without manual arithmetic.


Program.cs:

using System;
using Datereon;

class Program
{
    static void Main()
    {
        // Important: enable UTF-8 output to display non-ASCII characters
        // (e.g., Japanese kanji, Persian month names, Hebrew letters, accented characters).
        Console.OutputEncoding = System.Text.Encoding.UTF8;

        // Next week → US culture (ShortDate)
        var nextWeek = NaturalLanguage.ParseExpression(NaturalExpression.NextWeek)
                                      .ToFormattedString(DateFormat.ShortDate, CultureResolver.UnitedStates);

        // Next Monday → Mexico culture (ShortDate)
        var nextMonday = NaturalLanguage.ParseExpression(NaturalExpression.NextMonday)
                                        .ToFormattedString(DateFormat.ShortDate, CultureResolver.Mexico);

        // In two weeks → France culture (LongDate)
        var inTwoWeeks = NaturalLanguage.ParseExpression(NaturalExpression.InTwoWeeks)
                                        .ToFormattedString(DateFormat.LongDate, CultureResolver.France);

        Console.WriteLine($"Next week (US ShortDate): {nextWeek}");       // 08/03/2026
        Console.WriteLine($"Next Monday (MX ShortDate): {nextMonday}");   // 03/08/2026
        Console.WriteLine($"In two weeks (FR LongDate): {inTwoWeeks}");   // lundi 17 août 2026
    }
}

Output:

Next week (US ShortDate): 08/03/2026
Next Monday (MX ShortDate): 03/08/2026
In two weeks (FR LongDate): lundi 17 août 2026


  1. Flexible parsing

This example illustrates how Datereon can safely parse dates using multiple formats. By providing an array of possible patterns, DateService.TryParseMultipleFormats attempts each format until it finds a match, ensuring robust handling of different input styles without manual checks.


Program.cs:

using System;
using Datereon;

class Program
{
    static void Main()
    {
        // Important: enable UTF-8 output to display non-ASCII characters
        // (e.g., Japanese kanji, Persian month names, Hebrew letters, accented characters).
        Console.OutputEncoding = System.Text.Encoding.UTF8;

        var formats = new[] { DatePattern.yyyy_MM_dd, DatePattern.dd_MM_yyyy, DatePattern.MMMM_dd_yyyy, DatePattern.MMMM_d_yyyy }
        .Select(f => f.ToFormatString())
        .ToArray();

        if (DateService.TryParseMultipleFormats("2026-07-08", formats, CultureResolver.UnitedStates, out var parsed))
        {
            var usDate = parsed.ToFormattedString(DateFormat.ShortDate, CultureResolver.UnitedStates);
            var mxDate = parsed.ToFormattedString(DateFormat.ShortDate, CultureResolver.Mexico);
            var frDate = parsed.ToFormattedString(DateFormat.LongDate, CultureResolver.France);
            var jpDateIso = parsed.ToFormattedString(DateFormat.IsoDate, CultureResolver.Japan);
            var jpDateLong = parsed.ToFormattedString(DateFormat.LongDateTime, CultureResolver.Japan);

            Console.WriteLine($"US format (ShortDate): {usDate}");       // 07/08/2026
            Console.WriteLine($"Mexico format (ShortDate): {mxDate}");  // 08/07/2026
            Console.WriteLine($"France format (LongDate): {frDate}");   // mercredi 8 juillet 2026
            Console.WriteLine($"Japan format (IsoDate): {jpDateIso}");  // 2026-07-08
            Console.WriteLine($"Japan format (LongDateTime): {jpDateLong}"); // 2026年7月8日水曜日 0:00:00
        }
    }
}

Output:

US format (ShortDate): 07/08/2026
Mexico format (ShortDate): 08/07/2026
France format (LongDate): mercredi 8 juillet 2026
Japan format (IsoDate): 2026-07-08
Japan format (LongDateTime): 2026年7月8日水曜日 0:00:00


  1. Alternative calendars

This example highlights Datereon’s ability to convert standard DateTime values into different calendar systems. Using CalendarService, you can easily obtain equivalent dates in the Persian, Hebrew, Hijri, or fiscal calendars, making the library useful for globalized applications and region-specific requirements.


Program.cs:

using System;
using Datereon;

class Program
{
    static void Main()
    {
        // Important: enable UTF-8 output to display non-ASCII characters
        // (e.g., Japanese kanji, Persian month names, Hebrew letters, accented characters).
        Console.OutputEncoding = System.Text.Encoding.UTF8;

        var today = DateTime.Now;

        // Persian calendar → ShortDate
        var persianDateShort = CalendarService.ConvertToPersian(today)
                                              .ToFormattedString(DateFormat.ShortDate, CultureResolver.Persian);

        // Persian calendar → LongDate (month name)
        var persianDateLong = CalendarService.ConvertToPersian(today)
                                             .ToFormattedString(DateFormat.LongDate, CultureResolver.Persian);

        // Hebrew calendar → ShortDate
        var hebrewDateShort = CalendarService.ConvertToHebrew(today)
                                             .ToFormattedString(DateFormat.ShortDate, CultureResolver.Israel);

        // Hebrew calendar → LongDate (month name)
        var hebrewDateLong = CalendarService.ConvertToHebrew(today)
                                            .ToFormattedString(DateFormat.LongDate, CultureResolver.Israel);

        // Hijri calendar → ShortDate
        var hijriDate = CalendarService.ConvertToHijri(today)
                                       .ToFormattedString(DateFormat.ShortDate, CultureResolver.Turkey);

        // Fiscal year → numeric only (no culture)
        var fiscalYear = CalendarService.GetFiscalYear(today);

        Console.WriteLine($"Persian date (ShortDate): {persianDateShort}");   // 1405/5/5
        Console.WriteLine($"Persian date (LongDate): {persianDateLong}");     // Tir 5, 1405
        Console.WriteLine($"Hebrew date (ShortDate): {hebrewDateShort}");     // 5786/4/13
        Console.WriteLine($"Hebrew date (LongDate): {hebrewDateLong}");       // 13 Tammuz 5786
        Console.WriteLine($"Hijri date (ShortDate): {hijriDate}");            // 1447/12/11
        Console.WriteLine($"Fiscal year → numeric only: {fiscalYear}");       // 2026
    }
}


Output:

Persian date (ShortDate): 1405/5/5
Persian date (LongDate): Tir 5, 1405
Hebrew date (ShortDate): 5786/4/13
Hebrew date (LongDate): 13 Tammuz 5786
Hijri date (ShortDate): 1447/12/11
Fiscal year → numeric only: 2026

How to get month names instead of numeric values:

Textual month names like "Tir" or "Tammuz" require a custom formatter; by default .NET prints numeric values.


Program.cs:

using System;
using Datereon;

class Program
{
    static void Main()
    {
        // Important: enable UTF-8 output to display non-ASCII characters
        // (e.g., Japanese kanji, Persian month names, Hebrew letters, accented characters).
        Console.OutputEncoding = System.Text.Encoding.UTF8;

        var today = DateTime.Now;

        // Persian calendar → LongDate (month name)
        var persianDate = CalendarService.ConvertToPersian(today);
        var persianMonthName = persianDate.ToFormattedString(DateFormat.LongDate, CultureResolver.Persian);

        // Hebrew calendar → LongDate (month name)
        var hebrewDate = CalendarService.ConvertToHebrew(today);
        var hebrewMonthName = hebrewDate.ToFormattedString(DateFormat.LongDate, CultureResolver.Israel);

        Console.WriteLine($"Persian month: {persianMonthName}"); // Tir
        Console.WriteLine($"Hebrew month: {hebrewMonthName}");   // Tammuz
    }
}

Output:

Persian month: Tir
Hebrew month: Tammuz


  1. Time zones

This example shows how Datereon converts a DateTime into the local time of a specific country. By using TimeZoneService with the Country enum, you can easily obtain the correct regional time without relying on hard-coded time zone strings.


Program.cs:

using System;
using Datereon;

class Program
{
    static void Main()
    {
        // Important: enable UTF-8 output to display non-ASCII characters
        // (e.g., Japanese kanji, Persian month names, Hebrew letters, accented characters).
        Console.OutputEncoding = System.Text.Encoding.UTF8;

        var tokyoTime = TimeZoneService.ConvertToTimeZone(DateTime.UtcNow, Country.Japan);

        // US culture → LongDateTime
        var tokyoUS = tokyoTime.ToFormattedString(DateFormat.LongDateTime, CultureResolver.UnitedStates);

        // Japan culture → LongDate
        var tokyoJP = tokyoTime.ToFormattedString(DateFormat.LongDate, CultureResolver.Japan);

        Console.WriteLine($"Tokyo time (US LongDateTime): {tokyoUS}"); // Tuesday, July 28, 2026 11:15:00 AM
        Console.WriteLine($"Tokyo time (JP LongDate): {tokyoJP}");     // 2026年7月28日火曜日
    }
}

Output:

Tokyo time (US LongDateTime): Tuesday, July 28, 2026 11:15:00 AM
Tokyo time (JP LongDate): 2026年7月28日火曜日


  1. HolidayProvider

This example demonstrates how Datereon provides access to common holidays. With GetFixedHolidays, you can retrieve fixed-date events like New Year and Christmas, while GetEasterSunday uses an algorithm to compute the correct date for Easter in a given year. This ensures applications can handle both static and dynamic holidays without manual calculations.


Program.cs:

using System;
using Datereon;

class Program
{
    static void Main()
    {
        // Important: enable UTF-8 output to display non-ASCII characters
        // (e.g., Japanese kanji, Persian month names, Hebrew letters, accented characters).
        Console.OutputEncoding = System.Text.Encoding.UTF8;

        var holidays = HolidayProvider.GetFixedHolidays(2026);

        foreach (var h in holidays)
        {
            // US culture → ShortDate
            var holidayUS = h.ToFormattedString(DateFormat.ShortDate, CultureResolver.UnitedStates);
            Console.WriteLine($"Fixed holiday (US): {holidayUS}");

            // Mexico culture → ShortDate
            var holidayMX = h.ToFormattedString(DateFormat.ShortDate, CultureResolver.Mexico);
            Console.WriteLine($"Fixed holiday (MX): {holidayMX}");

            // France culture → LongDate
            var holidayFR = h.ToFormattedString(DateFormat.LongDate, CultureResolver.France);
            Console.WriteLine($"Fixed holiday (FR): {holidayFR}");

            // Japan culture → IsoDate
            var holidayJP = h.ToFormattedString(DateFormat.IsoDate, CultureResolver.Japan);
            Console.WriteLine($"Fixed holiday (JP IsoDate): {holidayJP}");

            // Japan culture → LongDate (month/day names in Japanese)
            var holidayJPText = h.ToFormattedString(DateFormat.LongDate, CultureResolver.Japan);
            Console.WriteLine($"Fixed holiday (JP LongDate): {holidayJPText}");
        }

        // Easter Sunday
        var easterSundayUS = HolidayProvider.GetEasterSunday(2026)
                                            .ToFormattedString(DateFormat.ShortDate, CultureResolver.UnitedStates);
        var easterSundayMX = HolidayProvider.GetEasterSunday(2026)
                                            .ToFormattedString(DateFormat.LongDate, CultureResolver.Mexico);
        var easterSundayFR = HolidayProvider.GetEasterSunday(2026)
                                            .ToFormattedString(DateFormat.LongDateTime, CultureResolver.France);
        var easterSundayJP = HolidayProvider.GetEasterSunday(2026)
                                            .ToFormattedString(DateFormat.IsoDate, CultureResolver.Japan);
        var easterSundayJPText = HolidayProvider.GetEasterSunday(2026)
                                                .ToFormattedString(DateFormat.LongDate, CultureResolver.Japan);

        Console.WriteLine($"Easter Sunday (US): {easterSundayUS}");       // 04/05/2026
        Console.WriteLine($"Easter Sunday (MX): {easterSundayMX}");       // domingo, 5 de abril de 2026
        Console.WriteLine($"Easter Sunday (FR): {easterSundayFR}");       // dimanche 5 avril 2026 00:00:00
        Console.WriteLine($"Easter Sunday (JP IsoDate): {easterSundayJP}"); // 2026-04-05
        Console.WriteLine($"Easter Sunday (JP LongDate): {easterSundayJPText}"); // 2026年4月5日日曜日
    }
}

Output:

Fixed holiday (US): 01/01/2026
Fixed holiday (MX): 01/01/2026
Fixed holiday (FR): mercredi 25 décembre 2026
Fixed holiday (JP IsoDate): 2026-12-25
Fixed holiday (JP LongDate): 2026年12月25日金曜日

Easter Sunday (US): 04/05/2026
Easter Sunday (MX): domingo, 5 de abril de 2026
Easter Sunday (FR): dimanche 5 avril 2026 00:00:00
Easter Sunday (JP IsoDate): 2026-04-05
Easter Sunday (JP LongDate): 2026年4月5日日曜日

Note:

HolidayProvider includes global holidays (New Year, Christmas, Easter) that are widely recognized across countries. These holidays are universal and not tied to any specific country’s calendar.

It does not provide country-specific holidays like Independence Day or regional observances.


  1. TimeProvider integration

This example demonstrates how Datereon leverages the modern .NET TimeProvider API for testable and flexible time handling. By wrapping TimeProvider.System in TimeProviderService, you can retrieve the current UTC time or perform operations like adding days, all while keeping your code easily mockable in unit tests.


Program.cs:

using System;
using Datereon;

class Program
{
    static void Main()
    {
        // Important: enable UTF-8 output to display non-ASCII characters
        // (e.g., Japanese kanji, Persian month names, Hebrew letters, accented characters).
        Console.OutputEncoding = System.Text.Encoding.UTF8;

        var providerService = new TimeProviderService(TimeProvider.System);

        var utcNowUS = providerService.GetUtcNowDateTime()
                                      .ToFormattedString(DateFormat.ShortDate, CultureResolver.UnitedStates);

        var utcNowMX = providerService.GetUtcNowDateTime()
                                      .ToFormattedString(DateFormat.ShortDate, CultureResolver.Mexico);

        var utcNowFR = providerService.GetUtcNowDateTime()
                                      .ToFormattedString(DateFormat.LongDate, CultureResolver.France);

        var plusThreeDaysJP = providerService.AddDaysDateTime(3);

        // Japan → IsoDate
        var jpIso = plusThreeDaysJP.ToFormattedString(DateFormat.IsoDate, CultureResolver.Japan);

        // Japan → LongDate (textual with kanji)
        var jpLong = plusThreeDaysJP.ToFormattedString(DateFormat.LongDate, CultureResolver.Japan);

        Console.WriteLine($"UTC Now (US): {utcNowUS}");   // 07/05/2026
        Console.WriteLine($"UTC Now (MX): {utcNowMX}");   // 05/07/2026
        Console.WriteLine($"UTC Now (FR): {utcNowFR}");   // dimanche 5 juillet 2026
        Console.WriteLine($"+3 days (JP IsoDate): {jpIso}");   // 2026-07-08
        Console.WriteLine($"+3 days (JP LongDate): {jpLong}"); // 2026年7月8日水曜日
    }
}

Output:

UTC Now (US): 07/05/2026
UTC Now (MX): 05/07/2026
UTC Now (FR): dimanche 5 juillet 2026
+3 days (JP IsoDate): 2026-07-08
+3 days (JP LongDate): 2026年7月8日水曜日


  1. Extended Date Methods

This example showcases Datereon’s advanced date operations. With DateService you can perform arithmetic (add, subtract, diff), comparisons (before, after, same), and flexible checks across days, months, or years. Combined with TimeService, you can easily calculate boundaries like the start or end of a month or week, and generate relative outputs such as “in 5 days” or “4 days ago.” These helpers simplify complex date logic into clear, type-safe methods.


Program.cs:

using System;
using Datereon;

class Program
{
    static void Main()
    {
        // Important: enable UTF-8 output to display non-ASCII characters
        // (e.g., Japanese kanji, Persian month names, Hebrew letters, accented characters).
        Console.OutputEncoding = System.Text.Encoding.UTF8;        

        var today = new DateTime(2026, 7, 5);

        // Add 10 days → US culture
        var plusTenDays = DateService.Add(today, 10, DateUnit.Days)
                                     .ToFormattedString(DateFormat.ShortDate, CultureResolver.UnitedStates);

        // Subtract 2 months → Mexico culture
        var minusTwoMonths = DateService.Subtract(today, 2, DateUnit.Months)
                                        .ToFormattedString(DateFormat.ShortDate, CultureResolver.Mexico);

        // Diff in months → numeric only (no culture needed)
        var diffMonths = DateService.Diff(today, new DateTime(2026, 8, 5), DateUnit.Months);

        // Comparisons → boolean values
        var isBefore = DateService.IsBefore(today, new DateTime(2026, 7, 10));
        var isAfter = DateService.IsAfter(today, new DateTime(2026, 7, 1));
        var isSameDay = DateService.IsSame(today, new DateTime(2026, 7, 5), DateUnit.Day);

        // Start of month → France culture
        var startOfMonth = TimeService.StartOfMonth(today)
                                      .ToFormattedString(DateFormat.ShortDate, CultureResolver.France);

        // End of month → Japan culture
        var endOfMonth = TimeService.EndOfMonth(today)
                                    .ToFormattedString(DateFormat.ShortDate, CultureResolver.Japan);

        // Start of week → Canada culture
        var startOfWeek = TimeService.StartOfWeek(today)
                                     .ToFormattedString(DateFormat.ShortDate, CultureResolver.Canada);

        // End of week → Germany culture
        var endOfWeek = TimeService.EndOfWeek(today)
                                   .ToFormattedString(DateFormat.ShortDate, CultureResolver.Germany);

        // Relative outputs → remain textual
        var relativeFuture = TimeService.RelativeFromNow(new DateTime(2026, 7, 10));
        var relativePast = TimeService.RelativeFromNow(new DateTime(2026, 7, 1));

        // Print results with interpolation
        Console.WriteLine($"Plus 10 days (US): {plusTenDays}");          // 07/15/2026
        Console.WriteLine($"Minus 2 months (MX): {minusTwoMonths}");     // 05/05/2026
        Console.WriteLine($"Diff in months: {diffMonths}");              // 1

        Console.WriteLine($"Is before 07/10/2026: {isBefore}");          // True
        Console.WriteLine($"Is after 07/01/2026: {isAfter}");            // True
        Console.WriteLine($"Is same day: {isSameDay}");                  // True

        Console.WriteLine($"Start of month (FR): {startOfMonth}");       // 01/07/2026
        Console.WriteLine($"End of month (JP): {endOfMonth}");           // 2026/07/31
        Console.WriteLine($"Start of week (CA): {startOfWeek}");         // 2026-06-29
        Console.WriteLine($"End of week (DE): {endOfWeek}");             // 05.07.2026

        Console.WriteLine($"Relative future: {relativeFuture}");         // "in 5 days"
        Console.WriteLine($"Relative past: {relativePast}");             // "4 days ago"
    }
}

Output:

Plus 10 days (US): 07/15/2026
Minus 2 months (MX): 05/05/2026
Diff in months: 1
Is before 07/10/2026: True
Is after 07/01/2026: True
Is same day: True
Start of month (FR): 01/07/2026
End of month (JP): 2026/07/31
Start of week (CA): 2026-06-29
End of week (DE): 05.07.2026
Relative future: in 5 days
Relative past: 4 days ago


  1. TimeService helpers

This example highlights Datereon’s built-in shortcuts for common relative dates. With TimeService, you can instantly retrieve values like yesterday, tomorrow, next week, or even offsets such as “past 10 days” or “future 30 days.” These helpers simplify everyday date calculations, making your code more readable and expressive.


Program.cs:

using System;
using Datereon;

class Program
{
    static void Main()
    {
        // Important: enable UTF-8 output to display non-ASCII characters
        // (e.g., Japanese kanji, Persian month names, Hebrew letters, accented characters).
        Console.OutputEncoding = System.Text.Encoding.UTF8;

        // Yesterday → ShortDate (US)
        var yesterday = TimeService.Yesterday()
                                   .ToFormattedString(DateFormat.ShortDate, CultureResolver.UnitedStates);

        // Tomorrow → LongDate (Mexico)
        var tomorrow = TimeService.Tomorrow()
                                  .ToFormattedString(DateFormat.LongDate, CultureResolver.Mexico);

        // Next week → LongDateTime (France)
        var nextWeek = TimeService.NextWeek()
                                  .ToFormattedString(DateFormat.LongDateTime, CultureResolver.France);

        // Day before yesterday → FullDateTimeShort (Germany)
        var dayBeforeYesterday = TimeService.DayBeforeYesterday()
                                            .ToFormattedString(DateFormat.FullDateTimeShort, CultureResolver.Germany);

        // Past 10 days → FullDateTimeLong (Japan)
        var pastTenDays = TimeService.Past(10)
                                     .ToFormattedString(DateFormat.FullDateTimeLong, CultureResolver.Japan);

        // Future 30 days → MonthDay (Canada)
        var futureThirtyDays = TimeService.Future(30)
                                          .ToFormattedString(DateFormat.MonthDay, CultureResolver.Canada);

        // Weekend → YearMonth (Italy)
        var weekend = TimeService.Weekend()
                                 .ToFormattedString(DateFormat.YearMonth, CultureResolver.Italy);

        // Next month → IsoDate (Spain)
        var nextMonth = TimeService.NextMonth()
                                   .ToFormattedString(DateFormat.IsoDate, CultureResolver.Spain);

        // Next year → IsoDateTime (Brazil)
        var nextYear = TimeService.NextYear()
                                  .ToFormattedString(DateFormat.IsoDateTime, CultureResolver.Brazil);

        // Print results with interpolation
        Console.WriteLine($"Yesterday (US ShortDate): {yesterday}");              // 07/26/2026
        Console.WriteLine($"Tomorrow (MX LongDate): {tomorrow}");                 // lunes, 27 de julio de 2026
        Console.WriteLine($"Next week (FR LongDateTime): {nextWeek}");            // lundi 3 août 2026 00:00:00
        Console.WriteLine($"Day before yesterday (DE FullDateTimeShort): {dayBeforeYesterday}"); // Samstag, 25. Juli 2026 00:00
        Console.WriteLine($"Past 10 days (JP FullDateTimeLong): {pastTenDays}");  // 2026年7月17日金曜日 0:00:00
        Console.WriteLine($"Future 30 days (CA MonthDay): {futureThirtyDays}");   // August 26
        Console.WriteLine($"Weekend (IT YearMonth): {weekend}");                  // luglio 2026
        Console.WriteLine($"Next month (ES IsoDate): {nextMonth}");               // 2026-08-27
        Console.WriteLine($"Next year (BR IsoDateTime): {nextYear}");             // 2027-07-27 00:00:00
    }
}

Output:

Yesterday (US ShortDate): 07/26/2026
Tomorrow (MX LongDate): lunes, 27 de julio de 2026
Next week (FR LongDateTime): lundi 3 août 2026 00:00:00
Day before yesterday (DE FullDateTimeShort): Samstag, 25. Juli 2026 00:00
Past 10 days (JP FullDateTimeLong): 2026年7月17日金曜日 0:00:00
Future 30 days (CA MonthDay): August 26
Weekend (IT YearMonth): luglio 2026
Next month (ES IsoDate): 2026-08-27
Next year (BR IsoDateTime): 2027-07-27 00:00:00


Quick Reference Tables

Culture & Parsing

Feature Method/Class Example Output
Culture resolver CultureResolver.Resolve(Country.UnitedKingdom) Sunday, July 5, 2026
Culture formatting DateService.FormatDate(today, CultureResolver.France) Sunday, July 5, 2026
Multiple parsing DateService.TryParseMultipleFormats("2026-07-05", formats, culture, out var parsed) 07/05/2026

Natural Language

Feature Method/Class Example Output
Next week NaturalLanguage.ParseExpression(NaturalExpression.NextWeek) 7/12/2026
Next Monday NaturalLanguage.ParseExpression(NaturalExpression.NextMonday) 7/6/2026
In two weeks NaturalLanguage.ParseExpression(NaturalExpression.InTwoWeeks) 7/19/2026

Calendars & Holidays

Feature Method/Class Example Output
Calendars (Persian) CalendarService.ConvertToPersian(today) 1405/4/14
Calendars (Hebrew) CalendarService.ConvertToHebrew(today) 5786/4/10
Calendars (Hijri) CalendarService.ConvertToHijri(today) 1447/12/9
Fiscal year CalendarService.GetFiscalYear(today) 2026
Universal holidays HolidayProvider.GetFixedHolidays(2026) 1/1/2026, 12/25/2026
Dynamic holiday HolidayProvider.GetEasterSunday(2026) 4/5/2026

Note: outputs are numeric by default. You can also use LongDate or LongDateTime to display textual month/day names (e.g., “Tir”, “Tammuz”, “dimanche”, “2026年12月25日金曜日”).

Time Zones

Feature Method/Class Example Output
Tokyo time TimeZoneService.ConvertToTimeZone(today, Country.Japan) 7/5/2026 21:58:00

TimeService Helpers

Feature Method/Class Example Output
Yesterday TimeService.Yesterday() 7/4/2026
Tomorrow TimeService.Tomorrow() 7/6/2026
Next week TimeService.NextWeek() 7/12/2026
Day before yesterday TimeService.DayBeforeYesterday() 7/3/2026
Past (10 days) TimeService.Past(10) 6/25/2026
Future (30 days) TimeService.Future(30) 8/4/2026
Weekend (Saturday) TimeService.Weekend() 7/11/2026
Next month TimeService.NextMonth() 8/5/2026
Next year TimeService.NextYear() 7/5/2027

Extended Methods

Feature Method/Class Example Output
Add DateService.Add(today, 10, DateUnit.Days) 7/15/2026
Subtract DateService.Subtract(today, 2, DateUnit.Months) 5/5/2026
Diff (months) DateService.Diff(today, new DateTime(2026, 8, 5), DateUnit.Months) 1
Comparisons (IsBefore) DateService.IsBefore(today, new DateTime(2026, 7, 10)) True
Comparisons (IsAfter) DateService.IsAfter(today, new DateTime(2026, 7, 1)) True
Comparisons (IsSame day) DateService.IsSame(today, new DateTime(2026, 7, 5), DateUnit.Day) True
Start of month TimeService.StartOfMonth(today) 7/1/2026
End of month TimeService.EndOfMonth(today) 7/31/2026
Start of week TimeService.StartOfWeek(today) 6/29/2026
End of week TimeService.EndOfWeek(today) 7/5/2026
Relative from now (future) TimeService.RelativeFromNow(new DateTime(2026, 7, 10)) in 5 days
Relative from now (past) TimeService.RelativeFromNow(new DateTime(2026, 7, 1)) 4 days ago

Note: examples show numeric formats for simplicity. For richer cultural outputs, LongDate and LongDateTime can be applied to display localized month/day names (e.g., “Donnerstag, 5. Juli 2026”, “2026年7月31日木曜日”).


Supported Countries

Supported Countries

Country Culture Code
Argentina es-AR
Australia en-AU
Brazil pt-BR
Canada en-CA
Chile es-CL
China zh-CN
Colombia es-CO
Costa Rica es-CR
El Salvador es-SV
France fr-FR
Germany de-DE
India hi-IN
Italy it-IT
Japan ja-JP
Mexico es-MX
Netherlands nl-NL
Peru es-PE
Portugal pt-PT
Singapore en-SG
Spain es-ES
SouthKorea ko-KR
Turkey tr-TR
United Kingdom en-GB
United States en-US

License

This project is freely available under the MIT license.
You may use it without restrictions, as long as you retain the reference to the original license.


Support the Project

If you find this library useful, consider supporting its development:

Buy Me a Coffee

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
3.0.6 111 8/13/2026
3.0.5 106 8/13/2026
3.0.4 113 7/29/2026
3.0.3 107 7/29/2026
3.0.2 112 7/29/2026
3.0.1 102 7/29/2026
3.0.0 109 7/29/2026
2.0.9 117 7/29/2026
2.0.8 113 7/28/2026
2.0.7 112 7/28/2026
2.0.6 103 7/28/2026
2.0.5 118 7/28/2026
2.0.4 103 7/28/2026
2.0.3 103 7/28/2026
2.0.2 99 7/28/2026
2.0.1 105 7/28/2026
2.0.0 104 7/28/2026
1.0.9 103 7/28/2026
1.0.8 334 7/28/2026
1.0.7 107 7/28/2026
Loading failed