1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-07 00:17:21 +08:00

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

44 lines
1.4 KiB
C#
Raw Normal View History

2019-03-04 13:24:19 +09: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 14:05:22 +09:00
using System;
using System.Globalization;
2019-03-02 13:40:43 +09:00
using osu.Framework.Bindables;
2018-11-17 14:05:22 +09: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>(DateTimeOffset.Now);
public new Bindable<DateTimeOffset>? Current
2018-11-17 14:05:22 +09:00
{
get => current;
2023-10-17 17:48:51 +09:00
set => current.Current = value!;
2018-11-17 14:05:22 +09:00
}
public DateTextBox()
{
base.Current = new Bindable<string>(string.Empty);
2020-09-02 13:17:17 +09:00
current.BindValueChanged(dto =>
base.Current.Value = dto.NewValue.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", DateTimeFormatInfo.InvariantInfo), true);
2022-06-24 21:25:23 +09:00
((OsuTextBox)Control).OnCommit += (sender, _) =>
2018-11-17 14:05:22 +09:00
{
try
{
current.Value = DateTimeOffset.Parse(sender.Text, DateTimeFormatInfo.InvariantInfo);
2018-11-17 14:05:22 +09:00
}
catch
{
2019-06-13 17:04:57 +09:00
// reset textbox content to its last valid state on a parse failure.
current.TriggerChange();
2018-11-17 14:05:22 +09:00
}
};
}
}
}