2023-06-23 00:37:25 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-03-04 12:24:19 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-11-17 13:05:22 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
2023-10-28 21:52:33 +08:00
|
|
|
|
using System.Globalization;
|
2019-03-02 12:40:43 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-11-17 13:05:22 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Overlays.Settings;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Components
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class DateTextBox : SettingsTextBox
|
2018-11-17 13:05:22 +08:00
|
|
|
|
{
|
2023-10-26 15:46:04 +08:00
|
|
|
|
private readonly BindableWithCurrent<DateTimeOffset> current = new BindableWithCurrent<DateTimeOffset>(DateTimeOffset.Now);
|
2023-07-24 19:20:52 +08:00
|
|
|
|
|
|
|
|
|
public new Bindable<DateTimeOffset>? Current
|
2018-11-17 13:05:22 +08:00
|
|
|
|
{
|
2020-10-06 16:18:41 +08:00
|
|
|
|
get => current;
|
2023-10-17 16:48:51 +08:00
|
|
|
|
set => current.Current = value!;
|
2018-11-17 13:05:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTextBox()
|
|
|
|
|
{
|
2021-10-02 01:54:10 +08:00
|
|
|
|
base.Current = new Bindable<string>(string.Empty);
|
2020-09-02 12:17:17 +08:00
|
|
|
|
|
2023-07-24 19:20:52 +08:00
|
|
|
|
current.BindValueChanged(dto =>
|
2023-10-28 21:52:33 +08:00
|
|
|
|
base.Current.Value = dto.NewValue.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", DateTimeFormatInfo.InvariantInfo), true);
|
2023-07-24 19:20:52 +08:00
|
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
|
((OsuTextBox)Control).OnCommit += (sender, _) =>
|
2018-11-17 13:05:22 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-10-28 21:52:33 +08:00
|
|
|
|
current.Value = DateTimeOffset.Parse(sender.Text, DateTimeFormatInfo.InvariantInfo);
|
2018-11-17 13:05:22 +08:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2019-06-13 16:04:57 +08:00
|
|
|
|
// reset textbox content to its last valid state on a parse failure.
|
2020-10-06 16:18:41 +08:00
|
|
|
|
current.TriggerChange();
|
2018-11-17 13:05:22 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|