daryllabar / DLaB.Xrm.XrmToolBoxTools

Plugins for the XrmToolBox
MIT License
78 stars 70 forks source link

DateTime Sub-Type added to <remarks> in generated fields/entities #509

Open PC-BPS opened 4 months ago

PC-BPS commented 4 months ago

What tool/version is it that you're making a feature request for?

EarlyBoundGenerator

Is your feature request related to a problem? Please describe.

When we try to write code for a mix of DateTimes (TimeZone Independent) and Date Only, we have to check the solution to confirm the type of DateTime before working on it. It is easy to make a mistake and accidentally set something to the UTC Date instead of our own local date (AEST). Records that are created or updated prior to 10am will have the day priors date.

Existing generated field:

/// <summary>
/// Start Date of Product
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("new_startdate")]
public System.Nullable<System.DateTime> new_startdate
{
    [System.Diagnostics.DebuggerNonUserCode()]
    get
    {
        return this.GetAttributeValue<System.Nullable<System.DateTime>>("new_startdate");
    }
    [System.Diagnostics.DebuggerNonUserCode()]
    set
    {
        this.SetAttributeValue("new_startdate", value);
    }
}

Describe the solution you'd like

When the earlybound entities and fields are generated, the comments of the field show that it is either TimeZone Independent or DateOnly. It would be great if it were configurable, so that a custom message could be shown for either situation.

Example:

/// <summary>
/// Start Date of Product
/// </summary>
 /// <remarks>
/// DateOnly - When dealing with UTC dates, convert using CustomUtility.ConvertToAEST()
/// </remarks>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("new_startdate")]
public System.Nullable<System.DateTime> new_startdate
{
    [System.Diagnostics.DebuggerNonUserCode()]
    get
    {
        return this.GetAttributeValue<System.Nullable<System.DateTime>>("new_startdate");
    }
    [System.Diagnostics.DebuggerNonUserCode()]
    set
    {
        this.SetAttributeValue("new_startdate", value);
    }
}

Describe alternatives you've considered Changing the description of each field that is DateOnly in the solution, so that it shows in the <summary>.

daryllabar commented 2 months ago

Hmm... When dealing with Dates in the SDK, they should always be set as UTC, and retrieved as UTC. What exactly is the conversion logic that you are applying and for which Date field formats? I'm wondering if there is a better approach that can be built in, or maybe an attribute metadata type that can at least be added.

PC-BPS commented 2 months ago

When we create a record prior to 10AM local time. If that record contains a date only field, the value is set to the day before. So in order for the date to be "Today" we have to add 10 hours to it.

It is difficult to identify which fields we need to do this to, we have to go look it up in the solution.

daryllabar commented 2 months ago

Does this not work?

entity.myDate = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);