Skip to content

Commit

Permalink
Merge pull request #67 from meokullu/localizations_0001
Browse files Browse the repository at this point in the history
v2.3.0 Visual output improvements, locations.
meokullu authored Jan 18, 2024
2 parents 48233a2 + a840e06 commit 323696e
Showing 4 changed files with 132 additions and 31 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -11,6 +11,11 @@
#### Removed
-->

### [2.3.0]

#### Added
* Under `Visualisation.cs` `TextMessage` class is added. `TextSeconOptionalPlural`, `TextMinuteOptionalPlural`, `TextHourOptionalPlural`, `TextDayOptionalPlural`, `TextSecond`, `TextMinute`, `TextHour`, `TextDay`, `TextMinutes`, `TextHours`, `TextDays`, `TextUncalculatable`, `TextNegative`, `TextTooLong`, `TextAnd` and `TextNumberFormatSeperator` can be set to choose what `NameETA(long? etaTimeInMs)`, `NameETAUnsafe(long etaTimeInMs)`, `NameETABetterVisual(long? etaTimeInMs)`, `NameETABetterVisualUnsafe(long etaTimeInMs)`, `NumberFormatETA(long? etaTimeInMs)` and `NumberFormatETAUnsafe(long etaTimeInMs)` methods create string to return.

### [2.2.0]

#### Added
11 changes: 6 additions & 5 deletions CalculateETA/CalculateETA.csproj
Original file line number Diff line number Diff line change
@@ -12,17 +12,18 @@
<PackageIcon>icon.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>
v2.2.0
* Async and reporting modules are added.
v2.3.0
* Under `Visualisation.cs` `TextMessage` class is added. `TextSecondOptionalPlural`, `TextMinuteOptionalPlural`, `TextHourOptionalPlural`, `TextDayOptionalPlural`, `TextSecond`, `TextMinute`, `TextHour`, `TextDay`, `TextMinutes`, `TextHours`, `TextDays`, `TextUncalculatable`, `TextNegative`, `TextTooLong`, `TextAnd` and `TextNumberFormatSeperator` can be set to choose what `NameETA(long? etaTimeInMs)`, `NameETAUnsafe(long etaTimeInMs)`, `NameETABetterVisual(long? etaTimeInMs)`, `NameETABetterVisualUnsafe(long etaTimeInMs)`, `NumberFormatETA(long? etaTimeInMs)` and `NumberFormatETAUnsafe(long etaTimeInMs)` methods create string to return.

