11 releases

0.3.34 Sep 30, 2024
0.3.32 Jul 26, 2024
0.3.28 Dec 29, 2023
0.3.25 Nov 17, 2023
0.1.17 Jul 28, 2022

#21 in Date and time

Download history 1387/week @ 2024-08-03 1397/week @ 2024-08-10 1130/week @ 2024-08-17 1348/week @ 2024-08-24 1196/week @ 2024-08-31 1469/week @ 2024-09-07 1219/week @ 2024-09-14 1603/week @ 2024-09-21 1462/week @ 2024-09-28 1431/week @ 2024-10-05 1165/week @ 2024-10-12 1354/week @ 2024-10-19 1012/week @ 2024-10-26 1147/week @ 2024-11-02 904/week @ 2024-11-09 930/week @ 2024-11-16

4,193 downloads per month
Used in 51 crates (11 directly)

Apache-2.0

62KB
1.5K SLoC

fastdate

codecov

fastdate of Any RFC3339Micro

way fastdate?

  • full test, Code testing coverage >= 99%
  • Powerful, easy to use
  • based on crate time

this date cartes is very fast(<= 50ns) including

  • offset_sec()
  • from_str("2022-12-13 11:12:14.123456")
  • now()
  • utc()
  • week_day()
  • to_string()
  • eq(),==
  • add(),sub()
  • format("YYYY-MM-DD hh:mm:ss.000000")
  • parse("YYYY-MM-DD,hh:mm:ss.000000","2022-12-13,11:12:14.123456")
  • set_offset()
  • unix_timestamp()
  • unix_timestamp_millis()
  • unix_timestamp_nano()
  • from_timestamp()
  • from_timestamp_millis()
  • from_timestamp_nano()
  • before(&date) -> bool
  • after(&date1) -> bool
  • from(v: SystemTime)
  • from(v: DateTime)
  • from(arg: Date)
  • from(arg: Time)
  • cmp(&self, other: &DateTime)/>/</>=/<= and more....
test bench_add                         ... bench:          14 ns/iter (+/- 0)
test bench_date_display                ... bench:          49 ns/iter (+/- 2)
test bench_date_from_str_iso_8601      ... bench:         129 ns/iter (+/- 6)
test bench_date_from_str_iso_8601_time ... bench:          69 ns/iter (+/- 2)
test bench_date_now_local              ... bench:          65 ns/iter (+/- 2)
test bench_date_parse_format           ... bench:         282 ns/iter (+/- 11)
test bench_date_utc                    ... bench:          49 ns/iter (+/- 2)
test bench_datetime_from_str           ... bench:         130 ns/iter (+/- 10)
test bench_eq                          ... bench:          10 ns/iter (+/- 0)
test bench_from_timestamp_millis       ... bench:          23 ns/iter (+/- 0)
test bench_get_micro                   ... bench:           0 ns/iter (+/- 0)
test bench_set_offset                  ... bench:          12 ns/iter (+/- 0)
test bench_timestamp                   ... bench:           2 ns/iter (+/- 0)
  • how use?

add to Cargo.tom dep

fastdate = "0.3"

use code

use fastdate::DateTime;
fn main(){
    //now with local time zone
    DateTime::now();
    //utc time now
    DateTime::utc();
    // add
    DateTime::now() + Duration::from_secs(1);
    // sub
    DateTime::now() - Duration::from_secs(1);
    //parse allow token = ["YYYY","MM","DD","hh","mm","ss",".000000","+00:00","Z"]
    fastdate::DateTime::parse("YYYY-MM-DD hh:mm:ss.000000000Z", "2022-12-13 11:12:14.123456789Z").unwrap();
    fastdate::DateTime::parse("YYYY-MM-DD hh:mm:ss.000000000+00:00", "2022-12-13 11:12:14.123456789+06:00").unwrap();
    DateTime::parse("hh:mm:ss.000000,YYYY-MM-DD","11:12:14.123456,2022-12-13").unwrap();
    //format allow token = ["YYYY","MM","DD","hh","mm","ss",".000000","+00:00","Z"]
     let dt = fastdate::DateTime::from((
        Date {
            day: 1,
            mon: 1,
            year: 2000,
        },
        Time {
            nano: 1233,
            sec: 11,
            minute: 1,
            hour: 1,
        },
    ));
    let str:String = dt.format("YYYY-MM-DD/hh/mm/ss");
    //befor,after
    let date1 = DateTime::from_str("2022-12-12 00:00:00").unwrap();
    let date2 = DateTime::from_str("2022-12-12 01:00:00").unwrap();
    assert_eq!(date2.after(&date1), true);
    assert_eq!(date1.before(&date2), true);
    //from str
    let datetime=DateTime::from_str("1234-12-13 11:12:13.123456");
    //from str time zone
    let datetime=DateTime::from_str("1234-12-13 11:12:13.123456+08:00");
    let datetime=DateTime::from_str("1234-12-13 11:12:13.123456Z");
    //to_string()
    let s = datetime.to_string();//1234-12-13 11:12:13.123456
    //unix_timestamp
    let timestamp = DateTime::now().unix_timestamp();
    //from unix_timestamp
    let datetime = DateTime::from_timestamp(timestamp);
    //unix_timestamp_millis
    let timestamp = DateTime::now().unix_timestamp_millis();
    //from unix millis
    let datetime = DateTime::from_timestamp_millis(timestamp);
    //unix_timestamp_nano
    let timestamp = DateTime::now().unix_timestamp_nano();
    //from unix_timestamp_nano
    let datetime = DateTime::from_timestamp_nano(timestamp);
    //sum Greenwich Mean Time (GMT) from datetime
    let time_gmt = DateTime::now().sub(Duration::from_secs(offset_sec() as u64));
}

Dependencies

~0.8–9MB
~83K SLoC