namespace Wrapped;
/// Extension members (C# 14 extension blocks).
public static class ListeningExtensions
{
// Members available on every IEnumerable
extension(IEnumerable plays)
{
/// Total time of all plays (an extension property).
public TimeSpan TotalListeningTime
{
get
{
var total = TimeSpan.Zero;
foreach (var play in plays)
{
total += play.Duration;
}
return total;
}
}
/// Number of plays that are not skips.
public int StreamCount
{
get
{
int count = 0;
foreach (var _ in plays.Filter(Filters.Not(Filters.IsSkip)))
{
count++;
}
return count;
}
}
}
// Members available on TimeSpan
extension(TimeSpan time)
{
/// Formats the time span as e.g. "12 h 05 min".
public string ToHoursAndMinutes() => $"{(int)time.TotalHours} h {time.Minutes:00} min";
}
}