See changelog (https://github.com/meokullu/CalculateETA/blob/master/CHANGELOG.md)
</PackageReleaseNotes>
<Version>2.2.0</Version>
<Version>2.3.0</Version>
<Description>CalculateETA is a project to calculate estimated time to arrive on loops whether it is in single-thread or multi-thread applicatons.</Description>
<Copyright>Enes Okullu</Copyright>
<RepositoryType>git</RepositoryType>
<PackageTags>ETA; Time; LeftTime; Iterations; Time-Estimations; Multi-thread; Single-thread; loops</PackageTags>
<AssemblyVersion>2.2.0</AssemblyVersion>
<FileVersion>2.2.0</FileVersion>
<AssemblyVersion>2.3.0</AssemblyVersion>
<FileVersion>2.3.0</FileVersion>
<PackageProjectUrl>https://meokullu.github.io/CalculateETA/</PackageProjectUrl>
<RepositoryUrl>https://github.com/meokullu/CalculateETA</RepositoryUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
145 changes: 120 additions & 25 deletions CalculateETA/src/Visualization.cs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static CalculateETA.CalculateETA.TextMessage;

namespace CalculateETA
{
@@ -28,6 +29,100 @@ public partial class CalculateETA
//
// TimeSpanETA(), NumberFormatETA(), NameETA(), NameETABetterVisual(), TimeSpanETAUnsafe(), NumberFormatETAUnsafe(), NameETAUnsafe() and NameETABetterVisualUnsafe() methods use TimeSpan(long: ticks) constructor.

/// <summary>
/// TextMessage has multiple properties to set text values for naming.
/// Optional parameters are used on methods: <see cref="NameETA(long?)"/> <see cref="NameETAUnsafe(long)"/> <see cref="NameETAAsync(long?)"/>
/// <br />
/// Non-Optional parameters are used on methods: <see cref="NameETABetterVisual(long?)"/> <see cref="NameETABetterVisualUnsafe(long)"/>
/// </summary>
public class TextMessage
{
/// <summary>
/// Stands to indicate second while it could be plural or singular. Default value is " second(s)"
/// </summary>
public static string TextSecondOptionalPlural = " second(s)";

/// <summary>
/// Stands to indicate minute while it could be plural or singular. Default value is " minute(s)"
/// </summary>
public static string TextMinuteOptionalPlural = " minute(s)";

/// <summary>
/// Stands to indicate hour while it could be plural or singular. Default value is " hour(s)"
/// </summary>
public static string TextHourOptionalPlural = " hour(s)";

/// <summary>
/// Stands to indicate day while it could be plural or singular. Default value is " day(s)"
/// </summary>
public static string TextDayOptionalPlural = " day(s)";

/// <summary>
/// Stands to indicate second while it could be singular. Default value is " second"
/// </summary>
public static string TextSecond = " second";

/// <summary>
/// Stands to indicate minute while it could be singular. Default value is " minute"
/// </summary>
public static string TextMinute = " minute";

/// <summary>
/// Stands to indicate hour while it could be singular. Default value is " hour"
/// </summary>
public static string TextHour = " hour";

/// <summary>
/// Stands to indicate day while it could be singular. Default value is " day"
/// </summary>
public static string TextDay = " day";

/// <summary>
/// Stands to indicate second while it could be plural. Default value is " seconds"
/// </summary>
public static string TextSeconds = " seconds";

/// <summary>
/// Stands to indicate minute while it could be plural. Default value is " minutes
/// </summary>
public static string TextMinutes = " minute";

/// <summary>
/// Stands to indicate hour while it could be plural. Default value is " hours
/// </summary>
public static string TextHours = " hours";

/// <summary>
/// Stands to indicate day while it could be plural. Default value is " days
/// </summary>
public static string TextDays = " days";

/// <summary>
/// Stands to indicate uncalculatable while ETA value is not possible to calculate. Default value is "Uncalculatable"
/// </summary>
public static string TextUncalculatable = "Uncalculatable";

/// <summary>
/// Stands to indicate negative while ETA value is negative. Default value is "Negative"
/// </summary>
public static string TextNegative = "Negative";

/// <summary>
/// Stands to indicate too long while ETA value is too long. Default value is "Too long"
/// </summary>
public static string TextTooLong = "Too long";

/// <summary>
/// Stands to indicate and between time indicators. Default value is " and " such as "1 hour and 2 minutes"
/// </summary>
public static string TextAnd = " and ";

/// <summary>
/// Stands to indicate and between time indicators on <see cref="NumberFormatETA(long?)"/> and <see cref="NumberFormatETAUnsafe(long)"/>.
/// </summary>
public static string TextNumberFormatSeparator = ":";
}

/// <summary>
/// Returns estimated time to finish on naming format. (xxx ms or xx second(s) or xx minute(s) and yy (second(s)...) Recommended for high-cpu-intense algorithm
/// </summary>
@@ -39,13 +134,13 @@ public static string NameETA(long? etaTimeInMs)
if (etaTimeInMs == null)
{
// Returning "Uncalculatable" to indicate the given parameter was null.
return "Uncalculatable";
return TextUncalculatable;
}
// Checking if the given parameter is negative.
else if (etaTimeInMs < 0)
{
// Returning "Negative" to indicate the given parameter was negative.
return "Negative";
return TextNegative;
}

// Checking if the given parameter is lower than one second. This is commented out for better performance.
@@ -62,25 +157,25 @@ public static string NameETA(long? etaTimeInMs)
if (ts.TotalSeconds < 60)
{
// Returning ETA as xx second(s).
return $"{ts.Seconds} second(s)";
return $"{ts.Seconds}{TextSecondOptionalPlural}";
}
// Checking if parameter is shorter than one hour.
else if (ts.TotalSeconds < 3600)
{
// Returning ETA as xx minute(s) and yy second(s).
return $"{ts.Minutes} minute(s) and {ts.Seconds} second(s)";
return $"{ts.Minutes}{TextMinuteOptionalPlural}{TextAnd}{ts.Seconds}{TextSecondOptionalPlural}";
}
// Checking if parameter is shorter than one day.
else if (ts.TotalSeconds < 86400)
{
// Returning ETA as xx hours(s) and yy minutes(s).
return $"{ts.Hours} hour(s) and {ts.Minutes} minute(s)";
return $"{ts.Hours}{TextHourOptionalPlural}{TextAnd}{ts.Minutes}{TextMinuteOptionalPlural}";
}
// If parameter is longer than a day.
else
{
// Returning ETA as xx days(s) and yy hour(s).
return $"{ts.Days} day(s) and {ts.Hours} hour(s)";
return $"{ts.Days}{TextDayOptionalPlural}{TextAnd}{ts.Hours}{TextHourOptionalPlural}";
}
}

@@ -98,25 +193,25 @@ public static string NameETAUnsafe(long etaTimeInMs)
if (ts.TotalSeconds < 60)
{
// Returning ETA as xx second(s).
return $"{ts.Seconds} second(s)";
return $"{ts.Seconds}{TextSecondOptionalPlural}";
}
// Checking if parameter is shorter than one hour.
else if (ts.TotalSeconds < 3600)
{
// Returning ETA as xx minute(s) and yy second(s).
return $"{ts.Minutes} minute(s) and {ts.Seconds} second(s)";
return $"{ts.Minutes}{TextMinuteOptionalPlural}{TextAnd}{ts.Seconds}{TextSecondOptionalPlural}";
}
// Checking if parameter is shorter than one day.
else if (ts.TotalSeconds < 86400)
{
// Returning ETA as xx hours(s) and yy minutes(s).
return $"{ts.Hours} hour(s) and {ts.Minutes} minute(s)";
return $"{ts.Hours}{TextHourOptionalPlural}{TextAnd}{ts.Minutes}{TextMinuteOptionalPlural}";
}
// If parameter is longer than a day.
else
{
// Returning ETA as xx days(s) and yy hour(s).
return $"{ts.Days} day(s) and {ts.Hours} hour(s)";
return $"{ts.Days}{TextDayOptionalPlural}{TextAnd}{ts.Hours}{TextHourOptionalPlural}";
}
}

