fluentassertions icon indicating copy to clipboard operation
fluentassertions copied to clipboard

DateBuilder that allows DateOnly building too

Open Corniel opened this issue 1 year ago • 5 comments

As illustration of the discussion in #2234

Corniel avatar Aug 27 '23 11:08 Corniel

Qodana for .NET

4 new problems were found

Inspection name Severity Problems
Convert local variable or field into constant (private accessibility) ◽️ Notice 4

💡 Qodana analysis was run in the pull request mode: only the changed files were checked ☁️ View the detailed Qodana report

Contact Qodana team

Contact us at [email protected]

  • Or via our issue tracker: https://jb.gg/qodana-issue
  • Or share your feedback: https://jb.gg/qodana-discussions

github-actions[bot] avatar Aug 27 '23 12:08 github-actions[bot]

@Corniel I like this :)

Although I would suggest to drop the AsOffset() and WithOffset() methods inside the DateBuilder struct, and only use extension methods for this, like:

public static DateTimeOffset WithOffset(this DateTime self, TimeSpan offset) => new(self, offset);
public static DateTimeOffset WithOffset(this DateBuilder self, TimeSpan offset) => new(self, offset);
public static DateTimeOffset AsOffset(this DateTime self) => new(self, 0.Hours());
public static DateTimeOffset AsOffset(this DateBuilder self) => new(self, 0.Hours());

This will address https://github.com/fluentassertions/fluentassertions/issues/2234#issuecomment-1694726115

ITaluone avatar Sep 07 '23 08:09 ITaluone

@Corniel I like this :)

Although I would suggest to drop the AsOffset() and WithOffset() methods inside the DateBuilder struct, and only use extension methods for this, like:

Why define the offset methods as extensions on the date builder? It's only purpose is just to do things like that?!

Corniel avatar Sep 07 '23 14:09 Corniel

Why define the offset methods as extensions on the date builder?

Because it shouldn't matter if you call AsOffset()/WithOffset() after the date "thing" like 10.May(2023).AsOffset() or after the time "thing" like 10.May(2023).At(...).AsOffset().

Now this is not possible, because AsOffset() is not recognized when chaining after At(...). And if you introduce AsOffset() as an extension method, the AsOffset()in the DateBuilder becomes useless.

Do you see my point?

IT-VBFK avatar Sep 07 '23 19:09 IT-VBFK

@IT-VBFK: I ment, that AsOffset should not be an extension for the DateBuilder. For DateTime it should.

Corniel avatar Sep 08 '23 22:09 Corniel