Skip to content

Commit

Permalink
Prepare v8.1.0 release (#72)
Browse files Browse the repository at this point in the history
* Fix XML comments

* Update cache payload serialization format to v2 (change timestamp precision to millisecond)

* Update version
  • Loading branch information
adams85 authored Jun 12, 2023
1 parent fe45139 commit 19d647a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
environment:
build_version: 8.0.0
build_version: 8.1.0
version: $(build_version)-{build}
image: Visual Studio 2022
configuration: Release
Expand Down
2 changes: 1 addition & 1 deletion samples/ASP.NETCore/WebApplication/WebApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ItemGroup>
<ProjectReference Include="..\..\..\src\ConfigCatClient\ConfigCatClient.csproj" />
<!-- Use PackageReference instead of the ProjectReference above in your application. -->
<!--<PackageReference Include="ConfigCat.Client" Version="8.0.0" />-->
<!--<PackageReference Include="ConfigCat.Client" Version="8.1.0" />-->
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.*" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.175" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\ConfigCatClient\ConfigCatClient.csproj" />
<!-- Use PackageReference instead of the ProjectReference above in your application. -->
<!--<PackageReference Include="ConfigCat.Client" Version="8.0.0" />-->
<!--<PackageReference Include="ConfigCat.Client" Version="8.1.0" />-->
</ItemGroup>

</Project>
9 changes: 5 additions & 4 deletions src/ConfigCat.Client.Tests/UtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ public void ArrayUtils_ToHexString_Works(byte[] bytes, string expected)
Assert.AreEqual(expected, bytes.ToHexString());
}

[DataRow("-62135596801", -1L)]
[DataRow("-62135596800", 0L)]
[DataRow("-62135596800001", -1L)]
[DataRow("-62135596800000", 0L)]
[DataRow("0", 621355968000000000L)]
[DataRow("+253402300799", 3155378975990000000L)]
[DataRow("+253402300800", -1L)]
[DataRow("+253402300799999", 3155378975999990000L)]
[DataRow("+253402300800000", -1L)]
[DataRow(".0", -1L)]
[DataRow("1.0", -1L)]
[DataRow("1x", -1L)]
[DataTestMethod]
Expand Down
2 changes: 1 addition & 1 deletion src/ConfigCatClient/Logging/LogLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum LogLevel
/// </summary>
Error = 1,
/// <summary>
/// Warning and Error events should be logged. Information and Debug events are discarded.
/// Warning and Error events are logged. Information and Debug events are discarded.
/// </summary>
Warning = 2,
/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/ConfigCatClient/ProjectConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ConfigCat.Client;

internal sealed class ProjectConfig
{
internal const string SerializationFormatVersion = "v1";
internal const string SerializationFormatVersion = "v2";

public static readonly ProjectConfig Empty = new(null, null, DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc), null);

Expand Down Expand Up @@ -40,8 +40,8 @@ public bool IsExpired(TimeSpan expiration)
public static DateTime GenerateTimeStamp()
{
var utcNow = DateTime.UtcNow;
// Remove the sub-second part as we need second precision only.
return utcNow.AddTicks(-(utcNow.Ticks % TimeSpan.TicksPerSecond));
// Remove the sub-millisecond part as we need millisecond precision only.
return utcNow.AddTicks(-(utcNow.Ticks % TimeSpan.TicksPerMillisecond));
}

public static string Serialize(ProjectConfig config)
Expand Down
2 changes: 1 addition & 1 deletion src/ConfigCatClient/RefreshResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace ConfigCat.Client;

/// <summary>
/// Contains the result of a <see cref="IConfigCatClient.ForceRefresh"/> or <see cref="IConfigCatClient.ForceRefreshAsync"/> operation.
/// Contains the result of an <see cref="IConfigCatClient.ForceRefresh"/> or <see cref="IConfigCatClient.ForceRefreshAsync"/> operation.
/// </summary>
public readonly record struct RefreshResult
{
Expand Down
27 changes: 13 additions & 14 deletions src/ConfigCatClient/Utils/DateTimeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ internal static class DateTimeUtils
public static string ToUnixTimeStamp(this DateTime dateTime)
{
#if !NET45
var seconds = new DateTimeOffset(dateTime).ToUnixTimeSeconds();
var milliseconds = new DateTimeOffset(dateTime).ToUnixTimeMilliseconds();
#else
// Based on: https://github.com/dotnet/runtime/blob/v6.0.13/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs#L607
// Based on: https://github.com/dotnet/runtime/blob/v6.0.13/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs#L629

const long unixEpochSeconds = 62_135_596_800L;

var seconds = dateTime.Ticks / TimeSpan.TicksPerSecond - unixEpochSeconds;
const long unixEpochMilliseconds = 62_135_596_800_000L;
var milliseconds = dateTime.Ticks / TimeSpan.TicksPerMillisecond - unixEpochMilliseconds;
#endif

return seconds.ToString(CultureInfo.InvariantCulture);
return milliseconds.ToString(CultureInfo.InvariantCulture);
}

public static bool TryParseUnixTimeStamp(ReadOnlySpan<char> span, out DateTime dateTime)
Expand All @@ -28,33 +27,33 @@ public static bool TryParseUnixTimeStamp(ReadOnlySpan<char> span, out DateTime d
var slice = span.ToString();
#endif

if (!long.TryParse(slice, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var seconds))
if (!long.TryParse(slice, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var milliseconds))
{
dateTime = default;
return false;
}

#if !NET45
try { dateTime = DateTimeOffset.FromUnixTimeSeconds(seconds).UtcDateTime; }
try { dateTime = DateTimeOffset.FromUnixTimeMilliseconds(milliseconds).UtcDateTime; }
catch (ArgumentOutOfRangeException)
{
dateTime = default;
return false;
}
#else
// Based on: https://github.com/dotnet/runtime/blob/v6.0.13/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs#L431
// Based on: https://github.com/dotnet/runtime/blob/v6.0.13/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs#L443

const long unixEpochSeconds = 62_135_596_800L;
const long unixMinSeconds = 0 / TimeSpan.TicksPerSecond - unixEpochSeconds;
const long unixMaxSeconds = 3_155_378_975_999_999_999L / TimeSpan.TicksPerSecond - unixEpochSeconds;
const long unixEpochMilliseconds = 62_135_596_800_000L;
const long unixMinMilliseconds = 0 / TimeSpan.TicksPerMillisecond - unixEpochMilliseconds;
const long unixMaxMilliseconds = 3_155_378_975_999_999_999L / TimeSpan.TicksPerMillisecond - unixEpochMilliseconds;

if (seconds < unixMinSeconds || seconds > unixMaxSeconds)
if (milliseconds < unixMinMilliseconds || milliseconds > unixMaxMilliseconds)
{
dateTime = default;
return false;
}

long ticks = (seconds + unixEpochSeconds) * TimeSpan.TicksPerSecond;
var ticks = (milliseconds + unixEpochMilliseconds) * TimeSpan.TicksPerMillisecond;
dateTime = new DateTime(ticks, DateTimeKind.Utc);
#endif

Expand Down

0 comments on commit 19d647a

Please sign in to comment.