Skip to content

Commit

Permalink
Merge pull request #246 from kasperk81/patch-1
Browse files Browse the repository at this point in the history
fix time formatting for other cultures
  • Loading branch information
andrueastman authored May 28, 2024
2 parents 173ecb9 + 4cd74fd commit 0787139
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.9.1] - 2024-05-24
## [1.9.3] - 2024-05-28

### Changed

- Fix time formatting for other cultures.

## [1.9.2] - 2024-05-24

### Changed

Expand Down
32 changes: 31 additions & 1 deletion Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Abstractions.Tests.Mocks;
using Moq;
Expand Down Expand Up @@ -259,6 +261,34 @@ public void SetsPathParametersOfTimeType()
Assert.Contains($"%24time=06%3A00%3A00", requestInfo.URI.OriginalString);
}
[Fact]
public void CurrentCultureDoesNotAffectTimeSerialization()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/users{?%24time}"
};

var currentCulture = CultureInfo.CurrentCulture;

// Act
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("da-DK");
var time = new Time(6, 0, 0);
var pathParameters = new Dictionary<string, object>
{
{ "%24time", time }
};

requestInfo.PathParameters = pathParameters;

// Assert
Assert.Contains($"%24time=06%3A00%3A00", requestInfo.URI.OriginalString);

// Cleanup
Thread.CurrentThread.CurrentCulture = currentCulture;
}
[Fact]
public void ThrowsInvalidOperationExceptionWhenBaseUrlNotSet()
{
// Arrange as the request builders would
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Kiota.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageProjectUrl>https://aka.ms/kiota/docs</PackageProjectUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<VersionPrefix>1.9.2</VersionPrefix>
<VersionPrefix>1.9.3</VersionPrefix>
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SignAssembly>false</SignAssembly>
Expand Down
2 changes: 1 addition & 1 deletion src/Time.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public int Second
/// <returns>The string time of day.</returns>
public override string ToString()
{
return this.DateTime.ToString("HH:mm:ss");
return this.DateTime.ToString("HH\\:mm\\:ss");
}
}
}

0 comments on commit 0787139

Please sign in to comment.