Fuel uses tai64
instead of unix
for our timestamps which is also already in seconds. Divide by 1000 to get milliseconds if you need to. Read more about tai64 here .
Example rust test below:
fn convert_to_datetime(timestamp: u64) -> DateTime<Utc> {
let unix = tai64::Tai64(timestamp).to_unix();
DateTime::from_timestamp(unix, 0).unwrap()
}
/// This test is here in addition to `can_set_custom_block_time` because even though this test
/// passed, the Sway `timestamp` function didn't take into account the block time change. This
/// was fixed and this test is here to demonstrate the fix.
#[tokio::test]
async fn test_sway_timestamp() -> Result<()> {
let block_time = 1u32; // seconds
let provider_config = NodeConfig {
block_production: Trigger::Interval {
block_time: std::time::Duration::from_secs(block_time.into()),
},
..NodeConfig::default()
};
let mut wallets = launch_custom_provider_and_get_wallets(
WalletsConfig::new(Some(1), Some(1), Some(100)),
Some(provider_config),