Fix seasonal deadline business day handling
TaxBaik CI/CD / build-and-deploy (push) Successful in 2m22s
TaxBaik CI/CD / build-and-deploy (push) Successful in 2m22s
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
namespace TaxBaik.Application.Seasonal;
|
||||
|
||||
public static class BusinessDayCalculator
|
||||
{
|
||||
private static readonly HashSet<DateOnly> HolidayDates = new()
|
||||
{
|
||||
// 2026
|
||||
new DateOnly(2026, 1, 1),
|
||||
new DateOnly(2026, 2, 16),
|
||||
new DateOnly(2026, 2, 17),
|
||||
new DateOnly(2026, 2, 18),
|
||||
new DateOnly(2026, 3, 1),
|
||||
new DateOnly(2026, 3, 2),
|
||||
new DateOnly(2026, 5, 5),
|
||||
new DateOnly(2026, 5, 25),
|
||||
new DateOnly(2026, 6, 6),
|
||||
new DateOnly(2026, 8, 15),
|
||||
new DateOnly(2026, 8, 16),
|
||||
new DateOnly(2026, 8, 17),
|
||||
new DateOnly(2026, 9, 24),
|
||||
new DateOnly(2026, 9, 25),
|
||||
new DateOnly(2026, 9, 26),
|
||||
new DateOnly(2026, 10, 3),
|
||||
new DateOnly(2026, 10, 4),
|
||||
new DateOnly(2026, 10, 5),
|
||||
new DateOnly(2026, 10, 9),
|
||||
new DateOnly(2026, 12, 25),
|
||||
|
||||
// 2027
|
||||
new DateOnly(2027, 1, 1),
|
||||
new DateOnly(2027, 2, 6),
|
||||
new DateOnly(2027, 2, 7),
|
||||
new DateOnly(2027, 2, 8),
|
||||
new DateOnly(2027, 2, 9),
|
||||
new DateOnly(2027, 3, 1),
|
||||
new DateOnly(2027, 3, 2),
|
||||
new DateOnly(2027, 5, 5),
|
||||
new DateOnly(2027, 5, 13),
|
||||
new DateOnly(2027, 6, 6),
|
||||
new DateOnly(2027, 8, 15),
|
||||
new DateOnly(2027, 8, 16),
|
||||
new DateOnly(2027, 9, 14),
|
||||
new DateOnly(2027, 9, 15),
|
||||
new DateOnly(2027, 9, 16),
|
||||
new DateOnly(2027, 10, 3),
|
||||
new DateOnly(2027, 10, 4),
|
||||
new DateOnly(2027, 10, 9),
|
||||
new DateOnly(2027, 10, 10),
|
||||
new DateOnly(2027, 10, 11),
|
||||
new DateOnly(2027, 12, 25),
|
||||
new DateOnly(2027, 12, 26)
|
||||
};
|
||||
|
||||
public static DateOnly GetEffectiveBusinessDate(DateOnly date)
|
||||
{
|
||||
var effectiveDate = date;
|
||||
while (!IsBusinessDay(effectiveDate))
|
||||
{
|
||||
effectiveDate = effectiveDate.AddDays(1);
|
||||
}
|
||||
|
||||
return effectiveDate;
|
||||
}
|
||||
|
||||
public static int GetBusinessDayDiff(DateOnly date, DateOnly referenceDate)
|
||||
{
|
||||
var effectiveDate = GetEffectiveBusinessDate(date);
|
||||
return effectiveDate.DayNumber - referenceDate.DayNumber;
|
||||
}
|
||||
|
||||
private static bool IsBusinessDay(DateOnly date)
|
||||
=> date.DayOfWeek is not DayOfWeek.Saturday and not DayOfWeek.Sunday
|
||||
&& !HolidayDates.Contains(date);
|
||||
}
|
||||
@@ -15,7 +15,8 @@ public class SeasonalMarketingService
|
||||
|
||||
if (today >= start && today <= end)
|
||||
{
|
||||
var days = (end - today).Days;
|
||||
var effectiveEnd = BusinessDayCalculator.GetEffectiveBusinessDate(DateOnly.FromDateTime(end)).ToDateTime(TimeOnly.MinValue);
|
||||
var days = BusinessDayCalculator.GetBusinessDayDiff(DateOnly.FromDateTime(end), DateOnly.FromDateTime(today));
|
||||
return new CurrentSeasonDto
|
||||
{
|
||||
Key = season.Key,
|
||||
@@ -27,7 +28,7 @@ public class SeasonalMarketingService
|
||||
RelatedCategorySlug = season.RelatedCategorySlug,
|
||||
CtaText = season.CtaText,
|
||||
DaysUntilDeadline = days,
|
||||
Deadline = end
|
||||
Deadline = effectiveEnd
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,7 +368,6 @@ catch (Exception ex)
|
||||
|
||||
app.UsePathBase("/taxbaik");
|
||||
app.UseResponseCompression();
|
||||
app.UseBlazorFrameworkFiles();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseRateLimiter();
|
||||
|
||||
Reference in New Issue
Block a user