ChuckJonas / ts-force

A Salesforce REST Client written in Typescript for Typescript
88 stars 21 forks source link

Dates are represented as DateTime #69

Closed ChuckJonas closed 3 years ago

ChuckJonas commented 5 years ago

For Salesforce Date (no time) fields, the API returns a string in the format YYYY-MM-DD.

Without much thought, I choose to parse this to a Javascript Date object. This causes timezone related issues, which often result in a Date saved to salesforce being off +- 1 day.

In a minor version, I'm thinking I can add some consistency by converting the Date to UTC (without timezone translation) before serialization.

However, the issue still persists that a "Calendar Date" SHOULD NOT be represented as a moment in time....

In a major version (because this will be a breaking change), I'm thinking we should adopt one of the following...

Type Format

A: string mirroring salesforce.

PROS:

CONS:

B: [number, number, number] tuple.

PROS:

CONS:

C: {year: number; month: number; day: number;} Obj

PROS:

CONS:

Month Format

If we go with option B or C, then we also need to decide if we want to store month as 0-11 or 1-12...

0-11

Pros:

Cons:

1-12

Pros:

Cons:

ChuckJonas commented 5 years ago

Leaning toward option C & 0-11. With this approach you would be able to pass the object directly into momentjs

const today = moment({ year:2019, month: 10, day: 3 });

day.js (popular alternative), does not support this yet, but may at some point

CarsonF commented 5 years ago

FWIW I use Luxon and its fromISO supports ISO dates without time out of the box. I really enjoy Luxon's API too.