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

feat: Added new date wrapper #1627

Merged
merged 197 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
197 commits
Select commit Hold shift + click to select a range
cd99e17
Adding RCs list
arboleya Dec 8, 2023
2b9495a
Ignoring RC labels
arboleya Dec 8, 2023
4dfd727
Configuring RC label
arboleya Dec 8, 2023
75ed18d
Re-configuring RC label
arboleya Dec 8, 2023
820b5e2
Adjusting PRs accepted labels
arboleya Dec 8, 2023
8b2c663
Merge branch 'master' into rc/salamander
arboleya Dec 10, 2023
8ebd388
chore: updating code owners (#1496)
arboleya Dec 12, 2023
4b3c8ea
Merge branch 'master' into rc/salamander
arboleya Dec 12, 2023
e12a62d
Merge branch 'master' into rc/salamander
arboleya Dec 13, 2023
c7b9b92
Merge branch 'master' into rc/salamander
arboleya Dec 13, 2023
cdc3e84
Merge branch 'master' into rc/salamander
arboleya Dec 13, 2023
8bea836
docs: purge hardcoded snippets on 'using typegen' page (#1403)
Dhaiwat10 Dec 14, 2023
5d5c939
chore: remove method that's same as base method (#1445)
nedsalk Dec 14, 2023
cd7aed5
Merge branch 'master' into rc/salamander
arboleya Dec 14, 2023
5261579
chore: implement RC workflow (#1497)
danielbate Dec 15, 2023
6a1c2f1
chore: fix rc release string replace (#1529)
danielbate Dec 15, 2023
b52c137
Merge branch 'master' into rc/salamander
arboleya Dec 15, 2023
e236fc8
Merge branch 'master' into rc/salamander
arboleya Dec 15, 2023
55e8301
docs: Update some hyperlinks to reference the new documentation hub (…
petertonysmith94 Dec 18, 2023
c5e56b4
Merge branch 'master' into rc/salamander
arboleya Dec 19, 2023
53ab0d6
chore: improve rc release message (#1559)
danielbate Dec 19, 2023
8021b38
feat: GraphQL subscriptions (#1374)
nedsalk Dec 20, 2023
58ef6e7
chore: pin `graphql-request` to `v5` (#1567)
danielbate Dec 20, 2023
e52a1cc
Merge branch 'master' into rc/salamander
arboleya Dec 20, 2023
5ebe5eb
chore: upgrade `tsx` (#1574)
danielbate Dec 20, 2023
5f12a6b
feat: migrate from Jest to Vitest (#1310)
danielbate Dec 21, 2023
92add1d
chore: fix temp test workflow (#1579)
danielbate Dec 21, 2023
76fee0e
Merge branch 'master' into rc/salamander
arboleya Dec 21, 2023
098c349
Fixing tsconfig.json
arboleya Dec 21, 2023
d759de2
chore: update required node engine in `create-fuels` (#1582)
danielbate Dec 21, 2023
576a46e
chore: add node version test matrix (#1575)
danielbate Dec 21, 2023
d3335de
chore: fix broken rc message (#1580)
danielbate Dec 22, 2023
c988199
chore: update nodejs to v20 (#1544)
nedsalk Dec 22, 2023
8d84846
feat: accepting addresses as `string` (#1583)
Torres-ssf Dec 22, 2023
773194c
chore: properly format the PR coverage report comment (#1586)
danielbate Dec 22, 2023
7949bb8
fix: flaky test (#1590)
Torres-ssf Dec 22, 2023
00e5850
docs: update `deposit-and-withdraw` page (#1591)
Torres-ssf Dec 23, 2023
563914e
feat: retry mechanism (#1474)
nedsalk Jan 3, 2024
87b7ce1
Merge branch 'master' into rc/salamander
arboleya Jan 3, 2024
7e46db9
Merge branch 'master' into rc/salamander
arboleya Jan 4, 2024
f698256
feat: replaced `semver` dependency with custom implementation (#1594)
nedsalk Jan 5, 2024
6c82640
feat: replace `elliptic` with `@noble/curves` (#1601)
nedsalk Jan 5, 2024
168a0e8
Merge branch 'master' into rc/salamander
arboleya Jan 5, 2024
ad7ee46
chore: fix CI failing due to missing tag in test (#1614)
nedsalk Jan 5, 2024
78e5e40
feat: improve ABI Coders `decode` validation (#1426)
danielbate Jan 5, 2024
ad5923d
Merge branch 'master' into rc/salamander
arboleya Jan 9, 2024
6b3edac
chore: added missing return types to date methods
petertonysmith94 Jan 10, 2024
baee3db
feat: added date wrapper
petertonysmith94 Jan 10, 2024
87bd58e
chore: changeset
petertonysmith94 Jan 10, 2024
17823e1
Merge branch 'master' into ps/feat/new-date-wrapper
petertonysmith94 Jan 10, 2024
34e4918
Merge branch 'master' into ps/feat/new-date-wrapper
petertonysmith94 Jan 10, 2024
b8a3bc2
fix: jest->vi
petertonysmith94 Jan 10, 2024
e969585
fix: inconsistent method name + added types
petertonysmith94 Jan 11, 2024
6796ef2
fix: do not generate a coverage diff without coverage artifact (#1629)
danielbate Jan 11, 2024
dbd576a
Merge branch 'rc/salamander' into ps/feat/new-date-wrapper
arboleya Jan 11, 2024
0668d88
Merge branch 'master' into rc/salamander
arboleya Jan 11, 2024
d31ee60
chore: pinpoint vitest to 1.0.4 (#1637)
arboleya Jan 12, 2024
895bea3
Merge branch 'rc/salamander' into ps/feat/new-date-wrapper
arboleya Jan 12, 2024
e29a46a
Merge branch 'ps/feat/new-date-wrapper' of github.com:petertonysmith9…
petertonysmith94 Jan 12, 2024
d146495
fix: removed spy, asserting on IFuelDate
petertonysmith94 Jan 12, 2024
db1df6b
chore: remove `ethers` dependency from `utils` (#1640)
danielbate Jan 12, 2024
349a309
fix: added missing types to time funcs
petertonysmith94 Jan 12, 2024
1730e4c
fix: incorrectly documented units for Unix
petertonysmith94 Jan 12, 2024
ba561d4
chore: moved providers->date.ts to `utils` folder
petertonysmith94 Jan 12, 2024
6a24488
fix: removed examples
petertonysmith94 Jan 12, 2024
d7045d6
chore: consolidated date and time
petertonysmith94 Jan 12, 2024
5036621
chore: tidy up the docs
petertonysmith94 Jan 12, 2024
df90729
docs: added docs for fromTai64ToDate and fromDateToTai64
petertonysmith94 Jan 12, 2024
45bfaf2
feat: scoping out the builder interface
petertonysmith94 Jan 12, 2024
3e05087
feat: removed dependency on tai64 package
petertonysmith94 Jan 12, 2024
ddb84d0
chore: removed tai64
petertonysmith94 Jan 12, 2024
9be3a66
fix: favour IP address over localhost
petertonysmith94 Jan 14, 2024
14aebe7
fix: `getOperation` for `Transfer Asset` (#1619)
Torres-ssf Jan 15, 2024
b32dc96
fix: remove external font dependencies (#1642)
petertonysmith94 Jan 15, 2024
2f80fd4
Merge branch 'rc/salamander' into ps/feat/new-date-wrapper
arboleya Jan 15, 2024
a4d278a
fix: missing Tai64Timestamp in codegen scalars
petertonysmith94 Jan 16, 2024
aac1b71
fix: generate RC PR comment on `pull_request` event only (#1648)
danielbate Jan 16, 2024
d41a26d
Merge branch 'master' into rc/salamander
arboleya Jan 16, 2024
de3cb15
fix: fix failing `rc` comment (#1657)
danielbate Jan 16, 2024
5236bfb
chore: add missing test group (#1658)
danielbate Jan 16, 2024
b6c76f0
refactor: DateTime introduction
petertonysmith94 Jan 16, 2024
06a72c6
Merge branch 'ps/feat/new-date-wrapper' of github.com:petertonysmith9…
petertonysmith94 Jan 16, 2024
acb8c5c
fix: time should be undefined in this example
petertonysmith94 Jan 16, 2024
e9f4148
fix: added test env config to test
petertonysmith94 Jan 16, 2024
ed0a49f
Merge branch 'master' into rc/salamander
arboleya Jan 16, 2024
2682148
feat: implement browser compatibility testing (#1630)
danielbate Jan 17, 2024
1b0bb20
chore: fix string replace in `rc` ci (#1659)
danielbate Jan 17, 2024
403ee6a
chore: adding extra reporters (#1661)
arboleya Jan 17, 2024
587d445
chore: manually trigger `rc` CI (#1660)
danielbate Jan 17, 2024
45c32d0
Enabling PR auto-release
arboleya Jan 17, 2024
311fe7f
Fixing RC name resolution
arboleya Jan 17, 2024
1284d07
feat: use `submitAndAwait` graphql endpoint (#1615)
nedsalk Jan 18, 2024
26a370d
fix: flaky retry test (#1654)
nedsalk Jan 18, 2024
606e6e6
feat: create a wallet without a provider (#1566)
petertonysmith94 Jan 18, 2024
206c2fe
chore!: Share single chainConfig and review node-related utilities (#…
Dhaiwat10 Jan 18, 2024
901ae9b
Merge branch 'master' into rc/salamander
arboleya Jan 18, 2024
86d4b86
Merge branch 'master' into ps/feat/new-date-wrapper
petertonysmith94 Jan 22, 2024
017f46f
chore: removed redundant interface
petertonysmith94 Jan 22, 2024
5f4af6b
chore: renaming NULL timestamp
petertonysmith94 Jan 22, 2024
111215b
chore: made @fuel-ts/utils a prod dependeny for @fuel-ts/provider
petertonysmith94 Jan 22, 2024
1e95096
feat: finalising the date-time + moved to utils
petertonysmith94 Jan 22, 2024
f39f532
docs: added date-time documentation
petertonysmith94 Jan 22, 2024
207f0ee
feat: added scalars for Unix and Tai64 timestamps
petertonysmith94 Jan 22, 2024
600e9f7
fix: added missing link to date-time docs
petertonysmith94 Jan 22, 2024
f4836c9
chore: removed comments
petertonysmith94 Jan 22, 2024
6af6e99
chore: added DateTime to spell checker
petertonysmith94 Jan 22, 2024
d0996ac
Merge branch 'rc/salamander' into ps/feat/new-date-wrapper
petertonysmith94 Jan 22, 2024
e2624b5
Merge branch 'rc/salamander' of github.com:FuelLabs/fuels-ts into ps/…
petertonysmith94 Jan 22, 2024
7ef3aee
Merge branch 'master' into ps/feat/new-date-wrapper
petertonysmith94 Jan 22, 2024
82cea5d
fix: missing / on the link
petertonysmith94 Jan 23, 2024
e632b14
docs: improvments to date-time documentation
petertonysmith94 Jan 23, 2024
a02f3a7
feat: added scalar mutations for unix and tai64 timestamps
petertonysmith94 Jan 23, 2024
745d39b
chore: updated TAI64_LEAP_SECONDS constant
petertonysmith94 Jan 23, 2024
d0810c3
Merge branch 'master' of github.com:FuelLabs/fuels-ts into ps/feat/ne…
petertonysmith94 Jan 23, 2024
eff5e70
docs: fixing spelling
petertonysmith94 Jan 23, 2024
011f62b
docs: added Atomique
petertonysmith94 Jan 23, 2024
f686f0e
Merge branch 'master' into ps/feat/new-date-wrapper
petertonysmith94 Jan 24, 2024
df695a9
Merge remote-tracking branch 'fuels' into ps/feat/new-date-wrapper
petertonysmith94 Jan 24, 2024
6b3bc45
fix: accounting for new constant
petertonysmith94 Jan 24, 2024
45713c6
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into ps…
petertonysmith94 Jan 27, 2024
788ca2b
chore: update lock file from master
petertonysmith94 Jan 27, 2024
67417d6
chore: install pnpm
petertonysmith94 Jan 27, 2024
c278248
chore: added missing return types to date methods
petertonysmith94 Jan 10, 2024
5329a05
feat: added date wrapper
petertonysmith94 Jan 10, 2024
a615223
chore: changeset
petertonysmith94 Jan 10, 2024
ee2e074
docs: update `deposit-and-withdraw` page (#1591)
Torres-ssf Dec 23, 2023
59a9435
feat: retry mechanism (#1474)
nedsalk Jan 3, 2024
e33833c
feat: replace `elliptic` with `@noble/curves` (#1601)
nedsalk Jan 5, 2024
830982d
fix: jest->vi
petertonysmith94 Jan 10, 2024
b1c5526
fix: inconsistent method name + added types
petertonysmith94 Jan 11, 2024
2dcfe90
fix: removed spy, asserting on IFuelDate
petertonysmith94 Jan 12, 2024
5217cd5
fix: added missing types to time funcs
petertonysmith94 Jan 12, 2024
7221095
fix: incorrectly documented units for Unix
petertonysmith94 Jan 12, 2024
be85454
chore: moved providers->date.ts to `utils` folder
petertonysmith94 Jan 12, 2024
48a2fdc
fix: removed examples
petertonysmith94 Jan 12, 2024
60b08df
chore: consolidated date and time
petertonysmith94 Jan 12, 2024
6756984
chore: tidy up the docs
petertonysmith94 Jan 12, 2024
cf303c6
docs: added docs for fromTai64ToDate and fromDateToTai64
petertonysmith94 Jan 12, 2024
407a2d9
feat: scoping out the builder interface
petertonysmith94 Jan 12, 2024
1d014dd
feat: removed dependency on tai64 package
petertonysmith94 Jan 12, 2024
51318ed
chore: removed tai64
petertonysmith94 Jan 12, 2024
d96e1d3
fix: favour IP address over localhost
petertonysmith94 Jan 14, 2024
94a9c83
fix: missing Tai64Timestamp in codegen scalars
petertonysmith94 Jan 16, 2024
9f5961c
refactor: DateTime introduction
petertonysmith94 Jan 16, 2024
22ad266
fix: time should be undefined in this example
petertonysmith94 Jan 16, 2024
121031b
fix: added test env config to test
petertonysmith94 Jan 16, 2024
28ad5b0
chore: removed redundant interface
petertonysmith94 Jan 22, 2024
bc1ff0e
chore: renaming NULL timestamp
petertonysmith94 Jan 22, 2024
507b5c9
chore: made @fuel-ts/utils a prod dependeny for @fuel-ts/provider
petertonysmith94 Jan 22, 2024
f731ce9
feat: finalising the date-time + moved to utils
petertonysmith94 Jan 22, 2024
8b863ea
docs: added date-time documentation
petertonysmith94 Jan 22, 2024
abce2d0
feat: added scalars for Unix and Tai64 timestamps
petertonysmith94 Jan 22, 2024
d0337af
fix: added missing link to date-time docs
petertonysmith94 Jan 22, 2024
77ba378
chore: removed comments
petertonysmith94 Jan 22, 2024
d85d21e
chore: added DateTime to spell checker
petertonysmith94 Jan 22, 2024
8ba07db
fix: flaky retry test (#1654)
nedsalk Jan 18, 2024
71913ae
fix: missing / on the link
petertonysmith94 Jan 23, 2024
a6c8eaa
docs: improvments to date-time documentation
petertonysmith94 Jan 23, 2024
2691e27
feat: added scalar mutations for unix and tai64 timestamps
petertonysmith94 Jan 23, 2024
2157ab3
chore: updated TAI64_LEAP_SECONDS constant
petertonysmith94 Jan 23, 2024
d0a190a
docs: fixing spelling
petertonysmith94 Jan 23, 2024
262aab6
docs: added Atomique
petertonysmith94 Jan 23, 2024
d76bf24
fix: accounting for new constant
petertonysmith94 Jan 24, 2024
10cdd4a
Merge branch 'ps/feat/date-wrapper-rebase' into ps/feat/new-date-wrapper
petertonysmith94 Jan 28, 2024
2eb21cc
Revert "chore: removed tai64"
petertonysmith94 Jan 28, 2024
6563319
chore: removed tai64 package
petertonysmith94 Jan 28, 2024
8b26fb5
Merge branch 'ps/feat/date-wrapper-rebase' into ps/feat/new-date-wrapper
petertonysmith94 Jan 28, 2024
7afac9b
Merge branch 'master' into ps/feat/new-date-wrapper
petertonysmith94 Feb 19, 2024
4184c09
chore: removed duplicate export
petertonysmith94 Feb 19, 2024
8f04f77
Merge branch 'master' into ps/feat/new-date-wrapper
petertonysmith94 Feb 19, 2024
804a8c3
Merge branch 'master' into ps/feat/new-date-wrapper
petertonysmith94 Feb 20, 2024
432fd8a
chore: lint
petertonysmith94 Feb 20, 2024
2be5d35
docs: updated DateTime docs title
petertonysmith94 Feb 22, 2024
6d510b2
chore: apply suggestions from code review
petertonysmith94 Feb 22, 2024
23778c7
chore: removed IDateTime
petertonysmith94 Feb 22, 2024
12a8e46
docs: changed **TAI64** to `TAI64`
petertonysmith94 Feb 22, 2024
3ec75f6
docs: changed **UNIX** to `UNIX`
petertonysmith94 Feb 22, 2024
20bb5fc
chore: updated getTime to toUnixMilliseconds
petertonysmith94 Feb 22, 2024
2355ac8
docs: added link to TAI64 section
petertonysmith94 Feb 22, 2024
5c5a9cf
Merge branch 'master' into ps/feat/new-date-wrapper
petertonysmith94 Feb 22, 2024
0b0d9f4
chore: updated incorrect imports in docs (#context -> #import)
petertonysmith94 Feb 22, 2024
52bf9ca
chore: revert pnpm-lock changes
petertonysmith94 Feb 22, 2024
7bf3d53
chore: linting
petertonysmith94 Feb 22, 2024
da4db72
chore: removed dependencies on DateTime utility functions
petertonysmith94 Feb 22, 2024
add197f
chore: removed browser test from doc-snippet test
petertonysmith94 Feb 23, 2024
ec46ae3
chore: unexposed the date-time-utility functions
petertonysmith94 Feb 23, 2024
fd7c57a
chore: lint
petertonysmith94 Feb 23, 2024
b1ef3f8
test: added tests around date-time convertion to
petertonysmith94 Feb 23, 2024
4a6d5fe
chore: incorrect date format
petertonysmith94 Feb 23, 2024
21a5af9
chore: lint
petertonysmith94 Feb 23, 2024
e2563c5
chore: updated changeset
petertonysmith94 Feb 23, 2024
6dd0716
chore: removed redundant scalars
petertonysmith94 Feb 23, 2024
526fea8
chore: unnesting data object
petertonysmith94 Feb 23, 2024
a7a0115
Merge branch 'master' into ps/feat/new-date-wrapper
petertonysmith94 Feb 23, 2024
0d205dc
chore: fix typo
petertonysmith94 Feb 26, 2024
a0f9468
Merge branch 'master' into ps/feat/new-date-wrapper
Dhaiwat10 Feb 26, 2024
53434c6
Merge branch 'master' into ps/feat/new-date-wrapper
petertonysmith94 Feb 26, 2024
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: 6 additions & 0 deletions .changeset/afraid-avocados-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/account": minor
"@fuel-ts/utils": minor
---

Add the DateTime class, which allows for the conversion between common date time formats.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { launchNode } from '@fuel-ts/account/test-utils';
import { Provider, fromTai64ToUnix } from 'fuels';
import { Provider, DateTime } from 'fuels';

/**
* @group node
Expand All @@ -15,7 +15,7 @@ test('produceBlocks with custom timestamp docs snippet', async () => {
}
const lastBlockNumber = latestBlock.height;
// #region Provider-produceBlocks-custom-timestamp
const lastBlockTimestamp = fromTai64ToUnix(latestBlock.time);
const lastBlockTimestamp = DateTime.fromTai64(latestBlock.time).toUnixMilliseconds();
const latestBlockNumber = await provider.produceBlocks(3, lastBlockTimestamp + 1000);
// #endregion Provider-produceBlocks-custom-timestamp
expect(latestBlockNumber.toHex()).toBe(lastBlockNumber.add(3).toHex());
Expand Down
93 changes: 93 additions & 0 deletions apps/docs-snippets/src/guide/types/date-time.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { DateTime } from 'fuels';

/**
* @group node
danielbate marked this conversation as resolved.
Show resolved Hide resolved
*/
describe(__filename, () => {
it('should be able to be created from multiple sources', () => {
// #region create-from-multiple-sources
// #import { DateTime };

const tai64: DateTime = DateTime.fromTai64('4611686020108779339');
const unixSeconds: DateTime = DateTime.fromUnixSeconds(1681391398);
const unixMilliseconds: DateTime = DateTime.fromUnixMilliseconds(1681391398000);
// #endregion create-from-multiple-sources

expect(tai64).toBeDefined();
expect(tai64.toTai64()).toBe('4611686020108779339');
expect(unixSeconds).toBeDefined();
expect(unixSeconds.toUnixSeconds()).toBe(1681391398);
expect(unixMilliseconds).toBeDefined();
expect(unixMilliseconds.toUnixMilliseconds()).toBe(1681391398000);
});

it('should be able to create fromTai64 and convert toTai64', () => {
// #region from-tai-64-and-to-tai-64
// #import { DateTime };

const date: DateTime = DateTime.fromTai64('4611686020108779339');
// #context console.log(date.toIso); // "4611686020108779339"

const tai64: string = date.toTai64();
// #context console.log(tai64); // "4611686020108779339"
// #endregion from-tai-64-and-to-tai-64

expect(date).toBeDefined();
expect(date.toISOString()).toEqual('2023-04-13T13:09:58.000Z');
expect(tai64).toEqual('4611686020108779339');
});

it('should be able to create fromUnixMilliseconds and convert toUnixMilliseconds', () => {
// #region from-unix-milliseconds-and-to-unix-milliseconds
// #import { DateTime };

const date: DateTime = DateTime.fromUnixMilliseconds(1681391398000);

const unixMilliseconds: number = date.toUnixMilliseconds();
// #context console.log(unixMilliseconds); // 1681391398000
// #endregion from-unix-milliseconds-and-to-unix-milliseconds

expect(date).toBeDefined();
expect(unixMilliseconds).toEqual(1681391398000);
});

it('should be able to create fromUnixSeconds and convert toUnixSeconds', () => {
// #region from-unix-seconds-and-to-unix-seconds
// #import { DateTime };

const date: DateTime = DateTime.fromUnixSeconds(1681391398);

const unixSeconds: number = date.toUnixSeconds();
// #context console.log(unixSeconds); // 1681391398
// #endregion from-unix-seconds-and-to-unix-seconds

expect(date).toBeDefined();
expect(unixSeconds).toEqual(1681391398);
});

/**
* Utility methods
*/
it('should extend the Date class', () => {
// #region date-object-methods
// #import { DateTime };

const dateTime: DateTime = DateTime.fromUnixMilliseconds(1681391398000);

// Extends the Date object
const date: Date = dateTime;

// Date object methods
date.getTime(); // 1681391398000
date.toISOString(); // 2023-04-13T13:09:58.000Z
date.toDateString(); // Thu Apr 13 2023
// #endregion date-object-methods

expect(dateTime).toBeDefined();
expect(date).toBeInstanceOf(Date);
expect(date.getTime()).toEqual(1681391398000);
expect(date.toISOString()).toEqual('2023-04-13T13:09:58.000Z');
expect(date.toDateString()).toEqual('Thu Apr 13 2023');
danielbate marked this conversation as resolved.
Show resolved Hide resolved
expect(date.toISOString()).toEqual(dateTime.toISOString());
});
});
6 changes: 5 additions & 1 deletion apps/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ export default defineConfig({
text: 'Vectors',
link: '/guide/types/vectors',
},
{
text: 'Date Time',
link: '/guide/types/date-time',
},
],
},
{
Expand Down Expand Up @@ -323,7 +327,7 @@ export default defineConfig({
},
{
text: 'Addresses',
link: '/guide/addresses',
link: '/guide/addresses/',
collapsed: true,
items: [
{
Expand Down
2 changes: 2 additions & 0 deletions apps/docs/spell-check-custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,5 @@ AbstractAddress
ContractFactory
ScriptTransactionRequest
CDN
DateTime
Atomique
59 changes: 59 additions & 0 deletions apps/docs/src/guide/types/date-time.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# DateTime

To allow for easier manipulation of date and time, the SDK exports the `DateTime` class which is a wrapper around the [built-in](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) `Date` class. Below we will go over the methods of instantiation, utility functions and time formats.

Internally the transactions and other time/date assets are encoded using the [`TAI64`](#tai-format) format. We return a `DateTime` class, to allow of easier conversion and formatting between the two formats.

## Instantiating a `DateTime`

We have a host of static method for **instantiation** of our `DateTime` class.
petertonysmith94 marked this conversation as resolved.
Show resolved Hide resolved

<<< @/../../docs-snippets/src/guide/types/date-time.test.ts#create-from-multiple-sources{ts:line-numbers}

### TAI64

`fromTai64` is a _static_ method, that allows the creation of `DateTime` class from a `TAI64` string.

`toTai64` is an _instance_ method, that allows the conversion of a `DateTime` class to a `TAI64` string.

<<< @/../../docs-snippets/src/guide/types/date-time.test.ts#from-tai-64-and-to-tai-64{ts:line-numbers}

### UNIX

`fromUnixMilliseconds` is a _static_ method, that allows the creation of `DateTime` class from a UNIX Milliseconds number.

`toUnixMilliseconds` is an _instance_ method, that allows the conversion of a `DateTime` class to a `UNIX` number in milliseconds.

<<< @/../../docs-snippets/src/guide/types/date-time.test.ts#from-unix-milliseconds-and-to-unix-milliseconds{ts:line-numbers}

`fromUnixSeconds` is a _static_ method, that allows the creation of `DateTime` class from a UNIX Seconds number.

`toUnixSeconds` is an _instance_ method, that allows the conversion of a `DateTime` class to a `UNIX` number in seconds.

<<< @/../../docs-snippets/src/guide/types/date-time.test.ts#from-unix-seconds-and-to-unix-seconds{ts:line-numbers}

### Date

The `DateTime` class extends the functionality of the `Date` object, so all method are available for your usages.

<<< @/../../docs-snippets/src/guide/types/date-time.test.ts#date-object-methods{ts:line-numbers}

## Formats
danielbate marked this conversation as resolved.
Show resolved Hide resolved

Here we will go over the different date/time formats that we use in the SDK. Internally the blockchain uses the `TAI64` format, but we also support the `UNIX` format for ease of use.

### UNIX Format

UNIX time is the number of seconds that have elapsed since **00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970**, minus leap seconds. Every day is treated as if it contains exactly 86400 seconds, so leap seconds are ignored.

### TAI Format

TAI stands for _Temps Atomique International_ and is the current international real-time standard [Source](https://cr.yp.to/libtai/tai64.html).
petertonysmith94 marked this conversation as resolved.
Show resolved Hide resolved

We use `TAI64` is a 64-bit integer representing the number of nanoseconds since the epoch.

- the TAI second beginning exactly _(2^62 - s) seconds_ before the beginning of 1970 TAI, if s is between 0 inclusive and 2^62 exclusive; or

- the TAI second beginning exactly _(2^62 + s) seconds_ after the beginning of 1970 TAI, if s is between -2^62 inclusive and 0 exclusive.

[Source](https://cr.yp.to/libtai/tai64.html)
3 changes: 2 additions & 1 deletion packages/account/codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"AssetId": "string",
"ContractId": "string",
"Salt": "string",
"Nonce": "string"
"Nonce": "string",
"Tai64Timestamp": "string"
Torres-ssf marked this conversation as resolved.
Show resolved Hide resolved
},
"useTypeImports": true,
"nonOptionalTypename": true,
Expand Down
15 changes: 7 additions & 8 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { BytesLike } from '@fuel-ts/interfaces';
import { BN, bn } from '@fuel-ts/math';
import type { Receipt } from '@fuel-ts/transactions';
import { InputType, ReceiptType, TransactionType } from '@fuel-ts/transactions';
import { arrayify, hexlify } from '@fuel-ts/utils';
import { DateTime, arrayify, hexlify } from '@fuel-ts/utils';
import { versions } from '@fuel-ts/versions';
import * as fuelTsVersionsMod from '@fuel-ts/versions';

Expand All @@ -25,8 +25,7 @@ import type {
} from './transaction-request';
import { ScriptTransactionRequest, CreateTransactionRequest } from './transaction-request';
import { TransactionResponse } from './transaction-response';
import { fromTai64ToDate } from './transaction-summary';
import { fromTai64ToUnix, fromUnixToTai64, sleep } from './utils';
import { sleep } from './utils';
import * as gasMod from './utils/gas';

afterEach(() => {
Expand Down Expand Up @@ -293,8 +292,8 @@ describe('Provider', () => {

expect(producedBlock).toBeDefined();

const oldest = new Date(fromTai64ToDate(timeLastBlockProduced || ''));
const newest = new Date(fromTai64ToDate(producedBlock?.time || ''));
const oldest: Date = DateTime.fromTai64(timeLastBlockProduced);
const newest: Date = DateTime.fromTai64(producedBlock?.time || DateTime.TAI64_NULL);

expect(newest >= oldest).toBeTruthy();
// #endregion Provider-produce-blocks
Expand All @@ -312,9 +311,9 @@ describe('Provider', () => {
}
const { time: latestBlockTimestampBeforeProduce, height: latestBlockNumberBeforeProduce } =
block;
const latestBlockUnixTimestampBeforeProduce = fromTai64ToUnix(
const latestBlockUnixTimestampBeforeProduce = DateTime.fromTai64(
latestBlockTimestampBeforeProduce
);
).toUnixMilliseconds();

const amountOfBlocksToProduce = 3;
const blockTimeInterval = 100; // 100ms
Expand All @@ -340,7 +339,7 @@ describe('Provider', () => {
}));
const expectedBlocks = Array.from({ length: amountOfBlocksToProduce }, (_, i) => ({
height: latestBlockNumberBeforeProduce.add(i + 1).toString(10),
time: fromUnixToTai64(startTime + i * blockTimeInterval),
time: DateTime.fromUnixMilliseconds(startTime + i * blockTimeInterval).toTai64(),
}));
expect(producedBlocks).toEqual(expectedBlocks);
});
Expand Down
7 changes: 3 additions & 4 deletions packages/account/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
InputMessageCoder,
TransactionCoder,
} from '@fuel-ts/transactions';
import { arrayify, hexlify } from '@fuel-ts/utils';
import { arrayify, hexlify, DateTime } from '@fuel-ts/utils';
import { checkFuelCoreVersionCompatibility } from '@fuel-ts/versions';
import { equalBytes } from '@noble/curves/abstract/utils';
import { Network } from 'ethers';
Expand Down Expand Up @@ -45,7 +45,6 @@ import { TransactionResponse } from './transaction-response';
import { processGqlReceipt } from './transaction-summary/receipt';
import {
calculatePriceWithFactor,
fromUnixToTai64,
getGasUsedFromReceipts,
getReceiptsWithMissingData,
} from './utils';
Expand Down Expand Up @@ -1394,13 +1393,13 @@ export default class Provider {
* Lets you produce blocks with custom timestamps and the block number of the last block produced.
*
* @param amount - The amount of blocks to produce
* @param startTime - The UNIX timestamp to set for the first produced block
* @param startTime - The UNIX timestamp (milliseconds) to set for the first produced block
* @returns A promise that resolves to the block number of the last produced block.
*/
async produceBlocks(amount: number, startTime?: number) {
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
blocksToProduce: bn(amount).toString(10),
startTimestamp: startTime ? fromUnixToTai64(startTime) : undefined,
startTimestamp: startTime ? DateTime.fromUnixMilliseconds(startTime).toTai64() : undefined,
});
return bn(latestBlockHeight);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { type BN } from '@fuel-ts/math';
import { type Transaction } from '@fuel-ts/transactions';
import { hexlify } from '@fuel-ts/utils';
import { DateTime, hexlify } from '@fuel-ts/utils';

import type { GqlGasCosts } from '../__generated__/operations';
import type { TransactionResultReceipt } from '../transaction-response';
import { getGasUsedFromReceipts } from '../utils';

import { calculateTransactionFee } from './calculate-transaction-fee';
import { fromTai64ToDate } from './date';
import {
getOperations,
getTransactionTypeName,
Expand Down Expand Up @@ -83,10 +82,10 @@ export function assembleTransactionSummary<TTransactionType = void>(
const mintedAssets = extractMintedAssetsFromReceipts(receipts);
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);

let date: Date | undefined;
let date: DateTime | undefined;

if (time) {
date = fromTai64ToDate(time);
date = DateTime.fromTai64(time);
}

const transactionSummary: TransactionSummary<TTransactionType> = {
Expand Down
43 changes: 0 additions & 43 deletions packages/account/src/providers/transaction-summary/date.test.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/account/src/providers/transaction-summary/date.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ export * from './operations';
export * from './get-transaction-summary';
export * from './assemble-transaction-summary';
export * from './receipt';
export * from './date';
export * from './calculate-transaction-fee';
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type IProcessGraphqlStatusResponse = Pick<

/** @hidden */
export const processGraphqlStatus = (gqlTransactionStatus?: GraphqlTransactionStatus) => {
let time: Time;
let time: Time | undefined;
let blockId: BlockId | undefined;
let status: TransactionStatus | undefined;

Expand Down
1 change: 0 additions & 1 deletion packages/account/src/providers/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export * from './block-explorer';
export * from './gas';
export * from './json';
export * from './sleep';
export * from './time';
Loading
Loading