-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DateSelector for date input options (#227)
* DateSelector * DateSelector.MinDate * Use Date <-> DateTimeOffset conversion from commonItems * Update README * Minor optimization
- Loading branch information
1 parent
c078a77
commit c930025
Showing
5 changed files
with
90 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using commonItems; | ||
using System; | ||
|
||
namespace Fronter.Models.Configuration.Options; | ||
|
||
public class DateSelector : Selector { | ||
public DateSelector(BufferedReader reader) { | ||
var parser = new Parser(); | ||
RegisterKeys(parser); | ||
parser.ParseStream(reader); | ||
} | ||
private void RegisterKeys(Parser parser) { | ||
parser.RegisterKeyword("editable", reader => Editable = reader.GetString() == "true"); | ||
parser.RegisterKeyword("value", reader => { | ||
var valueStr = reader.GetString(); | ||
Value = string.IsNullOrWhiteSpace(valueStr) ? null : new Date(valueStr); | ||
}); | ||
parser.RegisterKeyword("minDate", reader => MinDate = new Date(reader.GetString()).ToDateTimeOffset()); | ||
parser.RegisterKeyword("maxDate", reader => MaxDate = new Date(reader.GetString()).ToDateTimeOffset()); | ||
parser.RegisterKeyword("tooltip", reader => Tooltip = reader.GetString()); | ||
parser.RegisterRegex(CommonRegexes.Catchall, ParserHelpers.IgnoreAndLogItem); | ||
} | ||
|
||
public bool Editable { get; private set; } = true; // editable unless disabled | ||
public DateTimeOffset MinDate { get; set; } = DateTimeOffset.MinValue; | ||
public DateTimeOffset MaxDate { get; set; } = DateTimeOffset.MaxValue; | ||
public DateTimeOffset? DateTimeOffsetValue { get; set; } | ||
|
||
public Date? Value { | ||
get { | ||
if (DateTimeOffsetValue is null) { | ||
return null; | ||
} | ||
|
||
var offsetValue = DateTimeOffsetValue.Value; | ||
return new Date(offsetValue); | ||
} | ||
set { | ||
if (value is null) { | ||
DateTimeOffsetValue = null; | ||
} else { | ||
DateTimeOffsetValue = value.ToDateTimeOffset(); | ||
} | ||
} | ||
} | ||
|
||
public string? Tooltip { get; private set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters