Skip to content

Time struct comparison #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/DateTimeExtensions/TimeOfDay/Time.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,45 @@
if (hoursDiff != 0)
{
return hoursDiff;
}

Check failure on line 115 in src/DateTimeExtensions/TimeOfDay/Time.cs

View workflow job for this annotation

GitHub Actions / build

} expected

public override bool Equals(object obj)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're adding all of these methods in the wrong place, inside the CompareTo method. Move it outside of that method and fix the indentation.

{
if (!(obj is Time))
return false;

var other = (Time)obj;
return this.Hour == other.Hour &&
this.Minute == other.Minute &&
this.Second == other.Second;
}

public override int GetHashCode()
{
return HashCode.Combine(hour, minute, second);
}

public static bool operator ==(Time left, Time right)
{
return left.Equals(right);
}

public static bool operator !=(Time left, Time right)
{
return !(left == right);
}


//Hours are the same, so compare minutes
var minutesDiff = this.Minute.CompareTo(other.Minute);
if (minutesDiff != 0)

Check failure on line 146 in src/DateTimeExtensions/TimeOfDay/Time.cs

View workflow job for this annotation

GitHub Actions / build

Invalid token '!=' in class, record, struct, or interface member declaration

Check failure on line 146 in src/DateTimeExtensions/TimeOfDay/Time.cs

View workflow job for this annotation

GitHub Actions / build

) expected

Check failure on line 146 in src/DateTimeExtensions/TimeOfDay/Time.cs

View workflow job for this annotation

GitHub Actions / build

Tuple must contain at least two elements.

Check failure on line 146 in src/DateTimeExtensions/TimeOfDay/Time.cs

View workflow job for this annotation

GitHub Actions / build

Invalid token 'if' in class, record, struct, or interface member declaration
{
return minutesDiff;

Check failure on line 148 in src/DateTimeExtensions/TimeOfDay/Time.cs

View workflow job for this annotation

GitHub Actions / build

Invalid token ';' in class, record, struct, or interface member declaration
}

//minutes are the same so compare seconds
var secondsDiff = this.Second.CompareTo(other.Second);
if (secondsDiff != 0)

Check failure on line 153 in src/DateTimeExtensions/TimeOfDay/Time.cs

View workflow job for this annotation

GitHub Actions / build

Type or namespace definition, or end-of-file expected

Check failure on line 153 in src/DateTimeExtensions/TimeOfDay/Time.cs

View workflow job for this annotation

GitHub Actions / build

) expected

Check failure on line 153 in src/DateTimeExtensions/TimeOfDay/Time.cs

View workflow job for this annotation

GitHub Actions / build

Tuple must contain at least two elements.

Check failure on line 153 in src/DateTimeExtensions/TimeOfDay/Time.cs

View workflow job for this annotation

GitHub Actions / build

Type or namespace definition, or end-of-file expected
{
return secondsDiff;
}
Expand Down