diff --git a/README.md b/README.md
index 1ac9131..a86bcd1 100644
--- a/README.md
+++ b/README.md
@@ -266,3 +266,12 @@ var persianDate = islamicDate.ToPersianDateOnly().ToString();
// Print the Persian date
Console.WriteLine(persianDate);
```
+### Enhanced DateOnly Support in Persia.Net
+With this enhancement, you can directly convert a `DateOnly` object to a `PersianDateTime` or an `IslamicDateTime` object. This means you no longer need to first convert `DateOnly` to a `DateTime` object before converting to `PersianDateTime` or `IslamicDateTime`. This reduces the steps involved, making your code more efficient and readable.
+
+Here’s an example of how you can now directly convert a `DateOnly` object to a `PersianDateTime`:
+```csharp
+DateOnly dateOnly = // a DateOnly object comes from...;
+PersianDateTime persianDate = dateOnly.ToPersianDateTime();
+```
+All the `DateTime` extensions that have been introduced by Persia.Net have also been extended to the `DateOnly` struct. That is, all the methods and properties you’re accustomed to using with `DateTime` objects are now directly accessible on `DateOnly` objects.
diff --git a/src/Persia.Net.Test/IslamicDateOnlyTests.cs b/src/Persia.Net.Test/IslamicDateOnlyTests.cs
new file mode 100644
index 0000000..9d82a47
--- /dev/null
+++ b/src/Persia.Net.Test/IslamicDateOnlyTests.cs
@@ -0,0 +1,24 @@
+namespace Persia.Net.Test;
+
+public class IslamicDateOnlyTests
+{
+ [Fact]
+ public void Test_ConvertToIslamicDate_ReturnCorrectDate()
+ {
+ // Arrange
+ DateOnly nonNullableDate = new DateOnly(2024, 03, 26);
+ DateOnly? nullableDate = new DateOnly(2024, 03, 26);
+
+ // Act
+ var convertedNonNullableDate = nonNullableDate.ToIslamicDateTime();
+ var convertedNullableDate = nullableDate.ToIslamicDateTime();
+
+ // Assert
+ Assert.Equal(16, convertedNonNullableDate.Day);
+ Assert.Equal(09, convertedNonNullableDate.Month);
+ Assert.Equal(1445, convertedNonNullableDate.Year);
+ Assert.Equal(16, convertedNullableDate.Day);
+ Assert.Equal(09, convertedNullableDate.Month);
+ Assert.Equal(1445, convertedNullableDate.Year);
+ }
+}
\ No newline at end of file
diff --git a/src/Persia.Net.Test/PersianDateOnlyTests.cs b/src/Persia.Net.Test/PersianDateOnlyTests.cs
new file mode 100644
index 0000000..cc8bc27
--- /dev/null
+++ b/src/Persia.Net.Test/PersianDateOnlyTests.cs
@@ -0,0 +1,67 @@
+namespace Persia.Net.Test;
+
+public class PersianDateOnlyTests
+{
+ [Fact]
+ public void Test_ConvertToPersianDate_ReturnCorrectDate()
+ {
+ // Arrange
+ DateOnly? nullableDate = new DateOnly(2024, 03, 29);
+ DateOnly nonNullableDate = new DateOnly(2024, 03, 29);
+
+ // Act
+ var convertedNullableDate = nullableDate.ToPersianDateTime();
+ var convertedNonNullableDate = nonNullableDate.ToPersianDateTime();
+
+ // Assert
+ Assert.Equal(10, convertedNullableDate.Day);
+ Assert.Equal(1, convertedNullableDate.Month);
+ Assert.Equal(1403, convertedNullableDate.Year);
+
+ Assert.Equal(10, convertedNonNullableDate.Day);
+ Assert.Equal(01, convertedNonNullableDate.Month);
+ Assert.Equal(1403, convertedNonNullableDate.Year);
+ }
+
+ //[Fact]
+ //public void Test_HumanizePersianDateTimePassed_ReturnCorrectText()
+ //{
+ // // Arrange
+ // var date = new DateOnly(2022, 03, 25);
+
+ // // Act
+ // //var humanizedPersian = date.HumanizePassedPersianDateTime();
+ // var humanizedPersian = date.HumanizePassedPersianDateTime(TimeUnit.Days);
+
+ // // Assert
+ // Assert.Equal("۱۱ ماه و ۳۶۲ روز و ۲ ساعت پیش", humanizedPersian);
+ //}
+
+ [Fact]
+ public void Test_GetNextCurrentPreviousDayWeekMonth_ReturnCorrectDate()
+ {
+ // Arrange
+ var date = new DateOnly(2024, 03, 19);
+ DateOnly? nullableDate = new DateOnly(2024, 03, 19);
+
+ // Act
+ var nextDay = nullableDate.NextPersianDay();
+ var prevDay = date.PreviousPersianDay();
+ var currentWeek = date.CurrentPersianWeek();
+ var nextWeek = date.NextPersianWeek();
+ var previousWeek = date.PreviousPersianWeek();
+ var currentMonth = date.CurrentPersianMonth();
+ var nextMonth = date.NextPersianMonth();
+ var previousMonth = date.PreviousPersianMonth();
+
+ // Assert
+ Assert.Equal(new PersianDateTime(1403, 01, 01), nextDay);
+ Assert.Equal(new PersianDateTime(1402, 12, 28), prevDay);
+ Assert.Equal(new PersianDateTime(1403, 01, 01), currentWeek[4]);
+ Assert.Equal(new PersianDateTime(1403, 01, 04), nextWeek[0]);
+ Assert.Equal(new PersianDateTime(1402, 12, 25), previousWeek[6]);
+ Assert.Equal(new PersianDateTime(1402, 12, 26), currentMonth[25]);
+ Assert.Equal(new PersianDateTime(1403, 01, 03), nextMonth[2]);
+ Assert.Equal(new PersianDateTime(1402, 11, 30), previousMonth[29]);
+ }
+}
\ No newline at end of file
diff --git a/src/Persia.Net/Converter.cs b/src/Persia.Net/Converter.cs
index fafc44d..b47bbef 100644
--- a/src/Persia.Net/Converter.cs
+++ b/src/Persia.Net/Converter.cs
@@ -17,6 +17,30 @@ internal static PersianDateTime ConvertToPersian(DateTime date)
// Convert the Julian Day Number to a Persian date
var persianDate = JulianDayToPersian(jd);
+ // Get the progress of the year for the Persian date
+ var (dayOfYear, daysRemainingInYear) = GetYearProgress(persianDate.Year, DateOnly.FromDateTime(date));
+
+ persianDate.SetYearProgress(dayOfYear, daysRemainingInYear);
+ var daysInMonth = GetDaysInPersianMonth(persianDate.Year, persianDate.Month);
+ persianDate.SetDaysInMonth(daysInMonth);
+ var ticks = CalculatePersianTicks(persianDate);
+ persianDate.SetTicks(ticks);
+ return persianDate;
+ }
+
+ ///
+ /// Converts a Gregorian date to a Persian date.
+ ///
+ /// The Gregorian date to be converted.
+ /// A PersianDateTime object representing the converted Persian date.
+ internal static PersianDateTime ConvertToPersian(DateOnly date)
+ {
+ // Convert the Gregorian date to Julian Day Number
+ var jd = GregorianToJulianDay(date.Year, date.Month, date.Day);
+
+ // Convert the Julian Day Number to a Persian date
+ var persianDate = JulianDayToPersian(jd);
+
// Get the progress of the year for the Persian date
var (dayOfYear, daysRemainingInYear) = GetYearProgress(persianDate.Year, date);
@@ -142,7 +166,7 @@ private static DateOnly JulianDayToGregorian(double julianDay)
/// The year in the Persian calendar.
/// The date for which to calculate the year progress.
/// A tuple containing the day of the year and the number of days remaining in the year.
- private static (int DayOfYear, int DaysRemainingInYear) GetYearProgress(int year, DateTime date)
+ private static (int DayOfYear, int DaysRemainingInYear) GetYearProgress(int year, DateOnly date)
{
// Calculate the JDN (Julian Day Number) for the start and end of the year
var jdnStartOfYear = PersianToJulianDay(year, 1, 1);
diff --git a/src/Persia.Net/DateOnly/DateOnlyExtensions.cs b/src/Persia.Net/DateOnly/DateOnlyExtensions.cs
new file mode 100644
index 0000000..e86ad41
--- /dev/null
+++ b/src/Persia.Net/DateOnly/DateOnlyExtensions.cs
@@ -0,0 +1,258 @@
+using System;
+
+namespace Persia.Net;
+
+public static class DateOnlyExtensions
+{
+ ///
+ /// Converts a object to a object.
+ ///
+ /// The object to convert.
+ /// A object that represents the converted date from the object.
+ public static PersianDateTime ToPersianDateTime(this DateOnly dateOnly)
+ {
+ var date = dateOnly.ToDateTime(TimeOnly.MinValue);
+
+ return Converter.ConvertToPersian(date)
+ .SetDayOfWeek((int)date.DayOfWeek);
+ }
+
+ ///
+ /// Converts the date difference between the current date and the provided date into a human-readable format.
+ ///
+ /// The date to calculate the date difference from.
+ /// The number of time parts to include in the output string (e.g., if 3, it might print years, months, and days).
+ /// بعنوان مثال: ۱۱ ماه و ۳۶۲ روز پیش
+ public static string HumanizePassedPersianDateTime(this DateOnly dateOnly, int partsToPrint = 3)
+ {
+ var dtPersianNow = ToPersianDateTime(DateOnly.FromDateTime(DateTime.Now));
+ var dtPersian = ToPersianDateTime(dateOnly);
+
+ var years = dtPersianNow.Year - dtPersian.Year;
+ var months = dtPersianNow.Month - dtPersian.Month;
+ var days = dtPersianNow.DayOfYear - dtPersian.DayOfYear;
+
+ if (days < 0)
+ {
+ months--;
+ days += 30; // Approximation, can be 29, 30 or 31 depending on the month
+ }
+
+ if (months < 0)
+ {
+ years--;
+ months += 12;
+ }
+
+ var result = "";
+
+ if (years > 0 && partsToPrint > 0)
+ {
+ result = $"{years} سال";
+ partsToPrint--;
+ }
+ if (months > 0 && partsToPrint > 0)
+ {
+ if (!string.IsNullOrEmpty(result))
+ result += " و ";
+ result += $"{months} ماه";
+ partsToPrint--;
+ }
+ if (days > 1 && partsToPrint > 0)
+ {
+ if (!string.IsNullOrEmpty(result))
+ result += " و ";
+ result += $"{days} روز";
+ partsToPrint--;
+ }
+
+ return (result + " پیش").ToPersianString(true);
+ }
+
+ ///
+ /// Converts the date difference between the current date and the provided date into a human-readable format in Persian.
+ ///
+ /// The date to calculate the time difference from.
+ /// The unit of time to be used for the calculation. It calculates the total of the given unit time and prints only that unit.
+ /// بعنوان مثال: ۲ روز پیش
+ public static string HumanizePassedPersianDateTime(this DateOnly dateOnly, TimeUnit timeUnit)
+ {
+ var now = DateTime.Now;
+ var dtPersianNow = ToPersianDateTime(DateOnly.FromDateTime(now));
+ var dtPersian = ToPersianDateTime(dateOnly);
+
+ var years = dtPersianNow.Year - dtPersian.Year;
+ var months = years * 12 + dtPersianNow.Month - dtPersian.Month;
+ var days = (int)(now - dateOnly.ToDateTime(TimeOnly.MinValue)).TotalDays;
+
+ var result = "";
+
+ if (timeUnit == TimeUnit.Years)
+ result = $"{years} سال";
+ else if (timeUnit == TimeUnit.Months)
+ result = $"{months} ماه";
+ else if (timeUnit == TimeUnit.Days)
+ result = $"{days} روز";
+
+ return (result + " پیش").ToPersianString(true);
+ }
+
+ ///
+ /// Calculates the next day from the given date and returns it as a .
+ ///
+ /// The date to calculate the next day from.
+ /// A representing the next day.
+ public static PersianDateTime NextPersianDay(this DateOnly dateOnly)
+ {
+ return Converter.ConvertToPersian(dateOnly.AddDays(1))
+ .SetDayOfWeek((int)dateOnly.DayOfWeek);
+ }
+
+ ///
+ /// Calculates the Previous day from the given date and returns it as a PersianDateTime.
+ ///
+ /// The date to calculate the Previous day from.
+ /// A representing the Previous day.
+ public static PersianDateTime PreviousPersianDay(this DateOnly dateOnly)
+ {
+ return Converter.ConvertToPersian(dateOnly.AddDays(-1))
+ .SetDayOfWeek((int)dateOnly.DayOfWeek);
+ }
+
+ ///
+ /// Calculates the dates of the current Persian week for a given date.
+ ///
+ /// The date for which to calculate the current Persian week.
+ /// An array of objects representing each day of the current Persian week.
+ ///
+ /// This method calculates the start of the week based on the Persian calendar, where the week starts on Saturday.
+ /// It then creates a new for each day of the week, starting from the start of the week.
+ ///
+ public static PersianDateTime[] CurrentPersianWeek(this DateOnly dateOnly)
+ {
+ // Here the week starts with Saturday (DayOfWeek.Saturday is 6 in .NET)
+ var startOfWeek = dateOnly.AddDays(-((int)dateOnly.DayOfWeek + 1) % 7);
+ var week = new PersianDateTime[7];
+
+ for (var i = 0; i < 7; i++)
+ week[i] = startOfWeek.AddDays(i).ToPersianDateTime();
+
+ return week;
+ }
+
+ ///
+ /// Calculates the dates of the next Persian week for a given date.
+ ///
+ /// The date for which to calculate the next Persian week.
+ /// An array of objects representing each day of the next Persian week.
+ ///
+ /// This method calculates the start of the next week based on the Persian calendar, where the week starts on Saturday.
+ /// It then creates a new for each day of the week, starting from the start of the next week.
+ ///
+ public static PersianDateTime[] NextPersianWeek(this DateOnly dateOnly)
+ {
+ // Here the week starts with Saturday (DayOfWeek.Saturday is 6 in .NET)
+ var startOfNextWeek = dateOnly.AddDays(-((int)dateOnly.DayOfWeek + 1) % 7 + 7);
+ var week = new PersianDateTime[7];
+
+ for (var i = 0; i < 7; i++)
+ week[i] = startOfNextWeek.AddDays(i).ToPersianDateTime();
+
+ return week;
+ }
+
+ ///
+ /// Calculates the dates of the Previous Persian week for a given date.
+ ///
+ /// The date for which to calculate the Previous Persian week.
+ /// An array of objects representing each day of the Previous Persian week.
+ ///
+ /// This method calculates the start of the Previous week based on the Persian calendar, where the week starts on Saturday.
+ /// It then creates a new for each day of the week, starting from the start of the Previous week.
+ ///
+ public static PersianDateTime[] PreviousPersianWeek(this DateOnly dateOnly)
+ {
+ // Here the week starts with Saturday (DayOfWeek.Saturday is 6 in .NET)
+ var startOfNextWeek = dateOnly.AddDays(-((int)dateOnly.DayOfWeek + 1) % 7 - 7);
+ var week = new PersianDateTime[7];
+
+ for (var i = 0; i < 7; i++)
+ week[i] = startOfNextWeek.AddDays(i).ToPersianDateTime();
+
+ return week;
+ }
+
+ ///
+ /// Calculates the dates of the current Persian month for a given date.
+ ///
+ /// The date for which to calculate the current Persian month.
+ /// An array of objects representing each day of the current Persian month.
+ ///
+ /// This method first converts the given date to a Persian date. It then creates a new for each day of the month, starting from the first day of the month.
+ ///
+ public static PersianDateTime[] CurrentPersianMonth(this DateOnly dateOnly)
+ {
+ var dtPersian = ToPersianDateTime(dateOnly);
+
+ // Create an array to hold the days of the current month
+ var month = new PersianDateTime[dtPersian.DaysInMonth];
+
+ for (var i = 0; i < dtPersian.DaysInMonth; i++)
+ month[i] = new PersianDateTime(dtPersian.Year, dtPersian.Month, i + 1, TimeOnly.MinValue);
+
+ return month;
+ }
+
+ ///
+ /// Calculates the dates of the next Persian month for a given date.
+ ///
+ /// The date for which to calculate the next Persian month.
+ /// An array of objects representing each day of the next Persian month.
+ ///
+ /// This method first converts the given date to a Persian date. It then creates a new for each day of the next month, starting from the first day of the next month.
+ ///
+ public static PersianDateTime[] NextPersianMonth(this DateOnly dateOnly)
+ {
+ var dtPersian = dateOnly.ToPersianDateTime();
+
+ // Add one month to the PersianDateTime
+ dtPersian = dtPersian.Month + 1 == 13
+ ? new PersianDateTime(dtPersian.Year + 1, 1, 1, TimeOnly.MinValue)
+ : new PersianDateTime(dtPersian.Year, dtPersian.Month + 1, 1, TimeOnly.MinValue);
+
+ // Create an array to hold the days of the next month
+ var nextMonth = new PersianDateTime[dtPersian.DaysInMonth];
+
+ for (var i = 0; i < dtPersian.DaysInMonth; i++)
+ nextMonth[i] = new PersianDateTime(dtPersian.Year, dtPersian.Month, i + 1, TimeOnly.MinValue);
+
+ return nextMonth;
+ }
+
+ ///
+ /// Calculates the dates of the Previous Persian month for a given date.
+ ///
+ /// The date for which to calculate the Previous Persian month.
+ /// An array of objects representing each day of the Previous Persian month.
+ ///
+ /// This method first converts the given date to a Persian date. It then creates a new for each day of the Previous month, starting from the first day of the Previous month.
+ ///
+ public static PersianDateTime[] PreviousPersianMonth(this DateOnly dateOnly)
+ {
+ // Convert the date to PersianDateTime
+ var dtPersian = dateOnly.ToPersianDateTime();
+
+ // Subtract one month from the PersianDateTime
+ dtPersian = dtPersian.Month - 1 == 0
+ ? new PersianDateTime(dtPersian.Year - 1, 12, 1, TimeOnly.MinValue)
+ : new PersianDateTime(dtPersian.Year, dtPersian.Month - 1, 1, TimeOnly.MinValue);
+
+ // Create an array to hold the days of the Previous month
+ var nextMonth = new PersianDateTime[dtPersian.DaysInMonth];
+
+ for (var i = 0; i < dtPersian.DaysInMonth; i++)
+ nextMonth[i] = new PersianDateTime(dtPersian.Year, dtPersian.Month, i + 1, TimeOnly.MinValue);
+
+ return nextMonth;
+ }
+}
\ No newline at end of file
diff --git a/src/Persia.Net/DateOnly/DateOnlyIslamicExtensions.cs b/src/Persia.Net/DateOnly/DateOnlyIslamicExtensions.cs
new file mode 100644
index 0000000..c4988e3
--- /dev/null
+++ b/src/Persia.Net/DateOnly/DateOnlyIslamicExtensions.cs
@@ -0,0 +1,17 @@
+namespace Persia.Net;
+
+public static class DateOnlyIslamicExtensions
+{
+ ///
+ /// Converts a object to a object.
+ ///
+ /// The Gregorian DateTime to convert.
+ /// An object representing the converted date.
+ public static IslamicDateTime ToIslamicDateTime(this DateOnly dateOnly)
+ {
+ var date = dateOnly.ToDateTime(TimeOnly.MinValue);
+
+ return Converter.ConvertToIslamic(date)
+ .SetDayOfWeek((int)date.DayOfWeek);
+ }
+}
\ No newline at end of file
diff --git a/src/Persia.Net/DateOnly/NullableDateOnlyExtensions.cs b/src/Persia.Net/DateOnly/NullableDateOnlyExtensions.cs
new file mode 100644
index 0000000..999104e
--- /dev/null
+++ b/src/Persia.Net/DateOnly/NullableDateOnlyExtensions.cs
@@ -0,0 +1,172 @@
+using System;
+
+namespace Persia.Net;
+
+public static class NullableDateOnlyExtensions
+{
+ ///
+ /// Converts a object to a object.
+ ///
+ /// The to convert (nullable). If null, an is thrown
+ /// A representing the converted date.
+ public static PersianDateTime ToPersianDateTime(this DateOnly? dateOnly)
+ {
+ if (!dateOnly.HasValue)
+ throw new ArgumentNullException(nameof(dateOnly));
+
+ return dateOnly.Value.ToPersianDateTime();
+ }
+
+ ///
+ /// Converts the time difference between the current date and the provided date into a human-readable format.
+ ///
+ /// The date to calculate the date difference from. If null, an is thrown.
+ /// The number of time parts to include in the output string (e.g., if 3, it might print years, months, and days).
+ /// بعنوان مثال: ۱۱ ماه و ۳۶۲ روز پیش
+ public static string HumanizePassedPersianDateTime(this DateOnly? dateOnly, int partsToPrint = 3)
+ {
+ if (!dateOnly.HasValue)
+ throw new ArgumentNullException(nameof(dateOnly));
+
+ return dateOnly.Value.HumanizePassedPersianDateTime();
+ }
+
+ ///
+ /// Converts the time difference between the current date and the provided date into a human-readable format in Persian.
+ ///
+ /// The date to calculate the date time difference from. If null, an is thrown.
+ /// The unit of time to be used for the calculation. It calculates the total of the given unit time and prints only that unit.
+ /// A string that represents the time difference in total calculated of given unit time in a human-readable format in Persian.
+ public static string HumanizePassedPersianDateTime(this DateOnly? dateOnly, TimeUnit timeUnit)
+ {
+ if (!dateOnly.HasValue)
+ throw new ArgumentNullException(nameof(dateOnly));
+
+ return dateOnly.Value.HumanizePassedPersianDateTime(timeUnit);
+ }
+
+ ///
+ /// Calculates the next day from the given date and returns it as a .
+ ///
+ /// The date to calculate the next day from. If null, an is thrown.
+ /// A representing the next day.
+ public static PersianDateTime NextPersianDay(this DateOnly? dateOnly)
+ {
+ if (!dateOnly.HasValue)
+ throw new ArgumentNullException(nameof(dateOnly));
+
+ return dateOnly.Value.NextPersianDay();
+ }
+
+ ///
+ /// Calculates the Previous day from the given date and returns it as a PersianDateTime.
+ ///
+ /// The date to calculate the Previous day from. If null, an is thrown.
+ /// A representing the Previous day.
+ public static PersianDateTime PreviousPersianDay(this DateOnly? dateOnly)
+ {
+ if (!dateOnly.HasValue)
+ throw new ArgumentNullException(nameof(dateOnly));
+
+ return dateOnly.Value.PreviousPersianDay();
+ }
+
+ ///
+ /// Calculates the dates of the current Persian week for a given date.
+ ///
+ /// The date for which to calculate the current Persian week. If null, an is thrown.
+ /// An array of objects representing each day of the current Persian week.
+ ///
+ /// This method calculates the start of the week based on the Persian calendar, where the week starts on Saturday.
+ /// It then creates a new for each day of the week, starting from the start of the week.
+ ///
+ public static PersianDateTime[] CurrentPersianWeek(this DateOnly? dateOnly)
+ {
+ if (!dateOnly.HasValue)
+ throw new ArgumentNullException(nameof(dateOnly));
+
+ return dateOnly.Value.CurrentPersianWeek();
+ }
+
+ ///
+ /// Calculates the dates of the next Persian week for a given date.
+ ///
+ /// The date for which to calculate the next Persian week. If null, an is thrown.
+ /// An array of objects representing each day of the next Persian week.
+ ///
+ /// This method calculates the start of the next week based on the Persian calendar, where the week starts on Saturday.
+ /// It then creates a new for each day of the week, starting from the start of the next week.
+ ///
+ public static PersianDateTime[] NextPersianWeek(this DateOnly? dateOnly)
+ {
+ if (!dateOnly.HasValue)
+ throw new ArgumentNullException(nameof(dateOnly));
+
+ return dateOnly.Value.NextPersianWeek();
+ }
+
+ ///
+ /// Calculates the dates of the Previous Persian week for a given date.
+ ///
+ /// The date for which to calculate the Previous Persian week. If null, an is thrown.
+ /// An array of objects representing each day of the Previous Persian week.
+ ///
+ /// This method calculates the start of the Previous week based on the Persian calendar, where the week starts on Saturday.
+ /// It then creates a new for each day of the week, starting from the start of the Previous week.
+ ///
+ public static PersianDateTime[] PreviousPersianWeek(this DateOnly? dateOnly)
+ {
+ if (!dateOnly.HasValue)
+ throw new ArgumentNullException(nameof(dateOnly));
+
+ return dateOnly.Value.PreviousPersianWeek();
+ }
+
+ ///
+ /// Calculates the dates of the current Persian month for a given date.
+ ///
+ /// The date for which to calculate the current Persian month. If null, an is thrown.
+ /// An array of objects representing each day of the current Persian month.
+ ///
+ /// This method first converts the given date to a Persian date. It then creates a new for each day of the month, starting from the first day of the month.
+ ///
+ public static PersianDateTime[] CurrentPersianMonth(this DateOnly? dateOnly)
+ {
+ if (!dateOnly.HasValue)
+ throw new ArgumentNullException(nameof(dateOnly));
+
+ return dateOnly.Value.CurrentPersianMonth();
+ }
+
+ ///
+ /// Calculates the dates of the next Persian month for a given date.
+ ///
+ /// The date for which to calculate the next Persian month. If null, an is thrown.
+ /// An array of objects representing each day of the next Persian month.
+ ///
+ /// This method first converts the given date to a Persian date. It then creates a new for each day of the next month, starting from the first day of the next month.
+ ///
+ public static PersianDateTime[] NextPersianMonth(this DateOnly? dateOnly)
+ {
+ if (!dateOnly.HasValue)
+ throw new ArgumentNullException(nameof(dateOnly));
+
+ return dateOnly.Value.NextPersianMonth();
+ }
+
+ ///
+ /// Calculates the dates of the Previous Persian month for a given date.
+ ///
+ /// The date for which to calculate the Previous Persian month. If null, an is thrown.
+ /// An array of objects representing each day of the Previous Persian month.
+ ///
+ /// This method first converts the given date to a Persian date. It then creates a new for each day of the Previous month, starting from the first day of the Previous month.
+ ///
+ public static PersianDateTime[] PreviousPersianMonth(this DateOnly? dateOnly)
+ {
+ if (!dateOnly.HasValue)
+ throw new ArgumentNullException(nameof(dateOnly));
+
+ return dateOnly.Value.PreviousPersianMonth();
+ }
+}
\ No newline at end of file
diff --git a/src/Persia.Net/DateOnly/NullableDateOnlyIslamicExtensions.cs b/src/Persia.Net/DateOnly/NullableDateOnlyIslamicExtensions.cs
new file mode 100644
index 0000000..a885bdc
--- /dev/null
+++ b/src/Persia.Net/DateOnly/NullableDateOnlyIslamicExtensions.cs
@@ -0,0 +1,16 @@
+namespace Persia.Net;
+
+public static class NullableDateOnlyIslamicExtensions
+{
+ ///
+ /// Converts a object to a .
+ ///
+ /// The object to convert (nullable). If null, an is thrown
+ /// An representing the converted date.
+ public static IslamicDateTime ToIslamicDateTime(this DateOnly? dateOnly)
+ {
+ if (!dateOnly.HasValue)
+ throw new ArgumentNullException(nameof(dateOnly));
+ return dateOnly.Value.ToIslamicDateTime();
+ }
+}
\ No newline at end of file
diff --git a/src/Persia.Net/DateTime/DateTimeExtensions.cs b/src/Persia.Net/DateTime/DateTimeExtensions.cs
index c8eddf7..8cae08f 100644
--- a/src/Persia.Net/DateTime/DateTimeExtensions.cs
+++ b/src/Persia.Net/DateTime/DateTimeExtensions.cs
@@ -114,29 +114,17 @@ public static string HumanizePassedPersianDateTime(this DateTime dateTime, TimeU
var result = "";
if (timeUnit == TimeUnit.Years)
- {
result = $"{years} سال";
- }
else if (timeUnit == TimeUnit.Months)
- {
result = $"{months} ماه";
- }
else if (timeUnit == TimeUnit.Days)
- {
result = $"{days} روز";
- }
else if (timeUnit == TimeUnit.Hours)
- {
result = $"{hours} ساعت";
- }
else if (timeUnit == TimeUnit.Minutes)
- {
result = $"{minutes} دقیقه";
- }
else if (timeUnit == TimeUnit.Seconds)
- {
result = $"{seconds} ثانیه";
- }
return (result + " پیش").ToPersianString(true);
}
@@ -152,7 +140,6 @@ public static PersianDateTime NextPersianDay(this DateTime date)
return Converter.ConvertToPersian(date.AddDays(1))
.SetTime(TimeOnly.FromTimeSpan(date.TimeOfDay))
.SetDayOfWeek((int)date.DayOfWeek);
- //.GetLeapYearStatus();
}
///
diff --git a/src/Persia.Net/DateTime/NullableDateTimeIslamicExtensions.cs b/src/Persia.Net/DateTime/NullableDateTimeIslamicExtensions.cs
index 21a4a20..db4d951 100644
--- a/src/Persia.Net/DateTime/NullableDateTimeIslamicExtensions.cs
+++ b/src/Persia.Net/DateTime/NullableDateTimeIslamicExtensions.cs
@@ -5,7 +5,7 @@ public static class NullableDateTimeIslamicExtensions
///
/// Converts a Gregorian DateTime to a IslamicDateTime.
///
- /// The Gregorian DateTime to convert (nullable).
+ /// The Gregorian DateTime to convert (nullable). If null, an is thrown
/// An IslamicDateTime representing the converted date.
public static IslamicDateTime ToIslamicDateTime(this DateTime? date)
{
diff --git a/src/Persia.Net/Persia.Net.csproj b/src/Persia.Net/Persia.Net.csproj
index 4734da7..5b0b63f 100644
--- a/src/Persia.Net/Persia.Net.csproj
+++ b/src/Persia.Net/Persia.Net.csproj
@@ -7,15 +7,15 @@
latest
Majid Shahabfar
- Persia.Net is a versatile class library designed to seamlessly convert dates between Persian, Gregorian, and Arabic (Hijri) calendars.
+ Persia.Net is a versatile class library designed to seamlessly convert dates between Persian, Gregorian, and Islamic (Lunar Hijri) calendars.
https://github.com/shahabfar/Persia.Net
Persia.Net
Shahabfar
Persia.Net
Majid Shahabfar 2024
- 4.0.8.1
- 4.0.8.1
- 4.0.8.1
+ 4.1
+ 4.1
+ 4.1
persia-icon.png