-
-
Notifications
You must be signed in to change notification settings - Fork 27
[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
Open
itsmuntadhar
wants to merge
3
commits into
RobThree:master
Choose a base branch
from
MorabaaSoftwareSolutions:feat/min-max-methods
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dotnet.defaultSolution": "NUlid.sln" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
|
||
namespace NUlid; | ||
|
||
/// <summary> | ||
/// Extension methods for <see cref="DateTime"/> and <see cref="DateTimeOffset"/> to create <see cref="Ulid"/>s. | ||
/// </summary> | ||
public static class DateTimeExtensions | ||
{ | ||
/// <summary> | ||
/// Returns a new <see cref="Ulid"/> based on the current <see cref="DateTime"/> value. | ||
/// </summary> | ||
/// <param name="dateTimeOffset">date time offset to base new ULID upon</param> | ||
/// <returns>A new <see cref="Ulid"/></returns> | ||
public static Ulid NewUlid(this DateTimeOffset dateTimeOffset) | ||
=> Ulid.NewUlid(dateTimeOffset); | ||
|
||
/// <summary> | ||
/// Returns the minimum <see cref="Ulid"/> based on the current <see cref="DateTime"/> value. | ||
/// </summary> | ||
/// <param name="dateTimeOffset">date time offset to base new ULID upon</param> | ||
/// <returns>A new <see cref="Ulid"/></returns> | ||
public static Ulid MinUlid(this DateTimeOffset dateTimeOffset) | ||
=> Ulid.MinAt(dateTimeOffset); | ||
|
||
/// <summary> | ||
/// Returns the maximum <see cref="Ulid"/> based on the current <see cref="DateTime"/> value. | ||
/// </summary> | ||
/// <param name="dateTimeOffset">date time offset to base new ULID upon</param> | ||
/// <returns>A new <see cref="Ulid"/></returns> | ||
public static Ulid MaxUlid(this DateTimeOffset dateTimeOffset) | ||
=> Ulid.MaxAt(dateTimeOffset); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks> | ||
<Authors>RobIII</Authors> | ||
<Company>Devcorner.nl</Company> | ||
<PackageId>NUlid</PackageId> | ||
<NoPackageAnalysis>true</NoPackageAnalysis> | ||
<Product>NUlid</Product> | ||
<Copyright>(C) 2016 - 2025 Devcorner.nl</Copyright> | ||
<Nullable>enable</Nullable> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageProjectUrl>https://github.com/RobThree/NUlid</PackageProjectUrl> | ||
<PackageTags>Universally Unique Lexicographically Sortable Identifier;ULID;UUID;GUID</PackageTags> | ||
<Description>A .Net ULID implementation</Description> | ||
<LangVersion>latest</LangVersion> | ||
<PackageIcon>logo.png</PackageIcon> | ||
<GenerateDocumentationFile>True</GenerateDocumentationFile> | ||
<DocumentationFile>bin\Release\nulid.xml</DocumentationFile> | ||
<Configurations>Debug;Release</Configurations> | ||
<EnableNETAnalyzers>true</EnableNETAnalyzers> | ||
<AnalysisLevel>latest</AnalysisLevel> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<RepositoryUrl>https://github.com/RobThree/NUlid</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks> | ||
<Authors>RobIII</Authors> | ||
<Company>Devcorner.nl</Company> | ||
<PackageId>NUlid</PackageId> | ||
<NoPackageAnalysis>true</NoPackageAnalysis> | ||
<Product>NUlid</Product> | ||
<Copyright>(C) 2016 - 2025 Devcorner.nl</Copyright> | ||
<Nullable>enable</Nullable> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageProjectUrl>https://github.com/RobThree/NUlid</PackageProjectUrl> | ||
<PackageTags>Universally Unique Lexicographically Sortable Identifier;ULID;UUID;GUID</PackageTags> | ||
<Description>A .Net ULID implementation</Description> | ||
<LangVersion>latest</LangVersion> | ||
<PackageIcon>logo.png</PackageIcon> | ||
<GenerateDocumentationFile>True</GenerateDocumentationFile> | ||
<DocumentationFile>bin\Release\nulid.xml</DocumentationFile> | ||
<Configurations>Debug;Release</Configurations> | ||
<EnableNETAnalyzers>true</EnableNETAnalyzers> | ||
<AnalysisLevel>latest</AnalysisLevel> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<RepositoryUrl>https://github.com/RobThree/NUlid</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<DefineConstants>TRACE;RELEASE</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<DefineConstants>TRACE;RELEASE</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net45|AnyCPU'"> | ||
<DocumentationFile>bin\release\NUlid.xml</DocumentationFile> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net45|AnyCPU'"> | ||
<DocumentationFile>bin\release\NUlid.xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"> | ||
<PackageReference Include="System.Memory" Version="4.6.3" /> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"> | ||
<PackageReference Include="System.Memory" Version="4.6.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\logo.png"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
<None Include="..\README.md"> | ||
<Pack>True</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
</ItemGroup> | ||
</Project> | ||
<ItemGroup> | ||
<None Include="..\logo.png"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
<None Include="..\README.md"> | ||
<Pack>True</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,12 +1,13 @@ | ||||||||||||||
using NUlid.Rng; | ||||||||||||||
using System; | ||||||||||||||
using System; | ||||||||||||||
using System.Buffers.Binary; | ||||||||||||||
using System.ComponentModel; | ||||||||||||||
using System.Diagnostics; | ||||||||||||||
using System.Runtime.InteropServices; | ||||||||||||||
using System.Runtime.Serialization; | ||||||||||||||
using NUlid.Rng; | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
#if NET6_0_OR_GREATER | ||||||||||||||
using System.Buffers.Binary; | ||||||||||||||
using System.Runtime.CompilerServices; | ||||||||||||||
using System.Runtime.Intrinsics; | ||||||||||||||
#endif | ||||||||||||||
|
@@ -53,12 +54,12 @@ public struct Ulid : IEquatable<Ulid>, IComparable<Ulid>, IComparable, ISerializ | |||||||||||||
/// <summary> | ||||||||||||||
/// Represents the smallest possible value of <see cref="Ulid"/>. This field is read-only. | ||||||||||||||
/// </summary> | ||||||||||||||
public static readonly Ulid MinValue = new(_epoch, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); | ||||||||||||||
public static readonly Ulid MinValue = MinAt(_epoch); | ||||||||||||||
|
||||||||||||||
/// <summary> | ||||||||||||||
/// Represents the largest possible value of <see cref="Ulid"/>. This field is read-only. | ||||||||||||||
/// </summary> | ||||||||||||||
public static readonly Ulid MaxValue = new(DateTimeOffset.MaxValue, [255, 255, 255, 255, 255, 255, 255, 255, 255, 255]); | ||||||||||||||
public static readonly Ulid MaxValue = MaxAt(DateTimeOffset.MaxValue); | ||||||||||||||
|
||||||||||||||
/// <summary> | ||||||||||||||
/// A read-only instance of the <see cref="Ulid"/> structure whose value is all zeros. | ||||||||||||||
|
@@ -104,6 +105,22 @@ public static Ulid NewUlid(DateTimeOffset time) | |||||||||||||
public static Ulid NewUlid(IUlidRng rng) | ||||||||||||||
=> NewUlid(DateTimeOffset.UtcNow, rng); | ||||||||||||||
|
||||||||||||||
/// <summary> | ||||||||||||||
/// Creates and returns a new <see cref="Ulid"/> that is the minimum possible value for the specified time. | ||||||||||||||
/// </summary> | ||||||||||||||
/// <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 }); | ||||||||||||||
|
||||||||||||||
/// <summary> | ||||||||||||||
/// Creates and returns a new <see cref="Ulid"/> that is the maximum possible value for the specified time. | ||||||||||||||
/// </summary> | ||||||||||||||
/// <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 MaxAt(DateTimeOffset time) | ||||||||||||||
=> new(time, new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }); | ||||||||||||||
Comment on lines
+121
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
|
||||||||||||||
/// <summary> | ||||||||||||||
/// Creates and returns a new <see cref="Ulid"/> based on the specified time and using the specified RNG. | ||||||||||||||
/// </summary> | ||||||||||||||
|
@@ -868,4 +885,4 @@ public readonly string ToString(string? format, IFormatProvider? formatProvider) | |||||||||||||
//public static Ulid FromString(string ulid) => new Ulid(ulid); | ||||||||||||||
//public static implicit operator Ulid(string ulid) => FromString(ulid); | ||||||||||||||
//public static implicit operator string(Ulid ulid) => ulid.ToString(); | ||||||||||||||
} | ||||||||||||||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"sdk": { | ||
"version": "9.0.100", | ||
"allowPrerelease": false, | ||
"rollForward": "latestMinor" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Copilot uses AI. Check for mistakes.