@@ -131,13 +226,13 @@ public static string NameETABetterVisual(long? etaTimeInMs)
if (etaTimeInMs == null)
{
// Returning "Uncalculatable" to indicate the given parameter was null.
return "Uncalculatable";
return TextUncalculatable;
}
// Checking if the given parameter is negative.
else if (etaTimeInMs < 0)
{
// Returning "Negative" to indicate the given parameter was negative.
return "Negative";
return TextNegative;
}

// Checking if parameter is lower than one second. This is commented out for better performance.
@@ -154,25 +249,25 @@ public static string NameETABetterVisual(long? etaTimeInMs)
if (ts.TotalSeconds < 60)
{
// Returning ETA as x second or yy seconds.
return $"{ts.Seconds} {(ts.Seconds != 1 ? "seconds" : "second")}";
return $"{ts.Seconds} {(ts.Seconds != 1 ? TextSeconds : TextSecond)}";
}
// Checking if parameter is shorter than one hour.
else if (ts.TotalSeconds < 3600)
{
// Returning ETA as x minute or xx minutes, y second or yy seconds.
return $"{ts.Minutes} {(ts.Minutes != 1 ? "minutes" : "minute")} and {ts.Seconds} {(ts.Seconds != 1 ? "seconds" : "second")}";
return $"{ts.Minutes} {(ts.Minutes != 1 ? TextMinutes : TextMinute)}{TextAnd}{ts.Seconds} {(ts.Seconds != 1 ? TextSeconds : TextSecond)}";
}
// Checking if parameter is shorter than one day.
else if (ts.TotalSeconds < 86400)
{
// Returning ETA as x hour or xx hours and, y minute or yy minutes.
return $"{ts.Hours} {(ts.Hours != 1 ? "hours" : "hour")} and {ts.Minutes} {(ts.Minutes != 1 ? "minutes" : "minute")}";
return $"{ts.Hours} {(ts.Hours != 1 ? TextHours : TextHour)}{TextAnd}{ts.Minutes} {(ts.Minutes != 1 ? TextMinutes : TextMinute)}";
}
// If parameter is longer than a day.
else
{
// Returning ETA as x day or xx days, y hour and yy hours.
return $"{ts.Days} {(ts.Days != 1 ? "days" : "day")} and {ts.Hours} {(ts.Hours != 1 ? "hours" : "hour")}";
return $"{ts.Days} {(ts.Days != 1 ? TextDays : TextDay)}{TextAnd}{ts.Hours} {(ts.Hours != 1 ? TextHours : TextHour)}";
}
}

