Skip to content

Commit

Permalink
Merge pull request #11 from shahabfar/hotfix-HumanizePassedPersianDat…
Browse files Browse the repository at this point in the history
…eTime-TimeUnit

fix: fixing HumanizePassedPersianDateTime when using time unit for ti…
  • Loading branch information
shahabfar committed Mar 23, 2024
2 parents 14819b3 + 1296b5e commit ef9a507
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 ef9a507

Please sign in to comment.