microsoft / node-api-dotnet

Advanced interoperability between .NET and JavaScript in the same process.
MIT License
495 stars 53 forks source link

DateTimeOffset Marshalling not matching documentation #277

Closed smeatond closed 3 months ago

smeatond commented 5 months ago

When using DateTimeOffset, it marshals to System.DateTimeOffset not [Date, number] as mentioned in the docs: https://github.com/microsoft/node-api-dotnet/blob/main/Docs/typescript.md#special-types

Extract from ĒxampleModule.d.ts

export class SomeModelJS {
    constructor();

    id?: string;

    name?: string;

    created?: System.DateTimeOffset;

    updated?: Date;

    anotherField?: string;
}

c# Model:

[JSExport]
public  class SomeModelJS
{ 

    public string? Id {get; set;}     
    public string? Name {get; set;}
    public DateTimeOffset?  Created {get; set;}
    public DateTime?  Updated {get; set;}
    public string? AnotherField {get; set;}

}
jasongin commented 5 months ago

Thanks for reporting this. It appears the planned DateTimeOffset marshalling support was simply not implemented at all, and I lost track of it. So I'll use this issue to track the implementation. It shouldn't be difficult, so I can get it done relatively soon.

smeatond commented 5 months ago

Thank you Jason.

jasongin commented 3 months ago

Fixed, though I decided on a different design from how it was originally documented. See https://github.com/microsoft/node-api-dotnet/blob/main/Docs/dates.md