Skip to content
This repository was archived by the owner on Aug 7, 2026. It is now read-only.
This repository was archived by the owner on Aug 7, 2026. It is now read-only.

Export the datetime.getDateTimeFromEpoch utility method #676

Description

@cristobal

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions