DateField and TimeField depends on LayoutStyle.Computed.

This commit is contained in:
BDisp
2023-11-29 16:49:14 +00:00
parent 60bdd9635c
commit 73de270a8b
4 changed files with 10 additions and 8 deletions

View File

@@ -70,6 +70,7 @@ namespace Terminal.Gui {
void Initialize (DateTime date, bool isShort = false)
{
CultureInfo cultureInfo = CultureInfo.CurrentCulture;
LayoutStyle = LayoutStyle.Computed;
sepChar = cultureInfo.DateTimeFormat.DateSeparator;
longFormat = GetLongFormat (cultureInfo.DateTimeFormat.ShortDatePattern);
shortFormat = GetShortFormat (longFormat);

View File

@@ -70,6 +70,7 @@ namespace Terminal.Gui {
void Initialize (TimeSpan time, bool isShort = false)
{
CultureInfo cultureInfo = CultureInfo.CurrentCulture;
LayoutStyle = LayoutStyle.Computed;
sepChar = cultureInfo.DateTimeFormat.TimeSeparator;
longFormat = $" hh\\{sepChar}mm\\{sepChar}ss";
shortFormat = $" hh\\{sepChar}mm";

View File

@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace Terminal.Gui.ViewsTests {
@@ -16,6 +12,7 @@ namespace Terminal.Gui.ViewsTests {
Assert.Equal (DateTime.MinValue, df.Date);
Assert.Equal (1, df.CursorPosition);
Assert.Equal (new Rect (0, 0, 12, 1), df.Frame);
Assert.Equal (LayoutStyle.Computed, df.LayoutStyle);
var date = DateTime.Now;
df = new DateField (date);
@@ -23,18 +20,21 @@ namespace Terminal.Gui.ViewsTests {
Assert.Equal (date, df.Date);
Assert.Equal (1, df.CursorPosition);
Assert.Equal (new Rect (0, 0, 12, 1), df.Frame);
Assert.Equal (LayoutStyle.Computed, df.LayoutStyle);
df = new DateField (1, 2, date);
Assert.False (df.IsShortFormat);
Assert.Equal (date, df.Date);
Assert.Equal (1, df.CursorPosition);
Assert.Equal (new Rect (1, 2, 12, 1), df.Frame);
Assert.Equal (LayoutStyle.Computed, df.LayoutStyle);
df = new DateField (3, 4, date, true);
Assert.True (df.IsShortFormat);
Assert.Equal (date, df.Date);
Assert.Equal (1, df.CursorPosition);
Assert.Equal (new Rect (3, 4, 10, 1), df.Frame);
Assert.Equal (LayoutStyle.Computed, df.LayoutStyle);
df.IsShortFormat = false;
Assert.Equal (new Rect (3, 4, 12, 1), df.Frame);

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace Terminal.Gui.ViewsTests {
@@ -15,6 +11,7 @@ namespace Terminal.Gui.ViewsTests {
Assert.Equal (TimeSpan.MinValue, tf.Time);
Assert.Equal (1, tf.CursorPosition);
Assert.Equal (new Rect (0, 0, 10, 1), tf.Frame);
Assert.Equal (LayoutStyle.Computed, tf.LayoutStyle);
var time = DateTime.Now.TimeOfDay;
tf = new TimeField (time);
@@ -22,18 +19,21 @@ namespace Terminal.Gui.ViewsTests {
Assert.Equal (time, tf.Time);
Assert.Equal (1, tf.CursorPosition);
Assert.Equal (new Rect (0, 0, 10, 1), tf.Frame);
Assert.Equal (LayoutStyle.Computed, tf.LayoutStyle);
tf = new TimeField (1, 2, time);
Assert.False (tf.IsShortFormat);
Assert.Equal (time, tf.Time);
Assert.Equal (1, tf.CursorPosition);
Assert.Equal (new Rect (1, 2, 10, 1), tf.Frame);
Assert.Equal (LayoutStyle.Computed, tf.LayoutStyle);
tf = new TimeField (3, 4, time, true);
Assert.True (tf.IsShortFormat);
Assert.Equal (time, tf.Time);
Assert.Equal (1, tf.CursorPosition);
Assert.Equal (new Rect (3, 4, 7, 1), tf.Frame);
Assert.Equal (LayoutStyle.Computed, tf.LayoutStyle);
tf.IsShortFormat = false;
Assert.Equal (new Rect (3, 4, 10, 1), tf.Frame);