Skip to content
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

returns 16 chars hex id #62

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/Misc/Curiosity.Tools/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.5.3]

### Changed

- `PublicId.ToPublicId()` returns 16 chars string again

## [1.5.2]

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/Misc/Curiosity.Tools/Curiosity.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<AssemblyVersion>1.0.0</AssemblyVersion>
<FileVersion>1.0.0</FileVersion>
<PackageVersion>1.5.2</PackageVersion>
<PackageVersion>1.5.3</PackageVersion>

<Authors>Max Markelow (@markeli), Andrey Ioch (@DevCorvette)</Authors>
<Company>SIIS Ltd</Company>
Expand Down
11 changes: 4 additions & 7 deletions src/Misc/Curiosity.Tools/UniqueId/PublicId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ public static class PublicId
/// <returns>ID in HEX</returns>
public static string ToPublicId(this long id)
{
// number 17 in the format indicates the minimum number of characters in the string
// number 16 in the format indicates the minimum number of characters in the string
// missing characters are replaced with 0
// by the first 0, we can detect that the number is hexadecimal, even if all numbers are there
// until 2024 year, our UniqueIdGenerator had generated 16 characters string
return id.ToString("x17", CultureInfo.InvariantCulture);
return id.ToString("x16", CultureInfo.InvariantCulture);
}

/// <summary>
Expand Down Expand Up @@ -52,9 +50,8 @@ private static bool IsHexFormat(string line)
return true;
}

// until 2024 year, our UniqueIdGenerator had generated 16 chars string then 17 chars
// always with first 0
if ((line.Length == 16 || line.Length == 17) &&
// our UniqueIdGenerator will generate hex id with first 0 until 2028 year
if ((line.Length == 16) &&
line[0] == '0')
return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@ public void TryParse_Parse16CharsHexLine_LongValue()
id.Should().Be(value);
}

// can detect that line is 17 chars hex and parse it to true long value
[Fact]
public void TryParse_Parse17CharsHexLine_LongValue()
{
// arrange
const long value = 10752219502637056;
const string hex = "00026331630007000"; // 17 chars hex

// act
var canParse = PublicId.TryParse(hex, out var id);

// assert
canParse.Should().Be(true);
id.Should().Be(value);
}

// can detect that line is dec and parse it to true long value
[Fact]
public void TryParse_ParseDecLine_LongValue()
Expand Down
Loading