Skip to content
Merged
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
13 changes: 8 additions & 5 deletions std/datetime/date.d
Original file line number Diff line number Diff line change
Expand Up @@ -9986,12 +9986,11 @@ int cmpTimeUnits(string lhs, string rhs) @safe pure
import std.exception : enforce;
import std.format : format;

auto tstrings = timeStrings;
immutable indexOfLHS = countUntil(tstrings, lhs);
immutable indexOfRHS = countUntil(tstrings, rhs);
immutable indexOfLHS = countUntil(timeStrings, lhs);
immutable indexOfRHS = countUntil(timeStrings, rhs);
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, what was the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No reason to make a second copy of the reference when countUntil takes it by value

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough.


enforce(indexOfLHS != -1, format("%s is not a valid TimeString", lhs));
enforce(indexOfRHS != -1, format("%s is not a valid TimeString", rhs));
enforce!DateTimeException(indexOfLHS != -1, format("%s is not a valid TimeString", lhs));
enforce!DateTimeException(indexOfRHS != -1, format("%s is not a valid TimeString", rhs));

if (indexOfLHS < indexOfRHS)
return -1;
Expand All @@ -10004,9 +10003,13 @@ int cmpTimeUnits(string lhs, string rhs) @safe pure
///
@safe pure unittest
{
import std.exception : assertThrown;

assert(cmpTimeUnits("hours", "hours") == 0);
assert(cmpTimeUnits("hours", "weeks") < 0);
assert(cmpTimeUnits("months", "seconds") > 0);

assertThrown!DateTimeException(cmpTimeUnits("month", "second"));
}

@safe unittest
Expand Down