@@ -190,25 +285,25 @@ public static string NameETABetterVisualUnsafe(long etaTimeInMs)
if (ts.TotalSeconds < 60)
{
// Returning ETA as x second or yy seconds.
return $"{ts.Seconds} {(ts.Seconds != 1 ? "seconds" : "second")}";
return $"{ts.Seconds} {(ts.Seconds != 1 ? TextSeconds : TextSecond)}";
}
// Checking if parameter is shorter than one hour.
else if (ts.TotalSeconds < 3600)
{
// Returning ETA as x minute or xx minutes, y second or yy seconds.
return $"{ts.Minutes} {(ts.Minutes != 1 ? "minutes" : "minute")} and {ts.Seconds} {(ts.Seconds != 1 ? "seconds" : "second")}";
return $"{ts.Minutes} {(ts.Minutes != 1 ? TextMinutes : TextMinute)}{TextAnd}{ts.Seconds} {(ts.Seconds != 1 ? TextSeconds : TextSecond)}";
}
// Checking if parameter is shorter than one day.
else if (ts.TotalSeconds < 86400)
{
// Returning ETA as x hour or xx hours and, y minute or yy minutes.
return $"{ts.Hours} {(ts.Hours != 1 ? "hours" : "hour")} and {ts.Minutes} {(ts.Minutes != 1 ? "minutes" : "minute")}";
return $"{ts.Hours} {(ts.Hours != 1 ? TextHours : TextHour)}{TextAnd}{ts.Minutes} {(ts.Minutes != 1 ? TextMinutes : TextMinute)}";
}
// If parameter is longer than a day.
else
{
// Returning ETA as x day or xx days, y hour and yy hours.
return $"{ts.Days} {(ts.Days != 1 ? "days" : "day")} and {ts.Hours} {(ts.Hours != 1 ? "hours" : "hour")}";
return $"{ts.Days} {(ts.Days != 1 ? TextDays : TextDay)}{TextAnd}{ts.Hours} {(ts.Hours != 1 ? TextHours : TextHour)}";
}
}

@@ -223,26 +318,26 @@ public static string NumberFormatETA(long? etaTimeInMs)
if (etaTimeInMs == null)
{
// Returning "Uncalculatable" to indicate the given parameter was null.
return "Uncalculatable";
return TextUncalculatable;
}
// Checking if the given parameter is negative.
else if (etaTimeInMs < 0)
{
// Returning "Negative" to indicate the given parameter was negative.
return "Negative";
return TextNegative;
}
// Checking if the given parameter value will result misleading return value. Estimation under 24 hours will return.
else if (etaTimeInMs > 86400000)
{
// Returning "Too long" to indicaate the given parameter value will result estimation more than a day.
return "Too long";
return TextTooLong;
}

// Creating a TimeSpan from TimeSpan(ticks:)
TimeSpan ts = new TimeSpan(ticks: etaTimeInMs.Value * TimeSpan.TicksPerMillisecond);

// Returning ETA in number format. E.g 05:03:24
return $"{ts.Hours}:{ts.Minutes}:{ts.Seconds}";
return $"{ts.Hours}{TextNumberFormatSeparator}{ts.Minutes}{TextNumberFormatSeparator}{ts.Seconds}";
}

/// <summary>
@@ -256,7 +351,7 @@ public static string NumberFormatETAUnsafe(long etaTimeInMs)
TimeSpan ts = new TimeSpan(ticks: etaTimeInMs * TimeSpan.TicksPerMillisecond);

// Returning ETA in number format. E.g 05:03:24
return $"{ts.Hours}:{ts.Minutes}:{ts.Seconds}";
return $"{ts.Hours}{TextNumberFormatSeparator}{ts.Minutes}{TextNumberFormatSeparator}{ts.Seconds}";
}

/// <summary>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -45,4 +45,4 @@ If you'd like to contribute, then contribute. [contributing guide](https://githu
[![Contributors](https://contrib.rocks/image?repo=meokullu/CalculateETA)](https://github.com/meokullu/CalculateETA/graphs/contributors)

### Help
Twitter: Enes Okullu [@enesokullu](https://twitter.com/EnesOkullu)
Twitter: Enes Okullu [@enesokullu](https://twitter.com/EnesOkullu)

0 comments on commit 323696e

Please sign in to comment.