fuels-ts icon indicating copy to clipboard operation
fuels-ts copied to clipboard

Add new Date Wrapper

Open Torres-ssf opened this issue 1 year ago • 6 comments

We need to investigate and integrate a suitable date wrapper for broad use within the SDK.

Two critical factors must be considered:

  1. SDK Compatibility and GraphQL Resolver Integration: The date package must fully meet the needs of the SDK, and also for GraphQL resolvers. This is crucial because, during the implementation of these resolvers, specific date conversions are expected. (Refer to related issues 1572 and 1570 for more context.)

  2. Package Tree Shaking: It's essential to consider the tree-shakability of the package. This consideration is to ensure that the SDK's overall size isn't unnecessarily increased, maintaining its performance and efficiency.

[!NOTE]

  • Incoming from https://github.com/FuelLabs/fuels-ts/discussions/1537

Torres-ssf avatar Dec 20 '23 15:12 Torres-ssf

An external package may not even be needed here. We could implement something based off the native Date object, wrap our own functionality such as fromTai64ToUnix and document how it can be used with other packages?

danielbate avatar Dec 21 '23 10:12 danielbate

@danielbate could you pop my name on this one for me please🥇

petertonysmith94 avatar Jan 08 '24 10:01 petertonysmith94

@danielbate Do you think the internal date for the Date wrapper, should be stored as Tai64?

I assume that Tai64 is more integral internally and that the UNIX time is generally for the end users - but my assumptions have be wrong before 😃

petertonysmith94 avatar Jan 08 '24 11:01 petertonysmith94

@FuelLabs/frontend may be able to weigh in here as to what the better internal store format should be? I'd probably recommend UNIX due to it's flexibility unless said otherwise.

danielbate avatar Jan 10 '24 12:01 danielbate

@FuelLabs/frontend may be able to weigh in here as to what the better internal store format should be? I'd probably recommend UNIX due to it's flexibility unless said otherwise.

yes UNIX is great

LuizAsFight avatar Jan 22 '24 19:01 LuizAsFight

Got a PR here.

Just was looking for a review of the API


The following instantiation methods are available:

const tai64: DateTime = DateTime.fromTai64('4611686020108779312');
const unixSeconds: DateTime = DateTime.fromUnixSeconds(1681391398);
const unixMilliseconds: DateTime = DateTime.fromUnixMilliseconds(1681391398000);

Note: actively removed instantiation via the constructor (to avoid confusions between timestamps).


Provided are the following methods of conversion and fully date compatible:

const date: DateTime = DateTime.fromTai64('4611686020108779312');
date.toTai64() // (string) '4611686020108779312'
date.toUnixMilliseconds() // (number) 1681391398000
date.toUnixSeconds() // (number) 1681391398

petertonysmith94 avatar Jan 23 '24 15:01 petertonysmith94

I have removed the GraphQL resolver functionality due to functionality not possible #1572

petertonysmith94 avatar Feb 23 '24 14:02 petertonysmith94