public static TryParse ( string value, string format, System.DateTime currentDate, |
||
value | string | |
format | string | |
currentDate | System.DateTime | |
cultureInfo | ||
result | System.DateTime | |
return | bool |
private bool TryParseDateTime(string text, out DateTime result) { bool isValid = false; result = this.ContextNow; DateTime current = this.ContextNow; try { current = (this.Value.HasValue) ? this.Value.Value : DateTime.Parse(this.ContextNow.ToString(), this.CultureInfo.DateTimeFormat); isValid = DateTimeParser.TryParse(text, this.GetFormatString(Format), current, this.CultureInfo, out result); } catch (FormatException) { isValid = false; } if (!isValid) { isValid = DateTime.TryParseExact(text, this.GetFormatString(this.Format), this.CultureInfo, DateTimeStyles.None, out result); } if (!isValid) { result = (_lastValidDate != null) ? _lastValidDate.Value : current; } return(isValid); }
private bool TryParseDateTime(string text, out DateTime result) { bool isValid = false; result = this.ContextNow; DateTime current = this.ContextNow; try { // TempValue is used when Manipulating TextBox.Text while Value is not updated yet (used in DateTimePicker's TimePicker). current = this.TempValue.HasValue ? this.TempValue.Value : this.Value.HasValue ? this.Value.Value : DateTime.Parse(this.ContextNow.ToString(), this.CultureInfo.DateTimeFormat); isValid = DateTimeParser.TryParse(text, this.GetFormatString(Format), current, this.CultureInfo, this.AutoClipTimeParts, out result); } catch (FormatException) { isValid = false; } if (!isValid) { isValid = DateTime.TryParseExact(text, this.GetFormatString(this.Format), this.CultureInfo, DateTimeStyles.None, out result); } if (!isValid) { result = (_lastValidDate != null) ? _lastValidDate.Value : current; } return(isValid); }
protected override DateTime?ConvertTextToValue(string text) { if (string.IsNullOrEmpty(text)) { return(null); } DateTime current = Value.HasValue ? Value.Value : DateTime.Parse(DateTime.Now.ToString(), CultureInfo.DateTimeFormat); DateTime result; var success = DateTimeParser.TryParse(text, GetFormatString(Format), current, CultureInfo, out result); return(result); }
private bool TryParseDateTime(string text, out DateTime result) { bool isValid; DateTime current = this.Value.HasValue ? this.Value.Value : DateTime.Parse(DateTime.Now.ToString(), this.CultureInfo.DateTimeFormat); isValid = DateTimeParser.TryParse(text, this.GetFormatString(Format), current, this.CultureInfo, out result); if (!isValid && (this.Format == DateTimeFormat.Custom)) { isValid = DateTime.TryParseExact(text, this.GetFormatString(this.Format), this.CultureInfo, DateTimeStyles.None, out result); } return(isValid); }
protected override void OnTextChanged(string previousValue, string currentValue) { if (!_processTextChanged) { return; } if (!String.IsNullOrEmpty(currentValue)) { DateTime current = Value.HasValue ? Value.Value : DateTime.Parse(DateTime.Now.ToString(), CultureInfo.DateTimeFormat); DateTime result; var success = DateTimeParser.TryParse(currentValue, GetFormatString(Format), current, CultureInfo, out result); currentValue = result.ToString(); } SyncTextAndValueProperties(true, currentValue); }
protected override void OnTextChanged(string previousValue, string currentValue) { if (!_processTextChanged) { return; } //TODO: clean this up and make sure it doesn't fire recursively if (String.IsNullOrEmpty(currentValue)) { Value = null; return; } DateTime current = Value.HasValue ? Value.Value : DateTime.Parse(DateTime.Now.ToString(), CultureInfo.DateTimeFormat); DateTime result; var success = DateTimeParser.TryParse(currentValue, GetFormatString(Format), current, CultureInfo, out result); SyncTextAndValueProperties(InputBase.TextProperty, result.ToString(CultureInfo)); }