Add better date string formatting

This commit is contained in:
Dean Herbert
2018-11-17 14:05:22 +09:00
parent c1e1306c97
commit bed967b456
3 changed files with 47 additions and 35 deletions

View File

@ -0,0 +1,44 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
namespace osu.Game.Tournament.Components
{
public class DateTextBox : SettingsTextBox
{
public new Bindable<DateTimeOffset> Bindable
{
get { return bindable; }
set
{
bindable = value;
bindable.BindValueChanged(dto =>
base.Bindable.Value = dto.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"), true);
}
}
// hold a reference to the provided bindable so we don't have to in every settings section.
private Bindable<DateTimeOffset> bindable;
public DateTextBox()
{
base.Bindable = new Bindable<string>();
((OsuTextBox)Control).OnCommit = (sender, newText) =>
{
try
{
bindable.Value = DateTimeOffset.Parse(sender.Text);
}
catch
{
bindable.TriggerChange();
}
};
}
}
}

View File

@ -4,13 +4,13 @@
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Screens.Ladder.Components;
namespace osu.Game.Tournament.Screens.Groupings
@ -74,7 +74,7 @@ namespace osu.Game.Tournament.Screens.Groupings
updateGroupings();
}
private void updateGroupings()
private void updateGroupings()
{
LadderInfo.Groupings = items.Children.Select(c => c.Grouping).ToList();
}
@ -118,36 +118,4 @@ namespace osu.Game.Tournament.Screens.Groupings
}
}
}
public class DateTextBox : SettingsTextBox
{
public DateTextBox()
{
base.Bindable = new Bindable<string>();
((OsuTextBox)Control).OnCommit = (sender, newText) => {
try
{
bindable.Value = DateTimeOffset.Parse(sender.Text);
}
catch
{
bindable.TriggerChange();
}
};
}
// hold a reference to the provided bindable so we don't have to in every settings section.
private Bindable<DateTimeOffset> bindable;
public new Bindable<DateTimeOffset> Bindable
{
get { return bindable; }
set
{
bindable = value;
bindable.BindValueChanged(dto => base.Bindable.Value = dto.ToUniversalTime().ToString(), true);
}
}
}
}

View File

@ -12,7 +12,7 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
using osu.Game.Screens.Play.PlayerSettings;
using osu.Game.Tournament.Screens.Groupings;
using osu.Game.Tournament.Components;
namespace osu.Game.Tournament.Screens.Ladder.Components
{