[feature] add min and max at static methods#25
[feature] add min and max at static methods#25itsmuntadhar wants to merge 3 commits intoRobThree:masterfrom
Conversation
|
Hi! I'm not sure why I missed this PR and never replied. I'll look into this soon(-ish) and get back to you. Just wanted to let you know your PR is appreciated and I apologize for missing it. |
|
Things happen :) Will look into solving the conflicts shortly |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces new static methods for generating ULIDs based on a specific DateTimeOffset, allowing users to retrieve the minimum and maximum ULID values for a given time.
- Added Ulid.MinAt and Ulid.MaxAt static methods in Ulid.cs that generate ULIDs with fixed byte arrays for minimum and maximum values.
- Updated the MinValue and MaxValue fields to use the new methods.
- Provided corresponding DateTimeOffset extension methods (NewUlid, MinUlid, MaxUlid) in DateTimeExtensions.cs.
- Updated global.json and VS Code settings files for configuration.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| global.json | Updated SDK version configuration. |
| NUlid/Ulid.cs | Added static methods for ULID generation with min/max values and updated MinValue/MaxValue fields. |
| NUlid/DateTimeExtensions.cs | Added extension methods for DateTimeOffset to generate ULIDs. |
| .vscode/settings.json | Configured default solution for VS Code. |
| /// <param name="time">The <see cref="DateTimeOffset"/> to use for the time-part of the <see cref="Ulid"/>.</param> | ||
| /// <returns>Returns a new <see cref="Ulid"/>.</returns> | ||
| public static Ulid MinAt(DateTimeOffset time) | ||
| => new(time, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); |
There was a problem hiding this comment.
[nitpick] Consider extracting the fixed byte array [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] into a static readonly field to avoid new allocations on each call.
| => new(time, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); | |
| => new(time, MinBytes); |
| public static Ulid MaxAt(DateTimeOffset time) | ||
| => new(time, new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }); |
There was a problem hiding this comment.
[nitpick] Consider extracting the fixed byte array [255, 255, 255, 255, 255, 255, 255, 255, 255, 255] into a static readonly field to avoid new allocations on each call.
| public static Ulid MaxAt(DateTimeOffset time) | |
| => new(time, new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }); | |
| private static readonly byte[] MaxBytes = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; | |
| public static Ulid MaxAt(DateTimeOffset time) | |
| => new(time, MaxBytes); |
First, I would like to say thanks for the great work!
We've been looking into ULID to use instead of UUID/GUID in our projects and figured we could get rid of the dedicated "CreatedAt" column/prop that we usually have.
To make querying easier, we thought such methods would be great to have in the lib so we could do something like
Was also looking into writing a couple more extensions, maybe in another PR.
Basically
Thanks again