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

Initial implementation of date #190

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

saimeunt
Copy link

@saimeunt saimeunt commented Feb 28, 2025

📝 Initial implementation of datetime utility

This PR provides an implementation of a datetime utility library in Cairo heavily inspired by chrono.
Most of the functions needed to manipulate dates are implemented.

🛠️ Issue

📖 Description

Please refer to the chrono docs for usage as this utility aims at being a port of this rust library to Cairo.

Here's an example highlighting the basic operations available on datetimes, such as creating a DateTime from a starknet timestamp, simple formatting of dates and comparison.

#[test]
fn test_datetime_from_timestamp() {
    let dt1 = DateTimeTrait::from_timestamp(get_block_timestamp().try_into().unwrap()).unwrap();
    assert_eq!(format!("{}", dt1), "1970-01-01 00:00:00");
    start_cheat_block_timestamp_global(1707868800);
    let dt2 = DateTimeTrait::from_timestamp(get_block_timestamp().try_into().unwrap()).unwrap();
    assert_eq!(format!("{}", dt2), "2024-02-14 00:00:00");
    assert!(dt1 < dt2);
}

📝 Additional Notes

This utility being a port of chrono in Cairo, it is easy to cherry-pick missing functions from chrono that should be included in the Cairo version.

@saimeunt saimeunt marked this pull request as ready for review March 8, 2025 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT]: Add DateTime Utility Implementation
2 participants