PeriodHelper.cs 552 B

12345678910111213141516171819202122
  1. namespace Application.Features.Api.Studio.Helpers;
  2. public static class PeriodHelper
  3. {
  4. public static (DateTime Start, DateTime End) GetRange(string? period)
  5. {
  6. var now = DateTime.UtcNow;
  7. var end = now;
  8. var start = period switch
  9. {
  10. "today" => now.Date,
  11. "week" => now.AddDays(-7),
  12. "month" => now.AddMonths(-1),
  13. "quarter" => now.AddMonths(-3),
  14. "half" => now.AddMonths(-6),
  15. _ => now.AddMonths(-1)
  16. };
  17. return (start, end);
  18. }
  19. }