2019-07-30 12:58:08 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2022-06-17 15:37:17 +08:00
#nullable disable
2019-07-30 12:58:08 +08:00
using System ;
using System.Globalization ;
using Humanizer ;
namespace osu.Game.Utils
{
public static class HumanizerUtils
{
/// <summary>
2019-08-28 19:15:28 +08:00
/// Turns the current or provided date into a human readable sentence
2019-07-30 12:58:08 +08:00
/// </summary>
2019-08-28 19:15:28 +08:00
/// <param name="input">The date to be humanized</param>
/// <returns>distance of time in words</returns>
public static string Humanize ( DateTimeOffset input )
2019-07-30 12:58:08 +08:00
{
2019-08-28 19:15:28 +08:00
// this works around https://github.com/xamarin/xamarin-android/issues/2012 and https://github.com/Humanizr/Humanizer/issues/690#issuecomment-368536282
2019-07-30 12:58:08 +08:00
try
{
2019-08-28 19:15:28 +08:00
return input . Humanize ( ) ;
2019-07-30 12:58:08 +08:00
}
catch ( ArgumentException )
{
2019-08-28 19:15:28 +08:00
return input . Humanize ( culture : new CultureInfo ( "en-US" ) ) ;
2019-07-30 12:58:08 +08:00
}
}
}
}