Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Date Time node description to better illustrate how to use it #13460

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/DynamoCore/Graph/Nodes/NodeInputData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Serialization;
Expand Down Expand Up @@ -157,12 +157,12 @@ public override bool Equals(object obj)
{
var converted = obj as NodeInputData;

var valNumberComparison = false;
bool valNumberComparison;
try
{
valNumberComparison = Math.Abs(Convert.ToDouble(this.Value, CultureInfo.InvariantCulture) - Convert.ToDouble(converted.Value, CultureInfo.InvariantCulture)) < .000001;
}
catch (Exception e)
catch (Exception)
{
//this just stays false.
valNumberComparison = false;
Expand Down
5 changes: 4 additions & 1 deletion src/Libraries/CoreNodeModels/Input/DateTime.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using Dynamo.Configuration;
Expand All @@ -23,6 +23,9 @@ private DateTime(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts
ShouldDisplayPreviewCore = false;
}

/// <summary>
/// Constructor
/// </summary>
public DateTime()
{
Value = System.DateTime.UtcNow;
Expand Down
4 changes: 2 additions & 2 deletions src/Libraries/CoreNodeModels/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/Libraries/CoreNodeModels/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -537,7 +537,7 @@
<value>A converted numeric value.</value>
</data>
<data name="DateTimeDescription" xml:space="preserve">
<value>Creates a dateTime object from a formatted date and time string. Date and time must be in the format "April 12, 1977 12:00 PM"</value>
<value>Creates a dateTime object from a formatted date and time string. Date and time must be in the default DateTime format "MMMM dd, yyyy h:mm tt", e.g. "April 02, 1977 12:00 PM"</value>
</data>
<data name="ColorRangeSearchTags" xml:space="preserve">
<value>colorrange;</value>
Expand Down Expand Up @@ -632,4 +632,4 @@ Default value: {0}</value>
<data name="CustomSelectionOutputDescription" xml:space="preserve">
<value>Selected value</value>
</data>
</root>
</root>
6 changes: 3 additions & 3 deletions src/Libraries/CoreNodeModels/Properties/Resources.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -537,7 +537,7 @@
<value>A converted numeric value.</value>
</data>
<data name="DateTimeDescription" xml:space="preserve">
<value>Creates a dateTime object from a formatted date and time string. Date and time must be in the format "April 12, 1977 12:00 PM"</value>
<value>Creates a dateTime object from a formatted date and time string. Date and time must be in the default DateTime format "MMMM dd, yyyy h:mm tt", e.g. "April 02, 1977 12:00 PM"</value>
</data>
<data name="ColorRangeSearchTags" xml:space="preserve">
<value>colorrange;</value>
Expand Down Expand Up @@ -632,4 +632,4 @@ Default value: {0}</value>
<data name="CustomSelectionOutputDescription" xml:space="preserve">
<value>Selected value</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
using System;
using System;
using System.Globalization;
using System.Windows.Data;
using Dynamo.Configuration;

namespace CoreNodeModelsWpf.Converters
{
/// <summary>
/// DateTime converter used for Date Time node value conversion
/// </summary>
public class StringToDateTimeConverter : IValueConverter
{
/// <summary>
/// Convert Date Time object to string using DefaultDateFormat
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((DateTime)value).ToString(PreferenceSettings.DefaultDateFormat, CultureInfo.InvariantCulture);
}

/// <summary>
/// Convert input string to Date Time value, try to apply DefaultDateFormat.
/// If conversion fails, use default time.
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
DateTime dt;
return DateTime.TryParseExact(value.ToString(), PreferenceSettings.DefaultDateFormat,
CultureInfo.InvariantCulture, DateTimeStyles.None, out dt) ?
dt : PreferenceSettings.DynamoDefaultTime;
CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dt) ?
dt : PreferenceSettings.DynamoDefaultTime;
}
}
}