Apply suggested changes

This commit is contained in:
HoutarouOreki
2018-05-23 11:17:13 +02:00
parent 8e9dde97ce
commit 10bc3917b5
2 changed files with 16 additions and 60 deletions

View File

@ -13,61 +13,23 @@ namespace osu.Game.Graphics
public class DrawableDate : OsuSpriteText, IHasTooltip
{
private readonly DateTimeOffset date;
private readonly String dateFormat;
private readonly String tooltipFormat;
private readonly string dateFormat;
private readonly string tooltipFormat;
public DrawableDate(DateTimeOffset date)
public DrawableDate(DateTimeOffset date, string dateFormat = null, string tooltipFormat = null)
{
AutoSizeAxes = Axes.Both;
Font = "Exo2.0-RegularItalic";
this.date = date.ToLocalTime();
// if date's format is not specified, set it to an empty string,
// so that later we will know to humanize it
dateFormat = "";
// if tooltip's format is not specified, set it to an empty string
// so later we will know to default to a default time format
tooltipFormat = "";
}
public DrawableDate(string dateFormat, DateTimeOffset date)
{
AutoSizeAxes = Axes.Both;
Font = "Exo2.0-RegularItalic";
this.date = date.ToLocalTime();
// set a date format for later from an argument
// The string to format the date text with.
// May be null if the humanized format should be used.
this.dateFormat = dateFormat;
// if tooltip's format is not specified, set it to an empty string,
// so later we will know to default to a default time format
tooltipFormat = "";
}
public DrawableDate(DateTimeOffset date, string tooltipFormat)
{
AutoSizeAxes = Axes.Both;
Font = "Exo2.0-RegularItalic";
this.date = date.ToLocalTime();
// if date's format is not specified, set it to an empty string,
// so that later we will know to humanize it
dateFormat = "";
// set a tooltip format for later from an argument
// The string to format the tooltip text with.
// May be null if the default format should be used.
this.tooltipFormat = tooltipFormat;
}
public DrawableDate(string dateFormat, DateTimeOffset date, string tooltipFormat)
{
AutoSizeAxes = Axes.Both;
Font = "Exo2.0-RegularItalic";
this.date = date.ToLocalTime();
// set a date format for text generator from an argument
this.dateFormat = dateFormat;
// set a tooltip format for tooltip generator from an argument
this.tooltipFormat = tooltipFormat;
}
[BackgroundDependencyLoader]
private void load()
{
@ -104,18 +66,12 @@ namespace osu.Game.Graphics
public override bool HandleMouseInput => true;
// if date's format is specified
private void updateTime() => Text = dateFormat != "" ?
// format it as requested in a passed argument
String.Format(dateFormat, date) :
// otherwise, humanize it (for example: 2 hours ago)
date.Humanize();
private void updateTime() => Text = string.IsNullOrEmpty(dateFormat) ?
date.Humanize() :
string.Format(dateFormat, date);
// if we know that the tooltip format exists
public string TooltipText => tooltipFormat != "" ?
// then we format the tooltip text using that format
String.Format(tooltipFormat, date) :
// but otherwise, simply convert the date to string
date.ToString();
public string TooltipText => string.IsNullOrEmpty(tooltipFormat) ?
date.ToString() :
string.Format(tooltipFormat, date);
}
}