Skip to content

Commit

Permalink
-FIX: Onboarding issue due to minimal time offsets (#122)
Browse files Browse the repository at this point in the history
* -FIX: Onboarding issue due to minimal time offsets; Fixed the same way as in the Java SDK

* Update Function Documentation

* +ADD: A test case for the time offset
  • Loading branch information
Frank-Wiebeler authored and saschadoemer committed Aug 1, 2022
1 parent 4a402cd commit 6d4c481
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public class UtcDataService
/// </summary>
public static string Now => DateTime.UtcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");


/// <summary>
/// Delivering the current date with an offset in seconds using a valid AR format.
/// </summary>
public static string SecondsInThePastFromNow(int offset)
{
return DateTime.UtcNow.AddSeconds(offset*-1).ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
}
/// <summary>
/// Delivering the current date using a timestamp format.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public OnboardResponse Onboard(OnboardParameters onboardParameters, string priva
GatewayId = onboardParameters.GatewayId,
CertificateType = onboardParameters.CertificationType,
TimeZone = UtcDataService.TimeZone,
UtcTimestamp = UtcDataService.Now
UtcTimestamp = UtcDataService.SecondsInThePastFromNow(10)
};

var requestBody = JsonConvert.SerializeObject(onboardingRequest);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Net.Http;
using System.Threading;
using Agrirouter.Impl.Service.Common;
using Agrirouter.Test.Data;
using Agrirouter.Test.Helper;
Expand Down Expand Up @@ -33,5 +35,16 @@ public void GivenExistingOnboardingResponseForTheIdentifierTheServiceShouldReadT
Assert.NotEmpty(onboardingResponse.ConnectionCriteria.Commands);
Assert.NotEmpty(onboardingResponse.ConnectionCriteria.Measures);
}


[Fact]
public void OffsetTimeDiffersFromActualTime()
{
int testOffset = 23;
string firstTime = UtcDataService.Now;
string comparison = UtcDataService.SecondsInThePastFromNow(testOffset);
double difference = (DateTime.Parse(firstTime) - DateTime.Parse(comparison)).TotalSeconds - testOffset;
Assert.True(difference>-0.2 && difference < 0.2); //We need a small time difference to respect the processing time.
}
}
}

0 comments on commit 6d4c481

Please sign in to comment.