From 1296b5e1296299a2846e326cb7b5897388209aa2 Mon Sep 17 00:00:00 2001 From: Majid Shahabfar Date: Sat, 23 Mar 2024 23:00:58 +0330 Subject: [PATCH] fix: fixing HumanizePassedPersianDateTime when using time unit for time ellapse less than a day --- src/Persia.Net/DateTimes/DateTimeExtensions.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Persia.Net/DateTimes/DateTimeExtensions.cs b/src/Persia.Net/DateTimes/DateTimeExtensions.cs index 17d9875..6bc1eee 100644 --- a/src/Persia.Net/DateTimes/DateTimeExtensions.cs +++ b/src/Persia.Net/DateTimes/DateTimeExtensions.cs @@ -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 = ""; @@ -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); } + /// /// Calculates the next day from the given date and returns it as a PersianDateTime. ///