-
Notifications
You must be signed in to change notification settings - Fork 965
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
added German TimeOnlyToClockNotation #1249
Open
SpocWeb
wants to merge
7
commits into
Humanizr:main
Choose a base branch
from
SpocWeb:SpocWeb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
151a0d8
added German TimeOnlyToClockNotation
SpocWeb 7b6f44b
removed Curlies around single-Line
SpocWeb 8b16f94
adjusted public API, which is udeful on its own.
SpocWeb d41f0bf
fixed FW in ApiApprover/PublicApiApprovalTest.approve_public_api.appr…
SpocWeb 0df5da4
fixed Comments on PR
SpocWeb 9021c0b
merge from origin/main and resolved conflicts
SpocWeb c035163
fixed namespaces
SpocWeb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/Humanizer.Tests.Shared/Localisation/de/TimeToClockNotationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#if NET6_0_OR_GREATER | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
using Xunit; | ||
|
||
namespace Humanizer.Tests.Localisation.de; | ||
|
||
[UseCulture("de-DE")] | ||
[SuppressMessage("ReSharper", "StringLiteralTypo")] | ||
public static class TimeToClockNotationTests | ||
{ | ||
#region [InlineData(0, 0, "")] | ||
|
||
[Theory] | ||
[InlineData(0, 0, "Mitternacht")] | ||
[InlineData(0, 7, "12 Uhr 7 nachts")] | ||
[InlineData(1, 11, "1 Uhr 11 nachts")] | ||
[InlineData(4, 0, "4 Uhr nachts")] | ||
[InlineData(5, 1, "5 Uhr 1 nachts")] | ||
[InlineData(6, 0, "6 Uhr morgens")] | ||
[InlineData(6, 5, "fünf nach 6 morgens")] | ||
[InlineData(7, 10, "zehn nach 7 morgens")] | ||
[InlineData(8, 15, "Viertel nach 8 morgens")] | ||
[InlineData(9, 20, "zwanzig nach 9 morgens")] | ||
[InlineData(10, 25, "fünf vor halb 11 morgens")] | ||
[InlineData(11, 30, "halb 12 morgens")] | ||
[InlineData(12, 00, "Mittag")] | ||
[InlineData(12, 38, "12 Uhr 38 nachmittags")] | ||
[InlineData(12, 35, "fünf nach halb 1 nachmittags")] | ||
[InlineData(15, 40, "zwanzig vor 4 nachmittags")] | ||
[InlineData(17, 45, "Viertel vor 6 nachmittags")] | ||
[InlineData(19, 50, "zehn vor 8 abends")] | ||
[InlineData(21, 0, "9 Uhr abends")] | ||
[InlineData(21, 55, "fünf vor 10 abends")] | ||
[InlineData(22, 59, "10 Uhr 59 abends")] | ||
[InlineData(23, 43, "11 Uhr 43 abends")] | ||
|
||
#endregion [InlineData(0, 0, "")] | ||
|
||
public static void ConvertToClockNotationTimeOnlyStringDe(int hours, int minutes, string expectedResult) | ||
{ | ||
var actualResult = new TimeOnly(hours, minutes).ToClockNotation(); | ||
Assert.Equal(expectedResult, actualResult); | ||
} | ||
|
||
|
||
#region [InlineData(0, 0, "")] | ||
|
||
[Theory] | ||
[InlineData(0, 0, "Mitternacht")] | ||
[InlineData(0, 7, "fünf nach 12 nachts")] | ||
[InlineData(1, 11, "zehn nach 1 nachts")] | ||
[InlineData(4, 0, "4 Uhr nachts")] | ||
[InlineData(5, 1, "5 Uhr nachts")] | ||
[InlineData(6, 0, "6 Uhr morgens")] | ||
[InlineData(6, 5, "fünf nach 6 morgens")] | ||
[InlineData(7, 10, "zehn nach 7 morgens")] | ||
[InlineData(8, 15, "Viertel nach 8 morgens")] | ||
[InlineData(9, 20, "zwanzig nach 9 morgens")] | ||
[InlineData(10, 25, "fünf vor halb 11 morgens")] | ||
[InlineData(11, 30, "halb 12 morgens")] | ||
[InlineData(12, 00, "Mittag")] | ||
[InlineData(12, 38, "zwanzig vor 1 nachmittags")] | ||
[InlineData(12, 35, "fünf nach halb 1 nachmittags")] | ||
[InlineData(15, 40, "zwanzig vor 4 nachmittags")] | ||
[InlineData(17, 45, "Viertel vor 6 nachmittags")] | ||
[InlineData(19, 50, "zehn vor 8 abends")] | ||
[InlineData(21, 0, "9 Uhr abends")] | ||
[InlineData(21, 55, "fünf vor 10 abends")] | ||
[InlineData(22, 59, "11 Uhr abends")] | ||
[InlineData(23, 43, "Viertel vor 12 abends")] | ||
[InlineData(23, 58, "Mitternacht")] | ||
|
||
#endregion [InlineData(0, 0, "")] | ||
|
||
public static void ConvertToRoundedClockNotationTimeOnlyStringPtBr(int hours, int minutes, string expectedResult) | ||
{ | ||
var actualResult = new TimeOnly(hours, minutes).ToClockNotation(ClockNotationRounding.NearestFiveMinutes); | ||
Assert.Equal(expectedResult, actualResult); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Humanizer/Localisation/TimeToClockNotation/DeTimeOnlyToClockNotationConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#if NET6_0_OR_GREATER | ||
|
||
using System; | ||
|
||
namespace Humanizer.Localisation.TimeToClockNotation; | ||
|
||
internal class DeTimeOnlyToClockNotationConverter : ITimeOnlyToClockNotationConverter | ||
{ | ||
/// <summary> Switch to output Digits as Words </summary> | ||
public bool AsWords; | ||
|
||
/// <summary> Used to pre-pend, append or omit the Quarter of the Day </summary> | ||
public bool? PrePendQuarter = false; | ||
|
||
public string Convert(TimeOnly time, ClockNotationRounding roundToNearestFive) | ||
{ | ||
var ret = time.AsClockDe(roundToNearestFive, AsWords); | ||
if (!PrePendQuarter.HasValue | ||
|| ret == German.MidNight | ||
|| ret == German.MidDay) | ||
return ret; | ||
|
||
return PrePendQuarter.Value switch | ||
{ | ||
false => ret + ' ' + time.GetDayQuarterGermanGenitive(), | ||
true => time.GetDayQuarterGermanGenitive() + ' ' + ret | ||
}; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#if NET6_0_OR_GREATER | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Humanizer.Localisation.TimeToClockNotation; | ||
|
||
public static class German | ||
{ | ||
public const string MidNight = "Mitternacht"; | ||
public const string MidDay = "Mittag"; | ||
|
||
public static readonly IReadOnlyList<string> QuarterDay = new[] {"Nacht", "Morgen", "Nachmittag", "Abend"}; | ||
|
||
public static string GetDayQuarterGerman(this TimeOnly time) => QuarterDay[time.Hour / 6]; | ||
public static string GetDayQuarterGermanGenitive(this TimeOnly time) => GetDayQuarterGerman(time).ToLower() + "s"; | ||
|
||
/// <summary> Use 12 Hours but avoid 0 </summary> | ||
private static int NormalizeHour(TimeOnly time) => time.Hour % 12 != 0 ? (time.Hour % 12) : 12; | ||
|
||
[SuppressMessage("ReSharper", "StringLiteralTypo")] | ||
public static string AsClockDe(this TimeOnly time, ClockNotationRounding round, bool asWords = false) | ||
{ | ||
if (round == ClockNotationRounding.NearestFiveMinutes) | ||
{ | ||
var ticks = 5 * TimeSpan.TicksPerMinute; | ||
var quotient = (time.Ticks + ticks / 2) / ticks; | ||
var total = quotient * ticks; | ||
if (total >= TimeSpan.TicksPerDay) | ||
{ | ||
total -= TimeSpan.TicksPerDay; | ||
} | ||
time = new TimeOnly(total); | ||
} | ||
switch (time) | ||
{ | ||
case { Hour: 0, Minute: 0 }: return MidNight; | ||
case { Hour: 12, Minute: 0 }: return MidDay; | ||
} | ||
|
||
var addHour = time.AddHours(1); | ||
var hours = NormalizeHour(time); | ||
var hour = asWords ? hours.ToWords() : hours.ToString(); | ||
var nextHours = NormalizeHour(addHour); | ||
var nextHour = asWords ? nextHours.ToWords() : nextHours.ToString(); | ||
|
||
return time.Minute switch | ||
{ | ||
00 => $"{hour} Uhr", | ||
05 => $"fünf nach {hour}", | ||
10 => $"zehn nach {hour}", | ||
15 => $"Viertel nach {hour}", | ||
20 => $"zwanzig nach {hour}", | ||
25 => $"fünf vor halb {nextHour}", | ||
30 => $"halb {nextHour}", | ||
35 => $"fünf nach halb {nextHour}", | ||
40 => $"zwanzig vor {nextHour}", | ||
45 => $"Viertel vor {nextHour}", | ||
50 => $"zehn vor {nextHour}", | ||
55 => $"fünf vor {nextHour}", | ||
60 => $"{nextHour} Uhr", | ||
_ => $"{hour} Uhr {time.Minute}" //.AsWords() | ||
}; | ||
} | ||
|
||
} | ||
#endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Someone that knows the API policies of the project better than me should decide whether this change is appropriate, considering the existing public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it need to be public? if so can you add some docs that explain the use cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to make it internal for now.