1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 04:12:53 +08:00
osu-lazer/osu.Game.Tournament/Components/DateTextBox.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.3 KiB
C#
Raw Normal View History

2019-03-04 12:24:19 +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.
2018-11-17 13:05:22 +08:00
using System;
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
{
public partial class DateTextBox : SettingsTextBox
{
private readonly BindableWithCurrent<DateTimeOffset> current = new BindableWithCurrent<DateTimeOffset>();
public new Bindable<DateTimeOffset>? Current
2018-11-17 13:05:22 +08:00
{
get => current;
set => current.Current = value;
2018-11-17 13:05:22 +08:00
}
public DateTextBox()
{
base.Current = new Bindable<string>(string.Empty);
2020-09-02 12:17:17 +08:00
current.BindValueChanged(dto =>
base.Current.Value = dto.NewValue.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"), true);
2022-06-24 20:25:23 +08:00
((OsuTextBox)Control).OnCommit += (sender, _) =>
2018-11-17 13:05:22 +08:00
{
try
{
current.Value = DateTimeOffset.Parse(sender.Text);
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.
current.TriggerChange();
2018-11-17 13:05:22 +08:00
}
};
}
}
}