| Crates.io | chrono-light |
| lib.rs | chrono-light |
| version | 0.1.5 |
| created_at | 2022-04-18 18:33:36.70252+00 |
| updated_at | 2022-07-06 15:33:33.636877+00 |
| description | Light DateTime/scheduler library for Rust, no_std compatible |
| homepage | https://github.com/konrads/chrono-light |
| repository | https://github.com/konrads/chrono-light |
| max_upload_size | |
| id | 569976 |
| size | 86,597 |
Provides DateTime and Schedule capabilities with no external library dependencies. Works in std/no std, optional support for scale codec encoding/decoding/type info.
Functionality provided:
DateTime, and vice versaDateTimeDateTimescale feature enabling Encode/Decode/TypeInfo support for DateTime/Schedule structs.This library works with DateTimes and schedules within years of [1970, 4000].
Does not support timezones.
Overflow of months (>12), days (>28, >30, >31), hour (>23), minute/second (>59), millis (>999) is discouraged yet allowed, with excess added eg. 31 April ~= 1 May. Underflow of month/day (=0) causes panic. To avoid panic, validate hand crafted DateTime via Calendar::validate() or convert to unixtime via Calendar::to_unixtime_opt().
Reasoning behind these restrictions is to keep the footprint reasonably compact and performance reasonably fast, and cater for real life scenarios.
use chrono_light::prelude::*;
let c = Calendar::create();
let now_in_ms: u64 = 1650412800000; // represents 20/04/2022 00:00:00:000
let schedule = Schedule {
start: DateTime { year: 2020, month: 4, day: 30, hour: 0, minute: 0, second: 0, ms: 0 },
items: vec![(Frequency::Year, 1)],
end: Some(DateTime { year: 2025, month: 4, day: 30, hour: 0, minute: 0, second: 0, ms: 0 })
};
assert!(c.validate_schedule(&schedule).is_ok());
assert_eq!(Some(10*24*60*60*1000), c.next_occurrence_ms(&c.from_unixtime(now_in_ms), &schedule)); // triggers in 10 days
Chrono-light serves as a scheduling mechanism for scheduler-pallet.