Skip to content

Commit 4b04b78

Browse files
fix: DateTime/Timetoken conversion precision loss (#211)
* Fix innacurate DateTime to Unix nanoseconds conversion * Improve DateTime/Unix conversion unit tests + add new one * PubNub SDK v6.19.6.0 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
1 parent 43a3e47 commit 4b04b78

File tree

9 files changed

+40
-21
lines changed

9 files changed

+40
-21
lines changed

.pubnub.yml

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: c-sharp
2-
version: "6.19.5"
2+
version: "6.19.6"
33
schema: 1
44
scm: github.com/pubnub/c-sharp
55
changelog:
6+
- date: 2024-03-28
7+
version: v6.19.6
8+
changes:
9+
- type: bug
10+
text: "Fixes issue of inaccurate DateTime to TimeToken conversion in TranslateDateTimeToPubnubUnixNanoSeconds."
611
- date: 2024-01-17
712
version: v6.19.5
813
changes:
@@ -766,7 +771,7 @@ features:
766771
- QUERY-PARAM
767772
supported-platforms:
768773
-
769-
version: Pubnub 'C#' 6.19.5
774+
version: Pubnub 'C#' 6.19.6
770775
platforms:
771776
- Windows 10 and up
772777
- Windows Server 2008 and up
@@ -776,7 +781,7 @@ supported-platforms:
776781
- .Net Framework 4.5
777782
- .Net Framework 4.6.1+
778783
-
779-
version: PubnubPCL 'C#' 6.19.5
784+
version: PubnubPCL 'C#' 6.19.6
780785
platforms:
781786
- Xamarin.Android
782787
- Xamarin.iOS
@@ -796,7 +801,7 @@ supported-platforms:
796801
- .Net Core
797802
- .Net 6.0
798803
-
799-
version: PubnubUWP 'C#' 6.19.5
804+
version: PubnubUWP 'C#' 6.19.6
800805
platforms:
801806
- Windows Phone 10
802807
- Universal Windows Apps
@@ -820,7 +825,7 @@ sdks:
820825
distribution-type: source
821826
distribution-repository: GitHub
822827
package-name: Pubnub
823-
location: https://github.com/pubnub/c-sharp/releases/tag/v6.19.5.0
828+
location: https://github.com/pubnub/c-sharp/releases/tag/v6.19.6.0
824829
requires:
825830
-
826831
name: ".Net"
@@ -1103,7 +1108,7 @@ sdks:
11031108
distribution-type: source
11041109
distribution-repository: GitHub
11051110
package-name: PubNubPCL
1106-
location: https://github.com/pubnub/c-sharp/releases/tag/v6.19.5.0
1111+
location: https://github.com/pubnub/c-sharp/releases/tag/v6.19.6.0
11071112
requires:
11081113
-
11091114
name: ".Net Core"
@@ -1462,7 +1467,7 @@ sdks:
14621467
distribution-type: source
14631468
distribution-repository: GitHub
14641469
package-name: PubnubUWP
1465-
location: https://github.com/pubnub/c-sharp/releases/tag/v6.19.5.0
1470+
location: https://github.com/pubnub/c-sharp/releases/tag/v6.19.6.0
14661471
requires:
14671472
-
14681473
name: "Universal Windows Platform Development"

CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v6.19.6 - March 28 2024
2+
-----------------------------
3+
- Fixed: fixes issue of inaccurate DateTime to TimeToken conversion in TranslateDateTimeToPubnubUnixNanoSeconds.
4+
15
v6.19.5 - January 17 2024
26
-----------------------------
37
- Fixed: fixes issue of getting exception for custom objects in subscription and history when crypto module is configured.

src/Api/PubnubApi/EndPoint/OtherOperation.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static long TranslateDateTimeToSeconds(DateTime dotNetUTCDateTime)
9797
public static long TranslateDateTimeToPubnubUnixNanoSeconds(DateTime dotNetUTCDateTime)
9898
{
9999
TimeSpan timeSpan = dotNetUTCDateTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
100-
long timeStamp = Convert.ToInt64(timeSpan.TotalSeconds) * 10000000;
100+
long timeStamp = Convert.ToInt64(timeSpan.TotalSeconds * 10000000);
101101
return timeStamp;
102102
}
103103

src/Api/PubnubApi/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
[assembly: AssemblyProduct("Pubnub C# SDK")]
1212
[assembly: AssemblyCopyright("Copyright © 2021")]
1313
[assembly: AssemblyTrademark("")]
14-
[assembly: AssemblyVersion("6.19.5.0")]
15-
[assembly: AssemblyFileVersion("6.19.5.0")]
14+
[assembly: AssemblyVersion("6.19.6.0")]
15+
[assembly: AssemblyFileVersion("6.19.6.0")]
1616
// Setting ComVisible to false makes the types in this assembly not visible
1717
// to COM components. If you need to access a type in this assembly from
1818
// COM, set the ComVisible attribute to true on that type.

src/Api/PubnubApi/PubnubApi.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515
<PropertyGroup>
1616
<PackageId>Pubnub</PackageId>
17-
<PackageVersion>6.19.5.0</PackageVersion>
17+
<PackageVersion>6.19.6.0</PackageVersion>
1818
<Title>PubNub C# .NET - Web Data Push API</Title>
1919
<Authors>Pandu Masabathula</Authors>
2020
<Owners>PubNub</Owners>
2121
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2222
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
2323
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
2424
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
25-
<PackageReleaseNotes>Fixes issue of getting exception for custom objects in subscription and history when crypto module is configured.</PackageReleaseNotes>
25+
<PackageReleaseNotes>Fixes issue of inaccurate DateTime to TimeToken conversion in TranslateDateTimeToPubnubUnixNanoSeconds.</PackageReleaseNotes>
2626
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
2727
<!--<Summary>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Summary>-->
2828
<Description>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Description>

src/Api/PubnubApiPCL/PubnubApiPCL.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
<PropertyGroup>
1717
<PackageId>PubnubPCL</PackageId>
18-
<PackageVersion>6.19.5.0</PackageVersion>
18+
<PackageVersion>6.19.6.0</PackageVersion>
1919
<Title>PubNub C# .NET - Web Data Push API</Title>
2020
<Authors>Pandu Masabathula</Authors>
2121
<Owners>PubNub</Owners>
2222
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2323
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
2424
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
2525
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
26-
<PackageReleaseNotes>Fixes issue of getting exception for custom objects in subscription and history when crypto module is configured.</PackageReleaseNotes>
26+
<PackageReleaseNotes>Fixes issue of inaccurate DateTime to TimeToken conversion in TranslateDateTimeToPubnubUnixNanoSeconds.</PackageReleaseNotes>
2727
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
2828
<!--<Summary>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Summary>-->
2929
<Description>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Description>

src/Api/PubnubApiUWP/PubnubApiUWP.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
<PropertyGroup>
1818
<PackageId>PubnubUWP</PackageId>
19-
<PackageVersion>6.19.5.0</PackageVersion>
19+
<PackageVersion>6.19.6.0</PackageVersion>
2020
<Title>PubNub C# .NET - Web Data Push API</Title>
2121
<Authors>Pandu Masabathula</Authors>
2222
<Owners>PubNub</Owners>
2323
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2424
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
2525
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
2626
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
27-
<PackageReleaseNotes>Fixes issue of getting exception for custom objects in subscription and history when crypto module is configured.</PackageReleaseNotes>
27+
<PackageReleaseNotes>Fixes issue of inaccurate DateTime to TimeToken conversion in TranslateDateTimeToPubnubUnixNanoSeconds.</PackageReleaseNotes>
2828
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
2929
<!--<Summary>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Summary>-->
3030
<Description>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Description>

src/Api/PubnubApiUnity/PubnubApiUnity.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<PropertyGroup>
1717
<PackageId>PubnubApiUnity</PackageId>
18-
<PackageVersion>6.19.5.0</PackageVersion>
18+
<PackageVersion>6.19.6.0</PackageVersion>
1919
<Title>PubNub C# .NET - Web Data Push API</Title>
2020
<Authors>Pandu Masabathula</Authors>
2121
<Owners>PubNub</Owners>

src/UnitTests/PubnubApi.Tests/WhenGetRequestServerTime.cs

+14-4
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,27 @@ public static void ThenWithProxyItShouldReturnTimeStampWithSSL()
285285
public static void TranslateDateTimeToUnixTime()
286286
{
287287
//Test for 26th June 2012 GMT
288-
DateTime dt = new DateTime(2012, 6, 26, 0, 0, 0, DateTimeKind.Utc);
288+
DateTime dt = new DateTime(2012, 6, 26, 21, 37, 13, 37, DateTimeKind.Utc);
289289
long nanoSecondTime = Pubnub.TranslateDateTimeToPubnubUnixNanoSeconds(dt);
290-
Assert.True(13406688000000000 == nanoSecondTime);
290+
Assert.True(13407466330370000 == nanoSecondTime);
291+
}
292+
293+
[Test]
294+
public static void TranslateDateTimeToUnixTimeAndBack()
295+
{
296+
//Test for 26th June 2012 GMT
297+
DateTime expectedDate = new DateTime(2012, 6, 26, 21, 37, 13, 37, DateTimeKind.Utc);
298+
long nanoSecondTime = Pubnub.TranslateDateTimeToPubnubUnixNanoSeconds(expectedDate);
299+
DateTime dateAgain = Pubnub.TranslatePubnubUnixNanoSecondsToDateTime(nanoSecondTime);
300+
Assert.True(expectedDate.Equals(dateAgain));
291301
}
292302

293303
[Test]
294304
public static void TranslateUnixTimeToDateTime()
295305
{
296306
//Test for 26th June 2012 GMT
297-
DateTime expectedDate = new DateTime(2012, 6, 26, 0, 0, 0, DateTimeKind.Utc);
298-
DateTime actualDate = Pubnub.TranslatePubnubUnixNanoSecondsToDateTime(13406688000000000);
307+
DateTime expectedDate = new DateTime(2012, 6, 26, 21, 37, 13, 37, DateTimeKind.Utc);
308+
DateTime actualDate = Pubnub.TranslatePubnubUnixNanoSecondsToDateTime(13407466330370000);
299309
Assert.True(expectedDate == actualDate);
300310
}
301311

0 commit comments

Comments
 (0)