Skip to content

Commit

Permalink
fix: fixing HumanizePassedPersianDateTime when using time unit for ti…
Browse files Browse the repository at this point in the history
…me ellapse less than a day
  • Loading branch information
shahabfar committed Mar 23, 2024
1 parent 14819b3 commit 1296b5e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Persia.Net/DateTimes/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public static string HumanizePassedPersianDateTime(this DateTime dateTime, TimeU
var years = dtPersianNow.Year - dtPersian.Year;
var months = years * 12 + dtPersianNow.Month - dtPersian.Month;
var days = (int)(now - dateTime).TotalDays; // This is an approximation
var hours = (int)(now - dateTime).TotalHours;
var minutes = (int)(now - dateTime).TotalMinutes;
var seconds = (int)(now - dateTime).TotalSeconds;

var result = "";

Expand All @@ -127,20 +130,21 @@ public static string HumanizePassedPersianDateTime(this DateTime dateTime, TimeU
}
else if (timeUnit == TimeUnit.Hours)
{
result = $"{days * 24} ساعت"; // This is an approximation
result = $"{hours} ساعت";
}
else if (timeUnit == TimeUnit.Minutes)
{
result = $"{days * 24 * 60} دقیقه"; // This is an approximation
result = $"{minutes} دقیقه";
}
else if (timeUnit == TimeUnit.Seconds)
{
result = $"{days * 24 * 60 * 60} ثانیه"; // This is an approximation
result = $"{seconds} ثانیه";
}

return (result + " پیش").ToPersianString(true);
}


/// <summary>
/// Calculates the next day from the given date and returns it as a PersianDateTime.
/// </summary>
Expand Down

0 comments on commit 1296b5e

Please sign in to comment.