-
-
Notifications
You must be signed in to change notification settings - Fork 25
[feature] add min and max at static methods #25
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
base: master
Are you sure you want to change the base?
[feature] add min and max at static methods #25
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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); |
Copilot uses AI. Check for mistakes.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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); |
Copilot uses AI. Check for mistakes.
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