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

Export the datetime.getDateTimeFromEpoch utility method #676

Open
cristobal opened this issue Dec 1, 2021 · 0 comments
Open

Export the datetime.getDateTimeFromEpoch utility method #676

cristobal opened this issue Dec 1, 2021 · 0 comments
Labels
enhancement New feature or request T-dev-tools

Comments

@cristobal
Copy link

cristobal commented Dec 1, 2021

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

Describe the solution you'd like
Export the getDateTimeFromEpoch utility method on the datetime namespace.
This would allow smart contracts to store the blockTimestamp and then parse it back to PlainDateTime at a later stage.
A use case would be how long since some user last ran the smart contract or the smart contract was ran e.g.:

 const map = new PersistentMap<string, number>("f");

export function doSomeWork(accountId:string):void {
 const datetime = datetime.block_datetime();
 const last_datetime = datetime.getDateTimeFromEpoch(
 map.getSome<u64>(accountId)
 );

 const duration = last_datetime.until(datetime);
 if (duration.days === 0) 

 { return 'You still have to wait until you can run this method again.…' } 

 map.set(accountId, context.blockTimestamp);
 ...

 return 'success';
 }

Describe alternatives you've considered

  • I have considered just doing subtraction on u64 values and converting from nanoseconds to seconds.
  • Copy/Past the getDateTimeFromEpoch() code, which worked fine.

Additional context
Another option would to make the PlainDateTime class available to use.

@cristobal cristobal added the enhancement New feature or request label Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request T-dev-tools
Projects
None yet
Development

No branches or pull requests

1 participant