Skip to content

Commit

Permalink
To switch expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Sep 8, 2023
1 parent a8277b4 commit e95fcc0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ public DateTimeRange Parse(string content, DateTimeOffset relativeBaseTime) {
return null;

date = date.ChangeOffset(relativeBaseTime.Offset);
switch (content.Length) {
case 10:
return new DateTimeRange(date, date.EndOfDay());
case 13:
return new DateTimeRange(date, date.EndOfHour());
case 16:
return new DateTimeRange(date, date.EndOfMinute());
default:
return new DateTimeRange(date, date.EndOfSecond());
}
return content.Length switch {
10 => new DateTimeRange(date, date.EndOfDay()),
13 => new DateTimeRange(date, date.EndOfHour()),
16 => new DateTimeRange(date, date.EndOfMinute()),
_ => new DateTimeRange(date, date.EndOfSecond())
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ internal static class Helper {
internal static readonly List<string> MonthNames = new(new[] { "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" });

internal static TimeSpan GetTimeSpanFromName(string name) {
switch (name.ToLower()) {
case "minutes":
case "minute":
return TimeSpan.FromMinutes(1);
case "hours":
case "hour":
return TimeSpan.FromHours(1);
case "days":
case "day":
return TimeSpan.FromDays(1);
default:
return TimeSpan.Zero;
}
return name.ToLower() switch {
"minutes" => TimeSpan.FromMinutes(1),
"minute" => TimeSpan.FromMinutes(1),
"hours" => TimeSpan.FromHours(1),
"hour" => TimeSpan.FromHours(1),
"days" => TimeSpan.FromDays(1),
"day" => TimeSpan.FromDays(1),
_ => TimeSpan.Zero
};
}

internal static int GetMonthNumber(string name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@ public class ExplicitDatePartParser : IPartParser {
if (!isUpperLimit)
return date;

switch (match.Length) {
case 10:
return date.EndOfDay();
case 13:
return date.EndOfHour();
case 16:
return date.EndOfMinute();
default:
return date;
}
return match.Length switch {
10 => date.EndOfDay(),
13 => date.EndOfHour(),
16 => date.EndOfMinute(),
_ => date
};
}
}
}

0 comments on commit e95fcc0

Please sign in to comment.