Show a Persian added-X-ago timestamp on listing cards
Add JalaliDate.TimeAgo(utc) returning «همین حالا»/«۲ ساعت پیش»/«۳ روز پیش»/«۲ هفته پیش»/«۴ ماه پیش»/«۱ سال پیش», and display it (🕒) on the talent, job, and shift cards from their CreatedAt so users can see how recent each listing is. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
{
|
||||
<div class="search-snippet">@snip</div>
|
||||
}
|
||||
<div class="row muted" style="font-size:12px; margin-top:6px;">🕒 @JalaliDate.TimeAgo(Model.CreatedAt)</div>
|
||||
<div class="foot">
|
||||
<span class="pay">@salary</span>
|
||||
<span class="btn btn-outline" style="padding: 6px 14px;">جزئیات</span>
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
<div class="search-snippet">@snip</div>
|
||||
}
|
||||
<partial name="_HourBar" model="Model" />
|
||||
<div class="row muted" style="font-size:12px; margin-top:6px;">🕒 @JalaliDate.TimeAgo(Model.CreatedAt)</div>
|
||||
<div class="foot">
|
||||
<span class="pay">@JalaliDate.PayLabel(Model.PayType, Model.PayAmount, Model.SharePercent)</span>
|
||||
<span class="btn btn-outline" style="padding: 6px 14px;">جزئیات</span>
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<div class="row muted" style="font-size:12px; margin-top:6px;">🕒 @JalaliDate.TimeAgo(Model.CreatedAt)</div>
|
||||
<div class="foot">
|
||||
<span class="pay">@comp</span>
|
||||
<span class="btn btn-outline" style="padding: 6px 14px;">مشاهده و تماس</span>
|
||||
|
||||
@@ -30,6 +30,24 @@ public static class JalaliDate
|
||||
/// needs no timezone database.</summary>
|
||||
public static DateTime ToTehran(DateTime utc) => utc.AddMinutes(210);
|
||||
|
||||
/// <summary>Relative "added X ago" in Persian from a UTC timestamp: «همین حالا»، «۵ دقیقه پیش»،
|
||||
/// «۲ ساعت پیش»، «۳ روز پیش»، «۲ هفته پیش»، «۴ ماه پیش»، «۱ سال پیش».</summary>
|
||||
public static string TimeAgo(DateTime utc)
|
||||
{
|
||||
var span = DateTime.UtcNow - utc;
|
||||
if (span < TimeSpan.Zero) span = TimeSpan.Zero;
|
||||
var mins = (int)span.TotalMinutes;
|
||||
if (mins < 1) return "همین حالا";
|
||||
if (mins < 60) return ToPersianDigits(mins.ToString()) + " دقیقه پیش";
|
||||
var hours = (int)span.TotalHours;
|
||||
if (hours < 24) return ToPersianDigits(hours.ToString()) + " ساعت پیش";
|
||||
var days = (int)span.TotalDays;
|
||||
if (days < 7) return ToPersianDigits(days.ToString()) + " روز پیش";
|
||||
if (days < 30) return ToPersianDigits((days / 7).ToString()) + " هفته پیش";
|
||||
if (days < 365) return ToPersianDigits((days / 30).ToString()) + " ماه پیش";
|
||||
return ToPersianDigits((days / 365).ToString()) + " سال پیش";
|
||||
}
|
||||
|
||||
/// <summary>Jalali date + Tehran time, e.g. «۳۰ خرداد ۱۴۰۵ ۱۶:۲۱» — for UTC-stored timestamps.</summary>
|
||||
public static string DateTimeLabel(DateTime utc)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user