Skip to content

Commit

Permalink
Cleanup Selector from DateDiff and DateAdd Filter Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Jan 8, 2024
1 parent f79ffee commit df5257b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
25 changes: 9 additions & 16 deletions Shoko.Server/Filters/Functions/DateAddFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,27 @@ public DateAddFunction()
{
}

public DateAddFunction(FilterExpression<DateTime?> selector, TimeSpan parameter)
public DateAddFunction(FilterExpression<DateTime?> left, TimeSpan parameter)
{
Selector = selector;
Left = left;
Parameter = parameter;
}

public FilterExpression<DateTime?> Selector { get; set; }
public FilterExpression<DateTime?> Left { get; set; }
public TimeSpan Parameter { get; set; }

public override bool TimeDependent => Selector.TimeDependent;
public override bool UserDependent => Selector.UserDependent;
public override bool TimeDependent => Left.TimeDependent;
public override bool UserDependent => Left.UserDependent;
public override string HelpDescription => "This adds a timespan to a date selector";
public override FilterExpressionGroup Group => FilterExpressionGroup.Function;

public FilterExpression<DateTime?> Left
{
get => Selector;
set => Selector = value;
}

public override DateTime? Evaluate(IFilterable filterable, IFilterableUserInfo userInfo)
{
return Selector.Evaluate(filterable, userInfo) + Parameter;
return Left.Evaluate(filterable, userInfo) + Parameter;
}

protected bool Equals(DateAddFunction other)
{
return base.Equals(other) && Equals(Selector, other.Selector) && Parameter.Equals(other.Parameter);
return base.Equals(other) && Equals(Left, other.Left) && Parameter.Equals(other.Parameter);
}

public override bool Equals(object obj)
Expand All @@ -61,7 +54,7 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
return HashCode.Combine(base.GetHashCode(), Selector, Parameter);
return HashCode.Combine(base.GetHashCode(), Left, Parameter);
}

public static bool operator ==(DateAddFunction left, DateAddFunction right)
Expand All @@ -76,6 +69,6 @@ public override int GetHashCode()

public override bool IsType(FilterExpression expression)
{
return expression is DateAddFunction exp && Left.IsType(exp.Left) && Selector.IsType(exp.Selector);
return expression is DateAddFunction exp && Left.IsType(exp.Left);
}
}
24 changes: 9 additions & 15 deletions Shoko.Server/Filters/Functions/DateDiffFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,29 @@ namespace Shoko.Server.Filters.Functions;

public class DateDiffFunction : FilterExpression<DateTime?>, IWithDateSelectorParameter, IWithTimeSpanParameter
{
public DateDiffFunction(FilterExpression<DateTime?> selector, TimeSpan parameter)
public DateDiffFunction(FilterExpression<DateTime?> left, TimeSpan parameter)
{
Selector = selector;
Left = left;
Parameter = parameter;
}
public DateDiffFunction() { }

public FilterExpression<DateTime?> Selector { get; set; }
public FilterExpression<DateTime?> Left { get; set; }
public TimeSpan Parameter { get; set; }

public override bool TimeDependent => Selector.TimeDependent;
public override bool UserDependent => Selector.UserDependent;
public override bool TimeDependent => Left.TimeDependent;
public override bool UserDependent => Left.UserDependent;
public override string HelpDescription => "This subtracts a timespan from a date selector.";
public override FilterExpressionGroup Group => FilterExpressionGroup.Function;

public FilterExpression<DateTime?> Left
{
get => Selector;
set => Selector = value;
}

public override DateTime? Evaluate(IFilterable filterable, IFilterableUserInfo userInfo)
{
return Selector.Evaluate(filterable, userInfo) - Parameter;
return Left.Evaluate(filterable, userInfo) - Parameter;
}

protected bool Equals(DateDiffFunction other)
{
return base.Equals(other) && Equals(Selector, other.Selector) && Parameter.Equals(other.Parameter);
return base.Equals(other) && Equals(Left, other.Left) && Parameter.Equals(other.Parameter);
}

public override bool Equals(object obj)
Expand All @@ -58,7 +52,7 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
return HashCode.Combine(base.GetHashCode(), Selector, Parameter);
return HashCode.Combine(base.GetHashCode(), Left, Parameter);
}

public static bool operator ==(DateDiffFunction left, DateDiffFunction right)
Expand All @@ -73,6 +67,6 @@ public override int GetHashCode()

public override bool IsType(FilterExpression expression)
{
return expression is DateDiffFunction exp && Left.IsType(exp.Left) && Selector.IsType(exp.Selector);
return expression is DateDiffFunction exp && Left.IsType(exp.Left);
}
}

0 comments on commit df5257b

Please sign in to comment.